From 4c5c5ae5ba54440a4c190c61afa1640cfd80f1ae Mon Sep 17 00:00:00 2001 From: Faboslav Date: Tue, 1 Oct 2024 15:10:51 +0200 Subject: [PATCH 1/7] Replaced oxidation with separate custom logic to prevent crashes/compat issues --- .../common/block/CopperButtonBlock.java | 16 +-- ...ble.java => FriendsAndFoesOxidizable.java} | 14 +-- .../common/block/OnUseOxidizable.java | 112 ++++++++++++++++++ .../common/block/OxidizableButtonBlock.java | 18 +-- .../block/OxidizableLightningRodBlock.java | 29 ++++- .../common/mixin/AxeItemMixin.java | 71 ----------- .../common/mixin/HoneycombItemMixin.java | 18 --- .../common/mixin/LightningEntityMixin.java | 103 +++++++--------- .../mixin/LightningRodAbstractBlockMixin.java | 26 +++- .../LightningRodBlockDegradableMixin.java | 2 +- .../common/mixin/LightningRodBlockMixin.java | 22 ++++ .../common/util/WaxableBlocksMap.java | 2 +- .../friendsandfoes-common.mixins.json | 2 - 13 files changed, 246 insertions(+), 189 deletions(-) rename common/src/main/java/com/faboslav/friendsandfoes/common/block/{Oxidizable.java => FriendsAndFoesOxidizable.java} (88%) create mode 100644 common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java delete mode 100644 common/src/main/java/com/faboslav/friendsandfoes/common/mixin/AxeItemMixin.java delete mode 100644 common/src/main/java/com/faboslav/friendsandfoes/common/mixin/HoneycombItemMixin.java diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java index 67334b821..bbf5cb000 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java @@ -3,10 +3,6 @@ import net.minecraft.block.AbstractButtonBlock; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AxeItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsageContext; import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.util.ActionResult; @@ -37,16 +33,10 @@ public ActionResult onUse( Hand hand, BlockHitResult hit ) { - ItemStack itemStack = player.getStackInHand(hand); - Item itemInHand = itemStack.getItem(); + var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); - if (itemInHand instanceof AxeItem) { - ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit); - ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext); - - if (itemInHandUsageResult.isAccepted()) { - return itemInHandUsageResult; - } + if(actionResult.isAccepted()) { + return actionResult; } return super.onUse(state, world, pos, player, hand, hit); diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/Oxidizable.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java similarity index 88% rename from common/src/main/java/com/faboslav/friendsandfoes/common/block/Oxidizable.java rename to common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java index 0ca1eeaf0..54a66188a 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/Oxidizable.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java @@ -1,18 +1,20 @@ package com.faboslav.friendsandfoes.common.block; import com.faboslav.friendsandfoes.common.init.FriendsAndFoesBlocks; +import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap; import com.google.common.base.Suppliers; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.block.Oxidizable; import java.util.Optional; import java.util.function.Supplier; @SuppressWarnings({"rawtypes", "unchecked"}) -public interface Oxidizable extends net.minecraft.block.Oxidizable +public interface FriendsAndFoesOxidizable extends Oxidizable { Supplier> OXIDATION_LEVEL_INCREASES = Suppliers.memoize(() -> (BiMap) ImmutableBiMap.builder() .put(FriendsAndFoesBlocks.COPPER_BUTTON.get(), FriendsAndFoesBlocks.EXPOSED_COPPER_BUTTON.get()) @@ -38,9 +40,7 @@ static Block getUnaffectedOxidationBlock(Block block) { } static Optional getDecreasedOxidationState(BlockState state) { - return getDecreasedOxidationBlock(state.getBlock()).map((block) -> { - return block.getStateWithProperties(state); - }); + return getDecreasedOxidationBlock(state.getBlock()).map((block) -> block.getStateWithProperties(state)); } static Optional getIncreasedOxidationBlock(Block block) { @@ -53,13 +53,11 @@ static BlockState getUnaffectedOxidationState(BlockState state) { @Override default Optional getDegradationResult(BlockState state) { - return getIncreasedOxidationBlock(state.getBlock()).map((block) -> { - return block.getStateWithProperties(state); - }); + return getIncreasedOxidationBlock(state.getBlock()).map((block) -> block.getStateWithProperties(state)); } @Override default float getDegradationChanceMultiplier() { - return this.getDegradationLevel() == Oxidizable.OxidationLevel.UNAFFECTED ? 0.75F:1.0F; + return this.getDegradationLevel() == OxidationLevel.UNAFFECTED ? 0.75F:1.0F; } } \ No newline at end of file diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java new file mode 100644 index 000000000..8af90de95 --- /dev/null +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java @@ -0,0 +1,112 @@ +package com.faboslav.friendsandfoes.common.block; + +import com.faboslav.friendsandfoes.common.FriendsAndFoes; +import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap; +import com.google.common.collect.BiMap; +import net.minecraft.advancement.criterion.Criteria; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.*; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.event.GameEvent; + +import java.util.Optional; + +public final class OnUseOxidizable +{ + public static ActionResult onOxidizableUse( + BlockState blockState, + World world, + BlockPos blockPos, + PlayerEntity player, + Hand hand, + BlockHitResult hit + ) { + ItemStack itemStack = player.getStackInHand(hand); + Item itemInHand = itemStack.getItem(); + ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit); + + if(itemInHand instanceof HoneycombItem) { + Optional possibleWaxedState = OnUseOxidizable.getWaxedState(blockState); + + if(possibleWaxedState.isPresent()) { + if (player instanceof ServerPlayerEntity) { + Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity)player, blockPos, itemStack); + } + + if(!player.isCreative()) { + itemStack.decrement(1); + } + + world.setBlockState(blockPos, possibleWaxedState.get(), 11); + world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(player, possibleWaxedState.get())); + world.syncWorldEvent(player, 3003, blockPos, 0); + + return ActionResult.success(world.isClient); + }; + } else if(itemInHand instanceof AxeItem) { + Optional possibleUnWaxedState = OnUseOxidizable.getUnWaxedState(blockState); + Optional possibleOxidationState = FriendsAndFoesOxidizable.getDecreasedOxidationState(blockState); + Optional possibleState = Optional.empty(); + + if(possibleUnWaxedState.isPresent()) { + world.playSound(player, blockPos, SoundEvents.ITEM_AXE_WAX_OFF, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.syncWorldEvent(player, 3004, blockPos, 0); + possibleState = possibleUnWaxedState; + } else if(possibleOxidationState.isPresent()) { + world.playSound(player, blockPos, SoundEvents.ITEM_AXE_SCRAPE, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.syncWorldEvent(player, 3005, blockPos, 0); + possibleState = possibleOxidationState; + } + + if (possibleState.isPresent()) { + if (player instanceof ServerPlayerEntity) { + Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity)player, blockPos, itemStack); + } + + world.setBlockState(blockPos, possibleState.get(), 11); + world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(player, possibleState.get())); + + if (player != null) { + itemStack.damage(1, player, (p) -> { + p.sendToolBreakStatus(hand); + }); + } + + return ActionResult.success(world.isClient); + } else { + return ActionResult.PASS; + } + } + + if (itemInHand instanceof HoneycombItem || itemInHand instanceof AxeItem) { + ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext); + + if (itemInHandUsageResult.isAccepted()) { + return itemInHandUsageResult; + } + } + + return ActionResult.PASS; + } + + private static Optional getWaxedState(BlockState state) { + return Optional.ofNullable((Block)((BiMap) WaxableBlocksMap.UNWAXED_TO_WAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> { + return block.getStateWithProperties(state); + }); + } + + private static Optional getUnWaxedState(BlockState state) { + return Optional.ofNullable((Block)((BiMap) WaxableBlocksMap.WAXED_TO_UNWAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> { + return block.getStateWithProperties(state); + }); + } +} diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java index e0d3176bb..5a126ad8a 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java @@ -1,9 +1,7 @@ package com.faboslav.friendsandfoes.common.block; import net.minecraft.block.BlockState; -import net.minecraft.block.Oxidizable; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.*; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -13,7 +11,7 @@ import net.minecraft.world.World; @SuppressWarnings("deprecation") -public final class OxidizableButtonBlock extends CopperButtonBlock implements Oxidizable +public final class OxidizableButtonBlock extends CopperButtonBlock implements FriendsAndFoesOxidizable { private final OxidationLevel oxidationLevel; @@ -37,7 +35,7 @@ public void randomTick( @Override public boolean hasRandomTicks(BlockState state) { - return Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent(); + return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent(); } @Override @@ -54,16 +52,10 @@ public ActionResult onUse( Hand hand, BlockHitResult hit ) { - ItemStack itemStack = player.getStackInHand(hand); - Item itemInHand = itemStack.getItem(); - ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit); + var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); - if (itemInHand instanceof HoneycombItem || itemInHand instanceof AxeItem) { - ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext); - - if (itemInHandUsageResult.isAccepted()) { - return itemInHandUsageResult; - } + if(actionResult.isAccepted()) { + return actionResult; } return super.onUse(state, world, pos, player, hand, hit); diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java index fd6d3cb5e..614240754 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java @@ -2,13 +2,16 @@ import net.minecraft.block.BlockState; import net.minecraft.block.LightningRodBlock; -import net.minecraft.block.Oxidizable; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; +import net.minecraft.world.World; -@SuppressWarnings("deprecation") -public final class OxidizableLightningRodBlock extends LightningRodBlock implements Oxidizable +public final class OxidizableLightningRodBlock extends LightningRodBlock implements FriendsAndFoesOxidizable { private final OxidationLevel oxidationLevel; @@ -32,11 +35,29 @@ public void randomTick( @Override public boolean hasRandomTicks(BlockState state) { - return Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent(); + return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent(); } @Override public OxidationLevel getDegradationLevel() { return this.oxidationLevel; } + + @Override + public ActionResult onUse( + BlockState state, + World world, + BlockPos pos, + PlayerEntity player, + Hand hand, + BlockHitResult hit + ) { + var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); + + if(actionResult.isAccepted()) { + return actionResult; + } + + return super.onUse(state, world, pos, player, hand, hit); + } } \ No newline at end of file diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/AxeItemMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/AxeItemMixin.java deleted file mode 100644 index 1dc548d5b..000000000 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/AxeItemMixin.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.faboslav.friendsandfoes.common.mixin; - - -import com.faboslav.friendsandfoes.common.block.Oxidizable; -import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AxeItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import java.util.Optional; - -@Mixin(AxeItem.class) -public abstract class AxeItemMixin -{ - @ModifyVariable( - method = "useOnBlock", - ordinal = 0, - at = @At( - value = "STORE" - ) - ) - private Optional friendsandfoes_modifyOxidizedBlock( - Optional originalBlockState, - ItemUsageContext context - ) { - if (originalBlockState.isPresent()) { - return originalBlockState; - } - - World world = context.getWorld(); - BlockPos blockPos = context.getBlockPos(); - PlayerEntity playerEntity = context.getPlayer(); - BlockState state = world.getBlockState(blockPos); - - return this.friendsandfoes_tryStrip(world, blockPos, playerEntity, state); - } - - private Optional friendsandfoes_tryStrip( - World world, - BlockPos pos, - @Nullable PlayerEntity player, - BlockState state - ) { - Optional decreasedOxidationState = Oxidizable.getDecreasedOxidationState(state); - - if (decreasedOxidationState.isPresent()) { - world.playSound(player, pos, SoundEvents.ITEM_AXE_SCRAPE, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.syncWorldEvent(player, 3005, pos, 0); - return decreasedOxidationState; - } - - Optional unwaxedState = Optional.ofNullable(WaxableBlocksMap.WAXED_TO_UNWAXED_BLOCKS.get().get(state.getBlock())).map((block) -> block.getStateWithProperties(state)); - - if (unwaxedState.isPresent()) { - world.playSound(player, pos, SoundEvents.ITEM_AXE_WAX_OFF, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.syncWorldEvent(player, 3004, pos, 0); - return unwaxedState; - } - - return Optional.empty(); - } -} \ No newline at end of file diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/HoneycombItemMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/HoneycombItemMixin.java deleted file mode 100644 index 0706786a0..000000000 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/HoneycombItemMixin.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.faboslav.friendsandfoes.common.mixin; - -import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap; -import com.google.common.collect.ImmutableBiMap; -import com.llamalad7.mixinextras.injector.ModifyReceiver; -import net.minecraft.item.HoneycombItem; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(value = HoneycombItem.class, priority = 10000) -@SuppressWarnings({"rawtypes", "unchecked"}) -public abstract class HoneycombItemMixin -{ - @ModifyReceiver(method = "method_34723", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableBiMap$Builder;build()Lcom/google/common/collect/ImmutableBiMap;")) - private static ImmutableBiMap.Builder inject(ImmutableBiMap.Builder receiver) { - return receiver.putAll(WaxableBlocksMap.UNWAXED_TO_WAXED_BUTTON_BLOCKS.get()); - } -} \ No newline at end of file diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java index fbb031cf6..6be4c017d 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java @@ -1,8 +1,9 @@ package com.faboslav.friendsandfoes.common.mixin; +import com.faboslav.friendsandfoes.common.block.FriendsAndFoesOxidizable; import com.faboslav.friendsandfoes.common.tag.FriendsAndFoesTags; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.block.BlockState; +import net.minecraft.block.LightningRodBlock; import net.minecraft.block.Oxidizable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -14,8 +15,6 @@ 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.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.Iterator; import java.util.Optional; @@ -30,30 +29,13 @@ public LightningEntityMixin(EntityType type, World world) { @Shadow protected abstract BlockPos getAffectedBlockPos(); - @ModifyExpressionValue( - method = "powerLightningRod", - at = @At( - value = "INVOKE", - target = "net/minecraft/block/BlockState.isOf (Lnet/minecraft/block/Block;)Z" - ) - ) - private boolean friendsandfoes_expandPowerLightningRodIsLightningRodCondition(boolean original) { - BlockPos blockPos = this.getAffectedBlockPos(); - BlockState blockState = this.world.getBlockState(blockPos); - - return original || blockState.isIn(FriendsAndFoesTags.LIGHTNING_RODS); - } - @Inject( - at = @At( - value = "INVOKE", - target = "net/minecraft/entity/LightningEntity.powerLightningRod ()V", - ordinal = 0, - shift = At.Shift.AFTER - ), - method = "tick()V" + at = @At("TAIL"), + method = "powerLightningRod" ) - private void friendsandfoes_cleanLightningRodOxidation(CallbackInfo ci) { + private void friendsandfoes$powerLightningRod( + CallbackInfo ci + ) { BlockPos blockPos = this.getAffectedBlockPos(); BlockState blockState = this.getWorld().getBlockState(blockPos); @@ -62,46 +44,53 @@ private void friendsandfoes_cleanLightningRodOxidation(CallbackInfo ci) { blockPos, Oxidizable.getUnaffectedOxidationState(this.getWorld().getBlockState(blockPos)) ); + + ((LightningRodBlock)this.getWorld().getBlockState(blockPos).getBlock()).setPowered(blockState, this.getWorld(), blockPos); } } - @ModifyExpressionValue( - method = "cleanOxidation", - at = @At( - value = "INVOKE", - target = "net/minecraft/block/BlockState.isOf (Lnet/minecraft/block/Block;)Z" - ) - ) - private static boolean friendsandfoes_expandCleanOxidationRodIsLightningRodCondition( - boolean original, - World world, - BlockPos pos - ) { - BlockState blockState = world.getBlockState(pos); - - return original || blockState.isIn(FriendsAndFoesTags.LIGHTNING_RODS); - } @Inject( - at = @At( - value = "INVOKE", - target = "net/minecraft/block/Oxidizable.getDecreasedOxidationState (Lnet/minecraft/block/BlockState;)Ljava/util/Optional;", - ordinal = 0, - shift = At.Shift.AFTER - ), - method = "cleanOxidationAround(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Ljava/util/Optional;", - locals = LocalCapture.CAPTURE_FAILSOFT + at = @At("HEAD"), + method = "cleanOxidationAround(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos$Mutable;I)V" ) - private static void friendsandfoes_decreaseCustomOxidationStates( + private static void friendsandfoes$cleanOxidationAround( World world, BlockPos pos, - CallbackInfoReturnable> cir, - Iterator blockPosIterator, - BlockPos blockPos, - BlockState blockState + BlockPos.Mutable mutablePos, + int count, + CallbackInfo ci ) { - Oxidizable.getDecreasedOxidationState(blockState).ifPresent((state) -> { - world.setBlockState(blockPos, state); - }); + mutablePos.set(pos); + + for(int i = 0; i < count; ++i) { + Optional optional = friendsandfoes$cleanOxidationAround(world, mutablePos); + if (!optional.isPresent()) { + break; + } + + mutablePos.set(optional.get()); + } + } + + private static Optional friendsandfoes$cleanOxidationAround(World world, BlockPos pos) { + Iterator var2 = BlockPos.iterateRandomly(world.getRandom(), 10, pos, 1).iterator(); + + BlockPos blockPos; + BlockState blockState; + do { + if (!var2.hasNext()) { + return Optional.empty(); + } + + blockPos = (BlockPos)var2.next(); + blockState = world.getBlockState(blockPos); + } while(!(blockState.getBlock() instanceof Oxidizable)); + + BlockPos finalBlockPos = blockPos; + FriendsAndFoesOxidizable.getDecreasedOxidationState(blockState).ifPresent((state) -> world.setBlockState(finalBlockPos, state)); + + world.syncWorldEvent(3002, blockPos, -1); + return Optional.of(blockPos); } } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java index 00d408746..becd0d3cb 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java @@ -2,20 +2,28 @@ import net.minecraft.block.AbstractBlock; import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; +import net.minecraft.world.World; 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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(value = AbstractBlock.class, priority = 10000) public abstract class LightningRodAbstractBlockMixin { @Inject( method = "randomTick", - at = @At("TAIL") + at = @At("HEAD"), + cancellable = true ) public void friendsandfoes_randomTick( BlockState state, @@ -25,4 +33,20 @@ public void friendsandfoes_randomTick( CallbackInfo ci ) { } + + @Inject( + method = "onUse", + at = @At("HEAD"), + cancellable = true + ) + public void friendsandfoes_onUse( + BlockState state, + World world, + BlockPos pos, + PlayerEntity player, + Hand hand, + BlockHitResult hit, + CallbackInfoReturnable cir + ) { + } } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java index 371934710..7e770b95f 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java @@ -1,8 +1,8 @@ package com.faboslav.friendsandfoes.common.mixin; -import com.faboslav.friendsandfoes.common.block.Oxidizable; import net.minecraft.block.Degradable; import net.minecraft.block.LightningRodBlock; +import net.minecraft.block.Oxidizable; import org.spongepowered.asm.mixin.Mixin; @Mixin(value = LightningRodBlock.class, priority = 10000) diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java index 0869c56ed..62b8994d2 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java @@ -1,6 +1,7 @@ package com.faboslav.friendsandfoes.common.mixin; import com.faboslav.friendsandfoes.common.FriendsAndFoes; +import com.faboslav.friendsandfoes.common.block.OnUseOxidizable; import com.faboslav.friendsandfoes.common.client.render.entity.animation.KeyframeAnimation; import com.faboslav.friendsandfoes.common.entity.CopperGolemEntity; import com.faboslav.friendsandfoes.common.entity.ai.brain.CopperGolemBrain; @@ -13,8 +14,12 @@ import net.minecraft.block.pattern.BlockPattern; import net.minecraft.block.pattern.BlockPatternBuilder; import net.minecraft.block.pattern.CachedBlockPosition; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; import net.minecraft.world.World; @@ -213,4 +218,21 @@ public void friendsandfoes_randomTick( ) { ((Degradable) this).tickDegradation(state, world, pos, random); } + + @Override + public void friendsandfoes_onUse( + BlockState state, + World world, + BlockPos pos, + PlayerEntity player, + Hand hand, + BlockHitResult hit, + CallbackInfoReturnable cir + ) { + var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); + + if(actionResult.isAccepted()) { + cir.setReturnValue(actionResult); + } + } } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/util/WaxableBlocksMap.java b/common/src/main/java/com/faboslav/friendsandfoes/common/util/WaxableBlocksMap.java index 50098ec81..486b34597 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/util/WaxableBlocksMap.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/util/WaxableBlocksMap.java @@ -23,7 +23,7 @@ public final class WaxableBlocksMap .put(FriendsAndFoesBlocks.WAXED_OXIDIZED_LIGHTNING_ROD.get(), FriendsAndFoesBlocks.OXIDIZED_LIGHTNING_ROD.get()) .build()); - public static final Supplier> UNWAXED_TO_WAXED_BUTTON_BLOCKS = Suppliers.memoize(() -> (BiMap) ImmutableBiMap.builder() + public static final Supplier> UNWAXED_TO_WAXED_BLOCKS = Suppliers.memoize(() -> (BiMap) ImmutableBiMap.builder() .put(FriendsAndFoesBlocks.COPPER_BUTTON.get(), FriendsAndFoesBlocks.WAXED_COPPER_BUTTON.get()) .put(FriendsAndFoesBlocks.EXPOSED_COPPER_BUTTON.get(), FriendsAndFoesBlocks.WAXED_EXPOSED_COPPER_BUTTON.get()) .put(FriendsAndFoesBlocks.WEATHERED_COPPER_BUTTON.get(), FriendsAndFoesBlocks.WAXED_WEATHERED_COPPER_BUTTON.get()) diff --git a/common/src/main/resources/friendsandfoes-common.mixins.json b/common/src/main/resources/friendsandfoes-common.mixins.json index 541e533e6..8aaa20217 100644 --- a/common/src/main/resources/friendsandfoes-common.mixins.json +++ b/common/src/main/resources/friendsandfoes-common.mixins.json @@ -10,7 +10,6 @@ "mixins": [ "AbstractButtonBlockMixin", "AddCustomEntityPoseMixin", - "AxeItemMixin", "BeeEntityAccessor", "BeeEntityMixin", "BeeEntityMoveToFlowerGoalMixin", @@ -22,7 +21,6 @@ "BundleItemAccessor", "CarvedPumpkinBlockMixin", "ChickenEntityMixin", - "HoneycombItemMixin", "IllusionerEntityMixin", "IllusionerHostileEntityMixin", "IllusionerRaiderEntityMixin", From 01900c58054251229e01c49542bb61ce5f6b1410 Mon Sep 17 00:00:00 2001 From: Faboslav Date: Tue, 1 Oct 2024 15:11:59 +0200 Subject: [PATCH 2/7] Format --- .../common/block/CopperButtonBlock.java | 2 +- .../block/FriendsAndFoesOxidizable.java | 2 -- .../common/block/OnUseOxidizable.java | 24 +++++++++---------- .../common/block/OxidizableButtonBlock.java | 2 +- .../block/OxidizableLightningRodBlock.java | 2 +- .../renderer/MoobloomEntityRenderer.java | 1 - .../common/entity/CopperGolemEntity.java | 1 + .../FriendsAndFoesVillagerProfessions.java | 2 +- .../common/mixin/LightningEntityMixin.java | 8 +++---- .../mixin/LightningRodAbstractBlockMixin.java | 1 - .../common/mixin/LightningRodBlockMixin.java | 2 +- .../common/util/MovementUtil.java | 1 - 12 files changed, 21 insertions(+), 27 deletions(-) diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java index bbf5cb000..3d09af124 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/CopperButtonBlock.java @@ -35,7 +35,7 @@ public ActionResult onUse( ) { var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); - if(actionResult.isAccepted()) { + if (actionResult.isAccepted()) { return actionResult; } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java index 54a66188a..f8526d8e8 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java @@ -1,7 +1,6 @@ package com.faboslav.friendsandfoes.common.block; import com.faboslav.friendsandfoes.common.init.FriendsAndFoesBlocks; -import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap; import com.google.common.base.Suppliers; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; @@ -9,7 +8,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.Oxidizable; - import java.util.Optional; import java.util.function.Supplier; diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java index 8af90de95..3b594b9cd 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java @@ -1,6 +1,5 @@ package com.faboslav.friendsandfoes.common.block; -import com.faboslav.friendsandfoes.common.FriendsAndFoes; import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap; import com.google.common.collect.BiMap; import net.minecraft.advancement.criterion.Criteria; @@ -17,7 +16,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; - import java.util.Optional; public final class OnUseOxidizable @@ -34,15 +32,15 @@ public static ActionResult onOxidizableUse( Item itemInHand = itemStack.getItem(); ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit); - if(itemInHand instanceof HoneycombItem) { + if (itemInHand instanceof HoneycombItem) { Optional possibleWaxedState = OnUseOxidizable.getWaxedState(blockState); - if(possibleWaxedState.isPresent()) { + if (possibleWaxedState.isPresent()) { if (player instanceof ServerPlayerEntity) { - Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity)player, blockPos, itemStack); + Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity) player, blockPos, itemStack); } - if(!player.isCreative()) { + if (!player.isCreative()) { itemStack.decrement(1); } @@ -51,17 +49,17 @@ public static ActionResult onOxidizableUse( world.syncWorldEvent(player, 3003, blockPos, 0); return ActionResult.success(world.isClient); - }; - } else if(itemInHand instanceof AxeItem) { + } + } else if (itemInHand instanceof AxeItem) { Optional possibleUnWaxedState = OnUseOxidizable.getUnWaxedState(blockState); Optional possibleOxidationState = FriendsAndFoesOxidizable.getDecreasedOxidationState(blockState); Optional possibleState = Optional.empty(); - if(possibleUnWaxedState.isPresent()) { + if (possibleUnWaxedState.isPresent()) { world.playSound(player, blockPos, SoundEvents.ITEM_AXE_WAX_OFF, SoundCategory.BLOCKS, 1.0F, 1.0F); world.syncWorldEvent(player, 3004, blockPos, 0); possibleState = possibleUnWaxedState; - } else if(possibleOxidationState.isPresent()) { + } else if (possibleOxidationState.isPresent()) { world.playSound(player, blockPos, SoundEvents.ITEM_AXE_SCRAPE, SoundCategory.BLOCKS, 1.0F, 1.0F); world.syncWorldEvent(player, 3005, blockPos, 0); possibleState = possibleOxidationState; @@ -69,7 +67,7 @@ public static ActionResult onOxidizableUse( if (possibleState.isPresent()) { if (player instanceof ServerPlayerEntity) { - Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity)player, blockPos, itemStack); + Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity) player, blockPos, itemStack); } world.setBlockState(blockPos, possibleState.get(), 11); @@ -99,13 +97,13 @@ public static ActionResult onOxidizableUse( } private static Optional getWaxedState(BlockState state) { - return Optional.ofNullable((Block)((BiMap) WaxableBlocksMap.UNWAXED_TO_WAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> { + return Optional.ofNullable((Block) ((BiMap) WaxableBlocksMap.UNWAXED_TO_WAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> { return block.getStateWithProperties(state); }); } private static Optional getUnWaxedState(BlockState state) { - return Optional.ofNullable((Block)((BiMap) WaxableBlocksMap.WAXED_TO_UNWAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> { + return Optional.ofNullable((Block) ((BiMap) WaxableBlocksMap.WAXED_TO_UNWAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> { return block.getStateWithProperties(state); }); } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java index 5a126ad8a..5de8305eb 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableButtonBlock.java @@ -54,7 +54,7 @@ public ActionResult onUse( ) { var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); - if(actionResult.isAccepted()) { + if (actionResult.isAccepted()) { return actionResult; } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java index 614240754..3e50fdcbc 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OxidizableLightningRodBlock.java @@ -54,7 +54,7 @@ public ActionResult onUse( ) { var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); - if(actionResult.isAccepted()) { + if (actionResult.isAccepted()) { return actionResult; } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/client/render/entity/renderer/MoobloomEntityRenderer.java b/common/src/main/java/com/faboslav/friendsandfoes/common/client/render/entity/renderer/MoobloomEntityRenderer.java index 3751f7c36..40bf68a94 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/client/render/entity/renderer/MoobloomEntityRenderer.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/client/render/entity/renderer/MoobloomEntityRenderer.java @@ -9,7 +9,6 @@ import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.MobEntityRenderer; import net.minecraft.client.render.entity.model.CowEntityModel; -import net.minecraft.client.render.entity.model.EntityModelLayers; import net.minecraft.util.Identifier; @Environment(EnvType.CLIENT) diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/entity/CopperGolemEntity.java b/common/src/main/java/com/faboslav/friendsandfoes/common/entity/CopperGolemEntity.java index eae017299..9fcc19167 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/entity/CopperGolemEntity.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/entity/CopperGolemEntity.java @@ -50,6 +50,7 @@ import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; public final class CopperGolemEntity extends GolemEntity implements AnimatedEntity diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesVillagerProfessions.java b/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesVillagerProfessions.java index 48c325b49..cbef0a61e 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesVillagerProfessions.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesVillagerProfessions.java @@ -23,7 +23,7 @@ public final class FriendsAndFoesVillagerProfessions public static final RegistryEntry BEEKEEPER = VILLAGER_PROFESSIONS.register("beekeeper", () -> new VillagerProfession("beekeeper", pointOfInterest -> pointOfInterest.isIn(PointOfInterestTypeTags.BEE_HOME), pointOfInterest -> pointOfInterest.isIn(PointOfInterestTypeTags.BEE_HOME), ImmutableSet.of(Items.HONEYCOMB), ImmutableSet.of(), SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM)); public static void registerVillagerTrades(RegisterVillagerTradesEvent event) { - if(event.type() == BEEKEEPER.get()) { + if (event.type() == BEEKEEPER.get()) { event.register(1, new TradeOffersUtil.BuyForOneEmeraldFactory(FriendsAndFoesItems.BUTTERCUP.get(), 10, 16, 2)); event.register(1, new TradeOffersUtil.BuyForOneEmeraldFactory(Items.DANDELION, 10, 16, 2)); event.register(1, new TradeOffersUtil.BuyForOneEmeraldFactory(Items.SUNFLOWER, 10, 16, 2)); diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java index 6be4c017d..f728c1dcd 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java @@ -45,7 +45,7 @@ public LightningEntityMixin(EntityType type, World world) { Oxidizable.getUnaffectedOxidationState(this.getWorld().getBlockState(blockPos)) ); - ((LightningRodBlock)this.getWorld().getBlockState(blockPos).getBlock()).setPowered(blockState, this.getWorld(), blockPos); + ((LightningRodBlock) this.getWorld().getBlockState(blockPos).getBlock()).setPowered(blockState, this.getWorld(), blockPos); } } @@ -63,7 +63,7 @@ public LightningEntityMixin(EntityType type, World world) { ) { mutablePos.set(pos); - for(int i = 0; i < count; ++i) { + for (int i = 0; i < count; ++i) { Optional optional = friendsandfoes$cleanOxidationAround(world, mutablePos); if (!optional.isPresent()) { break; @@ -83,9 +83,9 @@ public LightningEntityMixin(EntityType type, World world) { return Optional.empty(); } - blockPos = (BlockPos)var2.next(); + blockPos = (BlockPos) var2.next(); blockState = world.getBlockState(blockPos); - } while(!(blockState.getBlock() instanceof Oxidizable)); + } while (!(blockState.getBlock() instanceof Oxidizable)); BlockPos finalBlockPos = blockPos; FriendsAndFoesOxidizable.getDecreasedOxidationState(blockState).ifPresent((state) -> world.setBlockState(finalBlockPos, state)); diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java index becd0d3cb..3e7a0923e 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java @@ -11,7 +11,6 @@ import net.minecraft.util.math.random.Random; import net.minecraft.world.World; 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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java index 62b8994d2..53741591c 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java @@ -231,7 +231,7 @@ public void friendsandfoes_onUse( ) { var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit); - if(actionResult.isAccepted()) { + if (actionResult.isAccepted()) { cir.setReturnValue(actionResult); } } diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/util/MovementUtil.java b/common/src/main/java/com/faboslav/friendsandfoes/common/util/MovementUtil.java index e7a6b5545..ada03c0af 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/util/MovementUtil.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/util/MovementUtil.java @@ -1,6 +1,5 @@ package com.faboslav.friendsandfoes.common.util; -import com.faboslav.friendsandfoes.common.FriendsAndFoes; import net.minecraft.entity.ai.brain.MemoryModuleType; import net.minecraft.entity.mob.MobEntity; import net.minecraft.util.math.Vec3d; From 5244fb0e2a6b594aff43e763e5e5fd34fe75d340 Mon Sep 17 00:00:00 2001 From: Faboslav Date: Tue, 1 Oct 2024 15:12:56 +0200 Subject: [PATCH 3/7] Removed unused mixin --- .../fabric/mixin/OxidizableMixin.java | 24 ------------------- .../friendsandfoes-fabric.mixins.json | 1 - 2 files changed, 25 deletions(-) delete mode 100644 fabric/src/main/java/com/faboslav/friendsandfoes/fabric/mixin/OxidizableMixin.java diff --git a/fabric/src/main/java/com/faboslav/friendsandfoes/fabric/mixin/OxidizableMixin.java b/fabric/src/main/java/com/faboslav/friendsandfoes/fabric/mixin/OxidizableMixin.java deleted file mode 100644 index e0fcad5c4..000000000 --- a/fabric/src/main/java/com/faboslav/friendsandfoes/fabric/mixin/OxidizableMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faboslav.friendsandfoes.fabric.mixin; - -import com.faboslav.friendsandfoes.common.util.OxidizableBlocksProvider; -import com.google.common.collect.ImmutableBiMap; -import com.llamalad7.mixinextras.injector.ModifyReceiver; -import net.minecraft.block.Oxidizable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(value = Oxidizable.class, priority = 10000) -@SuppressWarnings({"rawtypes", "unchecked"}) -public interface OxidizableMixin -{ - @ModifyReceiver( - method = "method_34740", - at = @At( - value = "INVOKE", - target = "Lcom/google/common/collect/ImmutableBiMap$Builder;build()Lcom/google/common/collect/ImmutableBiMap;" - ) - ) - private static ImmutableBiMap.Builder inject(ImmutableBiMap.Builder receiver) { - return receiver.putAll(OxidizableBlocksProvider.OXIDIZABLE_BLOCKS.get()); - } -} diff --git a/fabric/src/main/resources/friendsandfoes-fabric.mixins.json b/fabric/src/main/resources/friendsandfoes-fabric.mixins.json index a45eadec1..2cd2a9311 100644 --- a/fabric/src/main/resources/friendsandfoes-fabric.mixins.json +++ b/fabric/src/main/resources/friendsandfoes-fabric.mixins.json @@ -9,7 +9,6 @@ "mixins": [ "AddCustomRaidMemberMixin", "AddCustomSpawnGroupMixin", - "OxidizableMixin", "PointOfInterestTypesAccessor", "StructureEntityProcessorMixin" ], From a38fb145c5f9421f41fde27866c085750a59eb9b Mon Sep 17 00:00:00 2001 From: Faboslav Date: Tue, 1 Oct 2024 15:17:40 +0200 Subject: [PATCH 4/7] Supress warnings --- .../friendsandfoes/common/init/FriendsAndFoesBlocks.java | 1 - .../common/init/registry/forge/ForgeResourcefulRegistry.java | 1 + .../com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesBlocks.java b/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesBlocks.java index 8c491581f..f8720f8a2 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesBlocks.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesBlocks.java @@ -1,7 +1,6 @@ package com.faboslav.friendsandfoes.common.init; import com.faboslav.friendsandfoes.common.FriendsAndFoes; -import com.faboslav.friendsandfoes.common.block.Oxidizable; import com.faboslav.friendsandfoes.common.block.*; import com.faboslav.friendsandfoes.common.events.client.RegisterRenderLayersEvent; import com.faboslav.friendsandfoes.common.events.lifecycle.RegisterFlammabilityEvent; diff --git a/forge/src/main/java/com/faboslav/friendsandfoes/common/init/registry/forge/ForgeResourcefulRegistry.java b/forge/src/main/java/com/faboslav/friendsandfoes/common/init/registry/forge/ForgeResourcefulRegistry.java index e2acd153f..2605f5427 100644 --- a/forge/src/main/java/com/faboslav/friendsandfoes/common/init/registry/forge/ForgeResourcefulRegistry.java +++ b/forge/src/main/java/com/faboslav/friendsandfoes/common/init/registry/forge/ForgeResourcefulRegistry.java @@ -19,6 +19,7 @@ * @author ThatGravyBoat * https://github.com/Team-Resourceful/ResourcefulLib */ +@SuppressWarnings({"all", "deprecation", "removal"}) public class ForgeResourcefulRegistry implements ResourcefulRegistry { private final DeferredRegister register; diff --git a/forge/src/main/java/com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java b/forge/src/main/java/com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java index 13fb8de00..021baf71f 100644 --- a/forge/src/main/java/com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java +++ b/forge/src/main/java/com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java @@ -31,6 +31,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLEnvironment; +@SuppressWarnings({"all", "deprecation", "removal"}) @Mod(FriendsAndFoes.MOD_ID) public final class FriendsAndFoesForge { From 3a9133b9ef7d00f2196757b0d7fa411dff8d27cf Mon Sep 17 00:00:00 2001 From: Faboslav Date: Wed, 2 Oct 2024 15:15:20 +0200 Subject: [PATCH 5/7] Better oxidizable mixins --- .../common/mixin/LightningEntityMixin.java | 2 +- .../common/mixin/LightningRodAbstractBlockMixin.java | 2 +- .../common/mixin/LightningRodBlockBlockMixin.java | 4 ++-- .../mixin/LightningRodBlockDegradableMixin.java | 2 +- .../common/mixin/LightningRodBlockMixin.java | 8 +++++--- .../mixin/LightningRodBlockOxidizableMixin.java | 11 ++++++++++- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java index f728c1dcd..890d166dc 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningEntityMixin.java @@ -42,7 +42,7 @@ public LightningEntityMixin(EntityType type, World world) { if (blockState.isIn(FriendsAndFoesTags.LIGHTNING_RODS)) { this.getWorld().setBlockState( blockPos, - Oxidizable.getUnaffectedOxidationState(this.getWorld().getBlockState(blockPos)) + FriendsAndFoesOxidizable.getUnaffectedOxidationState(this.getWorld().getBlockState(blockPos)) ); ((LightningRodBlock) this.getWorld().getBlockState(blockPos).getBlock()).setPowered(blockState, this.getWorld(), blockPos); diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java index 3e7a0923e..8169a6801 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodAbstractBlockMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(value = AbstractBlock.class, priority = 10000) +@Mixin(value = AbstractBlock.class, priority = 1001) public abstract class LightningRodAbstractBlockMixin { @Inject( diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockBlockMixin.java index 5902dbf56..892f339a7 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockBlockMixin.java @@ -7,12 +7,12 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(value = Block.class, priority = 10000) +@Mixin(value = Block.class, priority = 1001) public abstract class LightningRodBlockBlockMixin extends LightningRodAbstractBlockMixin { @Inject( method = "hasRandomTicks", - at = @At("TAIL"), + at = @At("HEAD"), cancellable = true ) public void friendsandfoes_hasRandomTicks( diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java index 7e770b95f..f6fa10d94 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockDegradableMixin.java @@ -5,7 +5,7 @@ import net.minecraft.block.Oxidizable; import org.spongepowered.asm.mixin.Mixin; -@Mixin(value = LightningRodBlock.class, priority = 10000) +@Mixin(value = LightningRodBlock.class, priority = 1003) public abstract class LightningRodBlockDegradableMixin implements Degradable { @Override diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java index 53741591c..84faa2d6c 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java @@ -1,6 +1,7 @@ package com.faboslav.friendsandfoes.common.mixin; import com.faboslav.friendsandfoes.common.FriendsAndFoes; +import com.faboslav.friendsandfoes.common.block.FriendsAndFoesOxidizable; import com.faboslav.friendsandfoes.common.block.OnUseOxidizable; import com.faboslav.friendsandfoes.common.client.render.entity.animation.KeyframeAnimation; import com.faboslav.friendsandfoes.common.entity.CopperGolemEntity; @@ -33,7 +34,7 @@ import java.util.ArrayList; -@Mixin(value = LightningRodBlock.class, priority = 10000) +@Mixin(value = LightningRodBlock.class, priority = 1001) public abstract class LightningRodBlockMixin extends LightningRodBlockBlockMixin { @Nullable @@ -205,7 +206,7 @@ private boolean friendsandfoes_isCopperBlockWaxed( public void friendsandfoes_hasRandomTicks( BlockState state, CallbackInfoReturnable cir ) { - cir.setReturnValue(Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent()); + cir.setReturnValue(FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent()); } @Override @@ -216,7 +217,8 @@ public void friendsandfoes_randomTick( Random random, CallbackInfo ci ) { - ((Degradable) this).tickDegradation(state, world, pos, random); + ((Degradable)this).tickDegradation(state, world, pos, random); + ci.cancel(); } @Override diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockOxidizableMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockOxidizableMixin.java index a12f57b4a..5a79002b7 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockOxidizableMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockOxidizableMixin.java @@ -1,14 +1,23 @@ package com.faboslav.friendsandfoes.common.mixin; +import com.faboslav.friendsandfoes.common.block.FriendsAndFoesOxidizable; +import net.minecraft.block.BlockState; import net.minecraft.block.LightningRodBlock; import net.minecraft.block.Oxidizable; import net.minecraft.block.RodBlock; import org.spongepowered.asm.mixin.Mixin; -@Mixin(value = LightningRodBlock.class, priority = 10000) +import java.util.Optional; + +@Mixin(value = LightningRodBlock.class, priority = 1002) public abstract class LightningRodBlockOxidizableMixin extends RodBlock implements Oxidizable { public LightningRodBlockOxidizableMixin(Settings settings) { super(settings); } + + @Override + public Optional getDegradationResult(BlockState state) { + return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).map((block) -> block.getStateWithProperties(state)); + } } \ No newline at end of file From d931a993ee3434b73d5da9f727ad9b4843b83cf2 Mon Sep 17 00:00:00 2001 From: Faboslav Date: Wed, 2 Oct 2024 15:16:35 +0200 Subject: [PATCH 6/7] format --- .../friendsandfoes/common/block/FriendsAndFoesOxidizable.java | 1 + .../faboslav/friendsandfoes/common/block/OnUseOxidizable.java | 1 + .../friendsandfoes/common/mixin/LightningRodBlockMixin.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java index f8526d8e8..308d060a5 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/FriendsAndFoesOxidizable.java @@ -8,6 +8,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.Oxidizable; + import java.util.Optional; import java.util.function.Supplier; diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java index 3b594b9cd..5cc45ea62 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java @@ -16,6 +16,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; + import java.util.Optional; public final class OnUseOxidizable diff --git a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java index 84faa2d6c..d8d371808 100644 --- a/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/mixin/LightningRodBlockMixin.java @@ -217,7 +217,7 @@ public void friendsandfoes_randomTick( Random random, CallbackInfo ci ) { - ((Degradable)this).tickDegradation(state, world, pos, random); + ((Degradable) this).tickDegradation(state, world, pos, random); ci.cancel(); } From 5bb9f814a5bfcd4ab8cb6273f509788c0aaa07f9 Mon Sep 17 00:00:00 2001 From: Faboslav Date: Wed, 2 Oct 2024 17:16:00 +0200 Subject: [PATCH 7/7] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a3a62bd0..59f2c051a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.0.4 - Improved internal registries logic (Might fix some crashes) +- Mod should now not crash with mods like Caverns & Chasms and Unvoted & Shelved ## 3.0.3