From 0a5434c09472cbf8c8faf5e5f5ba893a1c9a894b Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 11 Oct 2024 11:29:30 -0400 Subject: [PATCH 1/4] Redo mixins --- build.gradle | 11 ++- .../content/trains/station/StationBlock.java | 4 +- .../trains/station/StationMapData.java | 4 +- .../BlockDestructionProgressExtension.java | 4 +- .../foundation/mixin/BlockItemMixin.java | 3 +- .../mixin/ContraptionDriverInteractMixin.java | 40 +++++----- .../mixin/CustomItemUseEffectsMixin.java | 9 +-- .../create/foundation/mixin/EntityMixin.java | 10 +-- .../foundation/mixin/LavaSwimmingMixin.java | 3 +- .../create/foundation/mixin/MainMixin.java | 50 ------------- .../mixin/MapItemSavedDataMixin.java | 75 ++++++------------- .../foundation/mixin/TestCommandMixin.java | 12 ++- .../mixin/WaterWheelFluidSpreadMixin.java | 18 ++--- .../client/BlockDestructionProgressMixin.java | 7 +- .../foundation/mixin/client/CameraMixin.java | 14 ++-- .../EntityContraptionInteractionMixin.java | 30 +++----- .../mixin/client/HeavyBootsOnPlayerMixin.java | 3 +- .../mixin/client/HumanoidArmorLayerMixin.java | 14 +++- .../mixin/client/LevelRendererMixin.java | 4 +- .../client/MapRendererMapInstanceMixin.java | 8 +- .../mixin/client/ModelDataRefreshMixin.java | 34 --------- .../mixin/client/PlayerRendererMixin.java | 15 +++- .../mixin/client/WindowResizeMixin.java | 4 +- .../compat/JourneyFullscreenMapMixin.java | 18 ++--- src/main/resources/create.mixins.json | 5 +- 25 files changed, 140 insertions(+), 259 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/mixin/MainMixin.java delete mode 100644 src/main/java/com/simibubi/create/foundation/mixin/client/ModelDataRefreshMixin.java diff --git a/build.gradle b/build.gradle index fb88a41c87..86b254c9c7 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,8 @@ minecraft { property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + property "mixin.debug.export", "true" + //jvmArgs '-XX:+IgnoreUnrecognizedVMOptions', '-XX:+AllowEnhancedClassRedefinition' // uncomment with jbr mods { @@ -167,6 +169,11 @@ dependencies { jarJar.ranged(it, '[1.0,2.0)') } + compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")) + implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.4.1")) { + jarJar.ranged(it, "[0.4.1,)") + } + implementation fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}") compileOnly fg.deobf("dev.engine_room.flywheel:flywheel-forge-api-${flywheel_minecraft_version}:${flywheel_version}") @@ -192,12 +199,12 @@ dependencies { // implementation fg.deobf("curse.maven:ic2-classic-242942:5555152") // implementation fg.deobf("curse.maven:druidcraft-340991:3101903") // implementation fg.deobf("com.railwayteam.railways:railways-1.19.2-1.6.4:all") { transitive = false } - + implementation fg.deobf("dev.architectury:architectury-forge:9.1.12") implementation fg.deobf("dev.ftb.mods:ftb-chunks-forge:2001.3.1") implementation fg.deobf("dev.ftb.mods:ftb-teams-forge:2001.3.0") implementation fg.deobf("dev.ftb.mods:ftb-library-forge:2001.2.4") - + implementation fg.deobf("curse.maven:journeymap-32274:5457831") // implementation fg.deobf("ignored:journeymap-1.20.1-5.10.1-forge") diff --git a/src/main/java/com/simibubi/create/content/trains/station/StationBlock.java b/src/main/java/com/simibubi/create/content/trains/station/StationBlock.java index e766fc9223..3f299a81cd 100644 --- a/src/main/java/com/simibubi/create/content/trains/station/StationBlock.java +++ b/src/main/java/com/simibubi/create/content/trains/station/StationBlock.java @@ -67,7 +67,7 @@ public BlockState updateShape(BlockState pState, Direction pDirection, BlockStat updateWater(pLevel, pState, pCurrentPos); return pState; } - + @Override public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEntity pPlacer, ItemStack pStack) { super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack); @@ -123,7 +123,7 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla if (!(savedData instanceof StationMapData stationMapData)) return InteractionResult.FAIL; - if (!stationMapData.toggleStation(pLevel, pPos, station)) + if (!stationMapData.create$toggleStation(pLevel, pPos, station)) return InteractionResult.FAIL; return InteractionResult.SUCCESS; diff --git a/src/main/java/com/simibubi/create/content/trains/station/StationMapData.java b/src/main/java/com/simibubi/create/content/trains/station/StationMapData.java index 308506ee80..96318a5929 100644 --- a/src/main/java/com/simibubi/create/content/trains/station/StationMapData.java +++ b/src/main/java/com/simibubi/create/content/trains/station/StationMapData.java @@ -5,8 +5,8 @@ public interface StationMapData { - boolean toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity); + boolean create$toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity); - void addStationMarker(StationMarker marker); + void create$addStationMarker(StationMarker marker); } diff --git a/src/main/java/com/simibubi/create/foundation/block/render/BlockDestructionProgressExtension.java b/src/main/java/com/simibubi/create/foundation/block/render/BlockDestructionProgressExtension.java index 2a7bca863f..1948efe36d 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/BlockDestructionProgressExtension.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/BlockDestructionProgressExtension.java @@ -8,7 +8,7 @@ public interface BlockDestructionProgressExtension { @Nullable - Set getExtraPositions(); + Set create$getExtraPositions(); - void setExtraPositions(@Nullable Set positions); + void create$setExtraPositions(@Nullable Set positions); } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java index f4031bcb23..b03d304d6c 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java @@ -21,8 +21,7 @@ public class BlockItemMixin { @Inject(method = "place", at = @At("HEAD"), cancellable = true) private void create$fixDeployerPlacement(BlockPlaceContext pContext, CallbackInfoReturnable cir) { BlockState state = pContext.getLevel().getBlockState(((UseOnContextAccessor) pContext).create$getHitResult().getBlockPos()); - if (!state.canBeReplaced() && pContext.getPlayer() instanceof DeployerFakePlayer) { + if (!state.canBeReplaced() && pContext.getPlayer() instanceof DeployerFakePlayer) cir.setReturnValue(InteractionResult.PASS); - } } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/ContraptionDriverInteractMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/ContraptionDriverInteractMixin.java index b575a7de5f..be91ac2258 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/ContraptionDriverInteractMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/ContraptionDriverInteractMixin.java @@ -1,32 +1,28 @@ package com.simibubi.create.foundation.mixin; -import javax.annotation.Nullable; - -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Intrinsic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.simibubi.create.content.contraptions.AbstractContraptionEntity; import net.minecraft.world.entity.Entity; -import net.minecraftforge.common.capabilities.CapabilityProvider; -import net.minecraftforge.common.extensions.IForgeEntity; +import net.minecraft.world.entity.projectile.ProjectileUtil; -@Mixin(Entity.class) -@Implements(@Interface(iface = IForgeEntity.class, prefix = "iForgeEntity$")) -public abstract class ContraptionDriverInteractMixin extends CapabilityProvider { - private ContraptionDriverInteractMixin(Class baseClass) { - super(baseClass); - } - - @Shadow - public abstract Entity getRootVehicle(); +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; - @Nullable - @Intrinsic - public boolean iForgeEntity$canRiderInteract() { - return getRootVehicle() instanceof AbstractContraptionEntity; +@Mixin(ProjectileUtil.class) +public class ContraptionDriverInteractMixin { + @WrapOperation( + method = "getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/Entity;canRiderInteract()Z" + ) + ) + private static boolean create$contraptionDriverCanInteract(Entity instance, Operation original) { + if (instance.getRootVehicle() instanceof AbstractContraptionEntity) + return true; + return original.call(instance); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java index 86a899299a..1ee0ea9ebd 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java @@ -22,18 +22,15 @@ private CustomItemUseEffectsMixin(EntityType entityType, Level level) { super(entityType, level); } - @Shadow - public abstract ItemStack getUseItem(); + @Shadow public abstract ItemStack getUseItem(); @Inject(method = "shouldTriggerItemUseEffects()Z", at = @At("HEAD"), cancellable = true) private void create$onShouldTriggerUseEffects(CallbackInfoReturnable cir) { ItemStack using = getUseItem(); Item item = using.getItem(); if (item instanceof CustomUseEffectsItem handler) { - Boolean result = handler.shouldTriggerUseEffects(using, (LivingEntity) (Object) this); - if (result != null) { - cir.setReturnValue(result); - } + if (handler.shouldTriggerUseEffects(using, (LivingEntity) (Object) this) != null) + cir.setReturnValue(true); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java index 45728dcfe5..efc677e7db 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java @@ -11,15 +11,11 @@ @Mixin(value = Entity.class, priority = 900) public class EntityMixin { - @Inject(method = "fireImmune()Z", at = @At("RETURN"), cancellable = true) - public void create$onFireImmune(CallbackInfoReturnable cir) { + private void create$onFireImmune(CallbackInfoReturnable cir) { if (!cir.getReturnValueZ()) { - Entity self = (Entity) (Object) this; - boolean immune = self.getPersistentData().getBoolean(NetheriteDivingHandler.FIRE_IMMUNE_KEY); - if (immune) - cir.setReturnValue(immune); + if (((Entity) (Object) this).getPersistentData().getBoolean(NetheriteDivingHandler.FIRE_IMMUNE_KEY)) + cir.setReturnValue(true); } } - } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java index b09cb72730..577b013aaa 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java @@ -25,8 +25,7 @@ private LavaSwimmingMixin(EntityType type, Level level) { @Inject(method = "travel(Lnet/minecraft/world/phys/Vec3;)V", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isInLava()Z")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V", shift = Shift.AFTER, ordinal = 0)) private void create$onLavaTravel(Vec3 travelVector, CallbackInfo ci) { - ItemStack bootsStack = DivingBootsItem.getWornItem(this); - if (AllItems.NETHERITE_DIVING_BOOTS.isIn(bootsStack)) + if (AllItems.NETHERITE_DIVING_BOOTS.isIn(DivingBootsItem.getWornItem(this))) setDeltaMovement(getDeltaMovement().multiply(DivingBootsItem.getMovementMultiplier((LivingEntity) (Object) this))); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/MainMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/MainMixin.java deleted file mode 100644 index 99994733ae..0000000000 --- a/src/main/java/com/simibubi/create/foundation/mixin/MainMixin.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.simibubi.create.foundation.mixin; - -import java.util.Collection; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import net.minecraft.core.BlockPos; -import net.minecraft.gametest.framework.GameTestRegistry; -import net.minecraft.gametest.framework.GameTestRunner; -import net.minecraft.gametest.framework.GameTestServer; -import net.minecraft.server.Main; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.packs.repository.PackRepository; -import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess; - -@Mixin(Main.class) -public class MainMixin { - /** - * Forge completely bypasses vanilla's - * {@link GameTestServer#create(Thread, LevelStorageAccess, PackRepository, Collection, BlockPos)}, - * which causes tests to generate at bedrock level in a regular world. This causes interference - * (ex. darkness, liquids, gravel) that makes tests fail and act inconsistently. Replacing the server Forge - * makes with one made by vanilla's factory causes tests to run on a superflat, as they should. - *

- * The system property 'create.useOriginalGametestServer' may be set to true to avoid this behavior. - * This may be desirable for other mods which pull Create into their development environments. - */ - @ModifyVariable( - method = "lambda$main$5", - at = @At( - value = "STORE", - ordinal = 0 - ), - require = 0 // don't crash if this fails - ) - private static MinecraftServer create$correctlyInitializeGametestServer(MinecraftServer original) { - if (original instanceof GameTestServer && !Boolean.getBoolean("create.useOriginalGametestServer")) { - return GameTestServer.create( - original.getRunningThread(), - original.storageSource, - original.getPackRepository(), - GameTestRunner.groupTestsIntoBatches(GameTestRegistry.getAllTestFunctions()), - BlockPos.ZERO - ); - } - return original; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java index f1c0d0af72..7c9f65545e 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java @@ -29,35 +29,23 @@ import net.minecraft.world.level.saveddata.maps.MapItemSavedData; @Mixin(MapItemSavedData.class) -public class MapItemSavedDataMixin implements StationMapData { - @Unique - private static final String STATION_MARKERS_KEY = "create:stations"; - - @Shadow - @Final - public int centerX; - - @Shadow - @Final - public int centerZ; - - @Shadow - @Final - public byte scale; +public abstract class MapItemSavedDataMixin implements StationMapData { + @Shadow @Final public int centerX; + @Shadow @Final public int centerZ; + @Shadow @Final public byte scale; + @Shadow @Final Map decorations; + @Shadow private int trackedDecorationCount; - @Shadow - @Final - Map decorations; + @Shadow protected abstract void removeDecoration(String pIdentifier); + @Shadow protected abstract void setDecorationsDirty(); + @Shadow public abstract boolean isTrackedCountOverLimit(int pTrackedCount); - @Shadow - private int trackedDecorationCount; - - @Unique - private final Map create$stationMarkers = Maps.newHashMap(); + @Unique private static final String STATION_MARKERS_KEY = "create:stations"; + @Unique private final Map create$stationMarkers = Maps.newHashMap(); @Inject( method = "load(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;", - at = @At("RETURN") + at = @At("TAIL") ) private static void create$onLoad(CompoundTag compound, CallbackInfoReturnable cir) { MapItemSavedData mapData = cir.getReturnValue(); @@ -66,15 +54,12 @@ public class MapItemSavedDataMixin implements StationMapData { ListTag listTag = compound.getList(STATION_MARKERS_KEY, Tag.TAG_COMPOUND); for (int i = 0; i < listTag.size(); ++i) { StationMarker stationMarker = StationMarker.load(listTag.getCompound(i)); - stationMapData.addStationMarker(stationMarker); + stationMapData.create$addStationMarker(stationMarker); } } - @Inject( - method = "save(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;", - at = @At("RETURN") - ) - public void create$onSave(CompoundTag compound, CallbackInfoReturnable cir) { + @Inject(method = "save(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;", at = @At("TAIL")) + private void create$onSave(CompoundTag compound, CallbackInfoReturnable cir) { ListTag listTag = new ListTag(); for (StationMarker stationMarker : create$stationMarkers.values()) { listTag.add(stationMarker.save()); @@ -83,7 +68,7 @@ public class MapItemSavedDataMixin implements StationMapData { } @Override - public void addStationMarker(StationMarker marker) { + public void create$addStationMarker(StationMarker marker) { create$stationMarkers.put(marker.getId(), marker); int scaleMultiplier = 1 << scale; @@ -113,23 +98,8 @@ public void addStationMarker(StationMarker marker) { } } - @Shadow - private void removeDecoration(String identifier) { - throw new AssertionError(); - } - - @Shadow - private void setDecorationsDirty() { - throw new AssertionError(); - } - - @Shadow - public boolean isTrackedCountOverLimit(int trackedCount) { - throw new AssertionError(); - } - @Override - public boolean toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity) { + public boolean create$toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity) { double xCenter = pos.getX() + 0.5D; double zCenter = pos.getZ() + 0.5D; int scaleMultiplier = 1 << scale; @@ -150,18 +120,15 @@ public boolean toggleStation(LevelAccessor level, BlockPos pos, StationBlockEnti } if (!isTrackedCountOverLimit(256)) { - addStationMarker(marker); + create$addStationMarker(marker); return true; } return false; } - @Inject( - method = "checkBanners(Lnet/minecraft/world/level/BlockGetter;II)V", - at = @At("RETURN") - ) - public void create$onCheckBanners(BlockGetter blockGetter, int x, int z, CallbackInfo ci) { + @Inject(method = "checkBanners(Lnet/minecraft/world/level/BlockGetter;II)V", at = @At("TAIL")) + private void create$onCheckBanners(BlockGetter blockGetter, int x, int z, CallbackInfo ci) { create$checkStations(blockGetter, x, z); } @@ -186,7 +153,7 @@ public boolean toggleStation(LevelAccessor level, BlockPos pos, StationBlockEnti } for (StationMarker marker : newMarkers) { - addStationMarker(marker); + create$addStationMarker(marker); } } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/TestCommandMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/TestCommandMixin.java index b9cc72e4de..245579141d 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/TestCommandMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/TestCommandMixin.java @@ -2,6 +2,11 @@ import javax.annotation.Nullable; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; + +import com.llamalad7.mixinextras.sugar.Local; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -20,7 +25,7 @@ @Mixin(TestCommand.class) public class TestCommandMixin { - @Redirect( + @WrapOperation( method = "runTest(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/gametest/framework/MultipleTestTracker;)V", at = @At( value = "INVOKE", @@ -28,12 +33,11 @@ public class TestCommandMixin { ), require = 0 // don't crash if this fails. non-critical ) - private static TestFunction create$getCorrectTestFunction(String testName, - ServerLevel level, BlockPos pos, @Nullable MultipleTestTracker tracker) { + private static TestFunction create$getCorrectTestFunction(String pTestName, Operation original, @Local(argsOnly = true) ServerLevel level, @Local(argsOnly = true) BlockPos pos) { StructureBlockEntity be = (StructureBlockEntity) level.getBlockEntity(pos); CompoundTag data = be.getPersistentData(); if (!data.contains("CreateTestFunction", Tag.TAG_STRING)) - return GameTestRegistry.getTestFunction(testName); + return original.call(pTestName); String name = data.getString("CreateTestFunction"); CreateTestFunction function = CreateTestFunction.NAMES_TO_FUNCTIONS.get(name); if (function == null) diff --git a/src/main/java/com/simibubi/create/foundation/mixin/WaterWheelFluidSpreadMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/WaterWheelFluidSpreadMixin.java index d398815e61..582aac16d7 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/WaterWheelFluidSpreadMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/WaterWheelFluidSpreadMixin.java @@ -21,22 +21,20 @@ @Mixin(FlowingFluid.class) public class WaterWheelFluidSpreadMixin { @Inject(method = "canPassThrough(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/level/material/Fluid;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;)Z", at = @At("HEAD"), cancellable = true) - protected void create$canPassThroughOnWaterWheel(BlockGetter pLevel, Fluid pFluid, BlockPos pFromPos, BlockState p_75967_, - Direction pDirection, BlockPos p_75969_, BlockState p_75970_, FluidState p_75971_, - CallbackInfoReturnable cir) { + private void create$canPassThroughOnWaterWheel(BlockGetter pLevel, Fluid pFluid, BlockPos pPos, BlockState pState, + Direction pDirection, BlockPos pSpreadPos, BlockState pSpreadState, + FluidState pFluidState, CallbackInfoReturnable cir) { + if (pDirection.getAxis() == Axis.Y) return; - if (pDirection.getAxis() == Axis.Y) - return; - - BlockPos belowPos = pFromPos.below(); + BlockPos belowPos = pPos.below(); BlockState belowState = pLevel.getBlockState(belowPos); if (AllBlocks.WATER_WHEEL_STRUCTURAL.has(belowState)) { - if (AllBlocks.WATER_WHEEL_STRUCTURAL.get() - .stillValid(pLevel, belowPos, belowState, false)) + if (AllBlocks.WATER_WHEEL_STRUCTURAL.get().stillValid(pLevel, belowPos, belowState, false)) belowState = pLevel.getBlockState(WaterWheelStructuralBlock.getMaster(pLevel, belowPos, belowState)); - } else if (!AllBlocks.WATER_WHEEL.has(belowState)) + } else { return; + } if (belowState.getBlock() instanceof IRotate irotate && irotate.getRotationAxis(belowState) == pDirection.getAxis()) diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java index 61cefd23e1..602b66adb4 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java @@ -12,16 +12,15 @@ @Mixin(BlockDestructionProgress.class) public class BlockDestructionProgressMixin implements BlockDestructionProgressExtension { - @Unique - private Set create$extraPositions; + @Unique private Set create$extraPositions; @Override - public Set getExtraPositions() { + public Set create$getExtraPositions() { return create$extraPositions; } @Override - public void setExtraPositions(Set positions) { + public void create$setExtraPositions(Set positions) { create$extraPositions = positions; } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/CameraMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/CameraMixin.java index 2422a2d1c5..0fc4144799 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/CameraMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/CameraMixin.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.mixin.client; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -10,12 +12,14 @@ @Mixin(Camera.class) public abstract class CameraMixin { - @ModifyArg( - method = "Lnet/minecraft/client/Camera;setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;getMaxZoom(D)D"), - index = 0 + @ModifyExpressionValue( + method = "setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/Camera;getMaxZoom(D)D" + ) ) - public double create$modifyCameraOffset(double originalValue) { + private double create$modifyCameraOffset(double originalValue) { return originalValue * CameraDistanceModifier.getMultiplier(); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java index 9797c89cbc..592caf1fab 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java @@ -40,27 +40,14 @@ private EntityContraptionInteractionMixin(Class baseClass) { super(baseClass); } - @Shadow - public Level level; + @Shadow private Level level; + @Shadow private Vec3 position; + @Shadow private float nextStep; + @Shadow @Final protected RandomSource random; + @Shadow private EntityDimensions dimensions; - @Shadow - private Vec3 position; - - @Shadow - private float nextStep; - - @Shadow - @Final - protected RandomSource random; - - @Shadow - private EntityDimensions dimensions; - - @Shadow - protected abstract float nextStep(); - - @Shadow - protected abstract void playStepSound(BlockPos pos, BlockState state); + @Shadow protected abstract float nextStep(); + @Shadow protected abstract void playStepSound(BlockPos pos, BlockState state); @Unique private Stream create$getIntersectionContraptionsStream() { @@ -98,7 +85,8 @@ private EntityContraptionInteractionMixin(Class baseClass) { } // involves block step sounds on contraptions - // IFNE line 661 injecting before `!blockstate.isAir(this.world, blockpos)` + // injecting before `!blockstate1.isAir(this.world, blockpos)` + // `if (this.moveDist > this.nextStep && !blockstate1.isAir()) {` @Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;isAir()Z", ordinal = 0)) private void create$contraptionStepSounds(MoverType mover, Vec3 movement, CallbackInfo ci) { Vec3 worldPos = position.add(0, -0.2, 0); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/HeavyBootsOnPlayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/HeavyBootsOnPlayerMixin.java index eafc48ead7..56a0e1d3f9 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/HeavyBootsOnPlayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/HeavyBootsOnPlayerMixin.java @@ -14,13 +14,12 @@ @Mixin(LocalPlayer.class) public abstract class HeavyBootsOnPlayerMixin extends AbstractClientPlayer { - private HeavyBootsOnPlayerMixin(ClientLevel level, GameProfile profile) { super(level, profile); } @Inject(method = "isUnderWater()Z", at = @At("HEAD"), cancellable = true) - public void create$noSwimmingWithHeavyBootsOn(CallbackInfoReturnable cir) { + private void create$noSwimmingWithHeavyBootsOn(CallbackInfoReturnable cir) { CompoundTag persistentData = getPersistentData(); if (persistentData.contains("HeavyBoots")) cir.setReturnValue(false); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/HumanoidArmorLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/HumanoidArmorLayerMixin.java index e3f8b8d606..47a403d382 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/HumanoidArmorLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/HumanoidArmorLayerMixin.java @@ -1,10 +1,11 @@ package com.simibubi.create.foundation.mixin.client; +import com.llamalad7.mixinextras.sugar.Local; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.item.CustomRenderedArmorItem; @@ -18,8 +19,15 @@ @Mixin(HumanoidArmorLayer.class) public class HumanoidArmorLayerMixin { - @Inject(method = "renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;)V", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/entity/LivingEntity;getItemBySlot(Lnet/minecraft/world/entity/EquipmentSlot;)Lnet/minecraft/world/item/ItemStack;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) - private void create$onRenderArmorPiece(PoseStack poseStack, MultiBufferSource bufferSource, LivingEntity entity, EquipmentSlot slot, int light, HumanoidModel model, CallbackInfo ci, ItemStack stack) { + @Inject( + method = "renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;" + ), + cancellable = true + ) + private void create$onRenderArmorPiece(PoseStack poseStack, MultiBufferSource bufferSource, LivingEntity entity, EquipmentSlot slot, int light, HumanoidModel model, CallbackInfo ci, @Local ItemStack stack) { if (stack.getItem() instanceof CustomRenderedArmorItem renderer) { renderer.renderArmorPiece((HumanoidArmorLayer) (Object) this, poseStack, bufferSource, entity, slot, light, model, stack); ci.cancel(); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/LevelRendererMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/LevelRendererMixin.java index f0adb6fec7..98226fcc5d 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/LevelRendererMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/LevelRendererMixin.java @@ -41,7 +41,7 @@ public class LevelRendererMixin { Set extraPositions = handler.getExtraPositions(level, pos, state, progress); if (extraPositions != null) { extraPositions.remove(pos); - ((BlockDestructionProgressExtension) progressObj).setExtraPositions(extraPositions); + ((BlockDestructionProgressExtension) progressObj).create$setExtraPositions(extraPositions); for (BlockPos extraPos : extraPositions) { destructionProgress.computeIfAbsent(extraPos.asLong(), l -> Sets.newTreeSet()).add(progressObj); } @@ -51,7 +51,7 @@ public class LevelRendererMixin { @Inject(method = "removeProgress(Lnet/minecraft/server/level/BlockDestructionProgress;)V", at = @At("RETURN")) private void create$onRemoveProgress(BlockDestructionProgress progress, CallbackInfo ci) { - Set extraPositions = ((BlockDestructionProgressExtension) progress).getExtraPositions(); + Set extraPositions = ((BlockDestructionProgressExtension) progress).create$getExtraPositions(); if (extraPositions != null) { for (BlockPos extraPos : extraPositions) { long l = extraPos.asLong(); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/MapRendererMapInstanceMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/MapRendererMapInstanceMixin.java index da6deef4ab..5b1c6f5cb8 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/MapRendererMapInstanceMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/MapRendererMapInstanceMixin.java @@ -2,6 +2,8 @@ import java.util.Iterator; +import com.llamalad7.mixinextras.sugar.Local; + import org.joml.Matrix4f; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; @@ -26,8 +28,8 @@ public class MapRendererMapInstanceMixin { private MapItemSavedData data; @Group(name = "custom_decoration_rendering", min = 1, max = 1) - @Inject(method = "draw(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/saveddata/maps/MapDecoration;render(I)Z", remap = false), locals = LocalCapture.CAPTURE_FAILHARD) - private void create$onDraw(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, int i, int j, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer, int index, Iterator iterator, MapDecoration decoration) { + @Inject(method = "draw(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/saveddata/maps/MapDecoration;render(I)Z", remap = false)) + private void create$onDraw(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, @Local(ordinal = 3) int index, @Local MapDecoration decoration) { if (decoration instanceof CustomRenderedMapDecoration renderer) { renderer.render(poseStack, bufferSource, active, packedLight, data, index); } @@ -35,7 +37,7 @@ public class MapRendererMapInstanceMixin { @Group(name = "custom_decoration_rendering") @Inject(method = "draw(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ZI)V", at = @At(value = "FIELD", target = "net/optifine/reflect/Reflector.ForgeMapDecoration_render:Lnet/optifine/reflect/ReflectorMethod;", opcode = Opcodes.GETSTATIC, ordinal = 1, remap = false), locals = LocalCapture.CAPTURE_FAILHARD) - private void create$onDrawOptifine(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, int i, int j, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer, int index, Iterator iterator, MapDecoration decoration) { + private void create$onDraw$Optifine(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, int i, int j, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer, int index, Iterator iterator, MapDecoration decoration) { if (decoration instanceof CustomRenderedMapDecoration renderer) { renderer.render(poseStack, bufferSource, active, packedLight, data, index); } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/ModelDataRefreshMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/ModelDataRefreshMixin.java deleted file mode 100644 index a2741cc758..0000000000 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/ModelDataRefreshMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.simibubi.create.foundation.mixin.client; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.simibubi.create.content.schematics.SchematicWorld; - -import net.minecraft.client.Minecraft; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.model.data.ModelDataManager; - -@OnlyIn(Dist.CLIENT) -@Mixin(ModelDataManager.class) -public class ModelDataRefreshMixin { - /** - * Normally ModelDataManager will throw an exception if a block entity tries - * to refresh its model data from a world the client isn't currently in, - * but we need that to not happen for block entities in fake schematic - * worlds, so in those cases just do nothing instead. - */ - @Inject(method = "requestModelDataRefresh", at = @At("HEAD"), cancellable = true, remap = false) - private static void create$requestModelDataRefresh(BlockEntity be, CallbackInfo ci) { - if (be != null) { - Level world = be.getLevel(); - if (world != Minecraft.getInstance().level && world instanceof SchematicWorld) - ci.cancel(); - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/PlayerRendererMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/PlayerRendererMixin.java index fb27d9f157..e59128527b 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/PlayerRendererMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/PlayerRendererMixin.java @@ -1,5 +1,9 @@ package com.simibubi.create.foundation.mixin.client; +import com.llamalad7.mixinextras.sugar.Local; + +import net.minecraft.client.model.HumanoidModel; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,8 +20,15 @@ @Mixin(PlayerRenderer.class) public class PlayerRendererMixin { - @Inject(method = "getArmPose(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/client/model/HumanoidModel$ArmPose;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/player/AbstractClientPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) - private static void create$onGetArmPose(AbstractClientPlayer player, InteractionHand hand, CallbackInfoReturnable cir, ItemStack stack) { + @Inject( + method = "getArmPose(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/client/model/HumanoidModel$ArmPose;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/item/ItemStack;isEmpty()Z" + ), + cancellable = true + ) + private static void create$onGetArmPose(AbstractClientPlayer player, InteractionHand hand, CallbackInfoReturnable cir, @Local ItemStack stack) { if (stack.getItem() instanceof CustomArmPoseItem armPoseProvider) { ArmPose pose = armPoseProvider.getArmPose(stack, player, hand); if (pose != null) { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java index d79e8b8313..0a2dc2d0f9 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java @@ -14,9 +14,7 @@ @Mixin(Minecraft.class) public class WindowResizeMixin { - @Shadow - @Final - private Window window; + @Shadow @Final private Window window; @Inject(method = "resizeDisplay()V", at = @At("TAIL")) private void create$updateWindowSize(CallbackInfo ci) { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java index 70bb999643..7f10eb0204 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java @@ -2,6 +2,7 @@ import java.awt.geom.Point2D; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -17,18 +18,12 @@ @Mixin(Fullscreen.class) public abstract class JourneyFullscreenMapMixin { + @Shadow @Final private static GridRenderer gridRenderer; + @Shadow private Boolean isScrolling; + @Shadow protected abstract Point2D.Double getMouseDrag(); - @Shadow - private static GridRenderer gridRenderer; - - @Shadow - private Boolean isScrolling; - - @Shadow - public abstract Point2D.Double getMouseDrag(); - - @Inject(method = "Ljourneymap/client/ui/fullscreen/Fullscreen;render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V", at = @At(target = "Ljourneymap/client/ui/fullscreen/Fullscreen;drawMap(Lnet/minecraft/client/gui/GuiGraphics;II)V", value = "INVOKE", shift = Shift.AFTER)) - public void create$journeyMapFullscreenRender(GuiGraphics graphics, int mouseX, int mouseY, float pt, + @Inject(method = "render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V", at = @At(target = "Ljourneymap/client/ui/fullscreen/Fullscreen;drawLogo(Lcom/mojang/blaze3d/vertex/PoseStack;)V", value = "INVOKE")) + private void create$journeyMapFullscreenRender(GuiGraphics graphics, int mouseX, int mouseY, float pt, CallbackInfo ci) { boolean dragging = isScrolling; Point2D.Double mouseDrag = getMouseDrag(); @@ -36,5 +31,4 @@ public abstract class JourneyFullscreenMapMixin { double z = gridRenderer.getCenterBlockZ() - (dragging ? mouseDrag.y : 0); JourneyTrainMap.onRender(graphics, (Fullscreen) (Object) this, x, z, mouseX, mouseY, pt); } - } diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 8db180be7d..26ee177975 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -1,7 +1,7 @@ { "required": true, "minVersion": "0.8", - "priority": 1100, + "priority": 1000, "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_17", "refmap": "create.refmap.json", @@ -13,7 +13,6 @@ "CustomItemUseEffectsMixin", "EntityMixin", "LavaSwimmingMixin", - "MainMixin", "MapItemSavedDataMixin", "TestCommandMixin", "WaterWheelFluidSpreadMixin", @@ -47,7 +46,7 @@ "client.MapRendererMapInstanceMixin", "client.PlayerRendererMixin", "client.WindowResizeMixin", - "compat.JourneyFullscreenMapMixin" + "compat.JourneyFullscreenMapMixin" ], "injectors": { "defaultRequire": 1 From cfc805c3b544326dc5c2aca964c13d24cdc6152a Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 11 Oct 2024 12:31:04 -0400 Subject: [PATCH 2/4] Revert formating changes & use tristate --- .../com/simibubi/create/api/TriState.java | 27 +++++++++++ .../foundation/item/CustomUseEffectsItem.java | 8 ++-- .../mixin/CustomItemUseEffectsMixin.java | 10 ++-- .../create/foundation/mixin/EntityMixin.java | 4 +- .../foundation/mixin/LavaSwimmingMixin.java | 3 +- .../mixin/MapItemSavedDataMixin.java | 48 ++++++++++++++----- .../EntityContraptionInteractionMixin.java | 30 ++++++++---- .../compat/JourneyFullscreenMapMixin.java | 13 +++-- 8 files changed, 111 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/simibubi/create/api/TriState.java diff --git a/src/main/java/com/simibubi/create/api/TriState.java b/src/main/java/com/simibubi/create/api/TriState.java new file mode 100644 index 0000000000..74ec329a0e --- /dev/null +++ b/src/main/java/com/simibubi/create/api/TriState.java @@ -0,0 +1,27 @@ +package com.simibubi.create.api; + +public enum TriState { + TRUE, + DEFAULT, + FALSE; + + public boolean isTrue() { + return this == TRUE; + } + + public boolean isDefault() { + return this == DEFAULT; + } + + public boolean isFalse() { + return this == FALSE; + } + + public boolean getValue() { + return switch (this) { + case TRUE -> true; + case DEFAULT -> throw new IllegalArgumentException("Default does not have a value"); + case FALSE -> false; + }; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java b/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java index 58c76c7536..2723894db7 100644 --- a/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java +++ b/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.item; +import com.simibubi.create.api.TriState; + import net.minecraft.util.RandomSource; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; @@ -10,10 +12,10 @@ public interface CustomUseEffectsItem { * * @param stack The ItemStack being used. * @param entity The LivingEntity using the item. - * @return null for default behavior, or boolean to override default behavior + * @return {@link TriState#DEFAULT} for default behavior, or boolean to override default behavior */ - default Boolean shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) { - return null; + default TriState shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) { + return TriState.DEFAULT; } /** diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java index 1ee0ea9ebd..fa46ce6eab 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CustomItemUseEffectsMixin.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.mixin; +import com.simibubi.create.api.TriState; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -22,15 +24,17 @@ private CustomItemUseEffectsMixin(EntityType entityType, Level level) { super(entityType, level); } - @Shadow public abstract ItemStack getUseItem(); + @Shadow + public abstract ItemStack getUseItem(); @Inject(method = "shouldTriggerItemUseEffects()Z", at = @At("HEAD"), cancellable = true) private void create$onShouldTriggerUseEffects(CallbackInfoReturnable cir) { ItemStack using = getUseItem(); Item item = using.getItem(); if (item instanceof CustomUseEffectsItem handler) { - if (handler.shouldTriggerUseEffects(using, (LivingEntity) (Object) this) != null) - cir.setReturnValue(true); + TriState result = handler.shouldTriggerUseEffects(using, (LivingEntity) (Object) this); + if (result != TriState.DEFAULT) + cir.setReturnValue(result.getValue()); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java index efc677e7db..caa2201b27 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/EntityMixin.java @@ -14,7 +14,9 @@ public class EntityMixin { @Inject(method = "fireImmune()Z", at = @At("RETURN"), cancellable = true) private void create$onFireImmune(CallbackInfoReturnable cir) { if (!cir.getReturnValueZ()) { - if (((Entity) (Object) this).getPersistentData().getBoolean(NetheriteDivingHandler.FIRE_IMMUNE_KEY)) + Entity self = (Entity) (Object) this; + boolean immune = self.getPersistentData().getBoolean(NetheriteDivingHandler.FIRE_IMMUNE_KEY); + if (immune) cir.setReturnValue(true); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java index 577b013aaa..b09cb72730 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LavaSwimmingMixin.java @@ -25,7 +25,8 @@ private LavaSwimmingMixin(EntityType type, Level level) { @Inject(method = "travel(Lnet/minecraft/world/phys/Vec3;)V", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isInLava()Z")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V", shift = Shift.AFTER, ordinal = 0)) private void create$onLavaTravel(Vec3 travelVector, CallbackInfo ci) { - if (AllItems.NETHERITE_DIVING_BOOTS.isIn(DivingBootsItem.getWornItem(this))) + ItemStack bootsStack = DivingBootsItem.getWornItem(this); + if (AllItems.NETHERITE_DIVING_BOOTS.isIn(bootsStack)) setDeltaMovement(getDeltaMovement().multiply(DivingBootsItem.getMovementMultiplier((LivingEntity) (Object) this))); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java index 7c9f65545e..51f8c44daa 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java @@ -30,18 +30,42 @@ @Mixin(MapItemSavedData.class) public abstract class MapItemSavedDataMixin implements StationMapData { - @Shadow @Final public int centerX; - @Shadow @Final public int centerZ; - @Shadow @Final public byte scale; - @Shadow @Final Map decorations; - @Shadow private int trackedDecorationCount; - - @Shadow protected abstract void removeDecoration(String pIdentifier); - @Shadow protected abstract void setDecorationsDirty(); - @Shadow public abstract boolean isTrackedCountOverLimit(int pTrackedCount); - - @Unique private static final String STATION_MARKERS_KEY = "create:stations"; - @Unique private final Map create$stationMarkers = Maps.newHashMap(); + @Unique + private static final String STATION_MARKERS_KEY = "create:stations"; + + + @Shadow + @Final + public int centerX; + + @Shadow + @Final + public int centerZ; + + @Shadow + @Final + public byte scale; + + @Shadow + @Final + Map decorations; + + @Shadow + private int trackedDecorationCount; + + + @Shadow + protected abstract void removeDecoration(String pIdentifier); + + @Shadow + protected abstract void setDecorationsDirty(); + + @Shadow + public abstract boolean isTrackedCountOverLimit(int pTrackedCount); + + + @Unique + private final Map create$stationMarkers = Maps.newHashMap(); @Inject( method = "load(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;", diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java index 592caf1fab..238f658f1e 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java @@ -40,14 +40,28 @@ private EntityContraptionInteractionMixin(Class baseClass) { super(baseClass); } - @Shadow private Level level; - @Shadow private Vec3 position; - @Shadow private float nextStep; - @Shadow @Final protected RandomSource random; - @Shadow private EntityDimensions dimensions; - - @Shadow protected abstract float nextStep(); - @Shadow protected abstract void playStepSound(BlockPos pos, BlockState state); + @Shadow + private Level level; + + @Shadow + private Vec3 position; + + @Shadow + private float nextStep; + + @Shadow + @Final + protected RandomSource random; + + @Shadow + private EntityDimensions dimensions; + + + @Shadow + protected abstract float nextStep(); + + @Shadow + protected abstract void playStepSound(BlockPos pos, BlockState state); @Unique private Stream create$getIntersectionContraptionsStream() { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java index 7f10eb0204..4765702c0a 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/compat/JourneyFullscreenMapMixin.java @@ -6,7 +6,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -18,9 +17,15 @@ @Mixin(Fullscreen.class) public abstract class JourneyFullscreenMapMixin { - @Shadow @Final private static GridRenderer gridRenderer; - @Shadow private Boolean isScrolling; - @Shadow protected abstract Point2D.Double getMouseDrag(); + @Shadow + @Final + private static GridRenderer gridRenderer; + + @Shadow + private Boolean isScrolling; + + @Shadow + protected abstract Point2D.Double getMouseDrag(); @Inject(method = "render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V", at = @At(target = "Ljourneymap/client/ui/fullscreen/Fullscreen;drawLogo(Lcom/mojang/blaze3d/vertex/PoseStack;)V", value = "INVOKE")) private void create$journeyMapFullscreenRender(GuiGraphics graphics, int mouseX, int mouseY, float pt, From f9c2acc261414530a771ccc8db1d9c3b6489f1c8 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 11 Oct 2024 12:35:37 -0400 Subject: [PATCH 3/4] Revert few more formating changes --- .../equipment/sandPaper/SandPaperItem.java | 5 +++-- .../foundation/item/CustomUseEffectsItem.java | 2 +- .../mixin/MapItemSavedDataMixin.java | 21 ++++++++----------- .../client/BlockDestructionProgressMixin.java | 3 ++- .../mixin/client/WindowResizeMixin.java | 4 +++- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java b/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java index df54f3b293..1a0b7d88f8 100644 --- a/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java +++ b/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java @@ -5,6 +5,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.api.TriState; import com.simibubi.create.foundation.item.CustomUseEffectsItem; import com.simibubi.create.foundation.item.render.SimpleCustomRenderer; import com.simibubi.create.foundation.mixin.accessor.LivingEntityAccessor; @@ -208,9 +209,9 @@ public boolean canPerformAction(ItemStack stack, ToolAction toolAction) { } @Override - public Boolean shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) { + public TriState shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) { // Trigger every tick so that we have more fine grain control over the animation - return true; + return TriState.TRUE; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java b/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java index 2723894db7..bad9628ab4 100644 --- a/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java +++ b/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java @@ -12,7 +12,7 @@ public interface CustomUseEffectsItem { * * @param stack The ItemStack being used. * @param entity The LivingEntity using the item. - * @return {@link TriState#DEFAULT} for default behavior, or boolean to override default behavior + * @return {@link TriState#DEFAULT} for default behavior, or {@link TriState#TRUE} to override default behavior */ default TriState shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) { return TriState.DEFAULT; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java index 51f8c44daa..d97123768f 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java @@ -33,7 +33,6 @@ public abstract class MapItemSavedDataMixin implements StationMapData { @Unique private static final String STATION_MARKERS_KEY = "create:stations"; - @Shadow @Final public int centerX; @@ -53,17 +52,6 @@ public abstract class MapItemSavedDataMixin implements StationMapData { @Shadow private int trackedDecorationCount; - - @Shadow - protected abstract void removeDecoration(String pIdentifier); - - @Shadow - protected abstract void setDecorationsDirty(); - - @Shadow - public abstract boolean isTrackedCountOverLimit(int pTrackedCount); - - @Unique private final Map create$stationMarkers = Maps.newHashMap(); @@ -122,6 +110,15 @@ public abstract class MapItemSavedDataMixin implements StationMapData { } } + @Shadow + protected abstract void removeDecoration(String pIdentifier); + + @Shadow + protected abstract void setDecorationsDirty(); + + @Shadow + public abstract boolean isTrackedCountOverLimit(int pTrackedCount); + @Override public boolean create$toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity) { double xCenter = pos.getX() + 0.5D; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java index 602b66adb4..1a6d8d3b61 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/BlockDestructionProgressMixin.java @@ -12,7 +12,8 @@ @Mixin(BlockDestructionProgress.class) public class BlockDestructionProgressMixin implements BlockDestructionProgressExtension { - @Unique private Set create$extraPositions; + @Unique + private Set create$extraPositions; @Override public Set create$getExtraPositions() { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java index 0a2dc2d0f9..d79e8b8313 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/client/WindowResizeMixin.java @@ -14,7 +14,9 @@ @Mixin(Minecraft.class) public class WindowResizeMixin { - @Shadow @Final private Window window; + @Shadow + @Final + private Window window; @Inject(method = "resizeDisplay()V", at = @At("TAIL")) private void create$updateWindowSize(CallbackInfo ci) { From cc8f2ded3a8669b436ce86690b9e12c55c1aa5c3 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 11 Oct 2024 12:37:22 -0400 Subject: [PATCH 4/4] update javadoc --- .../simibubi/create/foundation/item/CustomUseEffectsItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java b/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java index bad9628ab4..3e98d2f470 100644 --- a/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java +++ b/src/main/java/com/simibubi/create/foundation/item/CustomUseEffectsItem.java @@ -12,7 +12,7 @@ public interface CustomUseEffectsItem { * * @param stack The ItemStack being used. * @param entity The LivingEntity using the item. - * @return {@link TriState#DEFAULT} for default behavior, or {@link TriState#TRUE} to override default behavior + * @return {@link TriState#DEFAULT} for default behavior, or {@link TriState#TRUE}/{@link TriState#FALSE} to override default behavior */ default TriState shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) { return TriState.DEFAULT;