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 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 1ad079e8f..cf4566c6e 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 @@ -4,10 +4,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ButtonBlock; 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.util.ActionResult; import net.minecraft.util.Hand; @@ -35,16 +31,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 90% 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..308d060a5 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 @@ -7,12 +7,13 @@ 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 +39,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 +52,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..5cc45ea62 --- /dev/null +++ b/common/src/main/java/com/faboslav/friendsandfoes/common/block/OnUseOxidizable.java @@ -0,0 +1,111 @@ +package com.faboslav.friendsandfoes.common.block; + +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 7f713acb7..4b7a8a919 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; @@ -38,7 +36,7 @@ public void randomTick( @Override public boolean hasRandomTicks(BlockState state) { - return Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent(); + return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent(); } @Override @@ -55,16 +53,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 521b18cf7..f0f0bab18 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 @@ -3,9 +3,14 @@ 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; public final class OxidizableLightningRodBlock extends LightningRodBlock implements Oxidizable { @@ -31,11 +36,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/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 0c15b8e0d..eeca46a01 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 @@ -51,6 +51,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/FriendsAndFoesBlocks.java b/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesBlocks.java index 7a7daf5f6..f2f3c06ee 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/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesVillagerProfessions.java b/common/src/main/java/com/faboslav/friendsandfoes/common/init/FriendsAndFoesVillagerProfessions.java index e97ea0b87..91fdfef70 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/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 fda96d86c..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 @@ -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,78 +29,68 @@ 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.getWorld().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); 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); } } - @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..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 @@ -2,20 +2,27 @@ 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.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) +@Mixin(value = AbstractBlock.class, priority = 1001) public abstract class LightningRodAbstractBlockMixin { @Inject( method = "randomTick", - at = @At("TAIL") + at = @At("HEAD"), + cancellable = true ) public void friendsandfoes_randomTick( BlockState state, @@ -25,4 +32,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/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 371934710..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 @@ -1,11 +1,11 @@ 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) +@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 56cdc5866..849491004 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,8 @@ 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; import com.faboslav.friendsandfoes.common.entity.ai.brain.CopperGolemBrain; @@ -13,8 +15,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; @@ -28,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 @@ -200,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 @@ -212,5 +218,23 @@ public void friendsandfoes_randomTick( CallbackInfo ci ) { ((Degradable) this).tickDegradation(state, world, pos, random); + ci.cancel(); + } + + @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/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 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; 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 f65de3b79..8bf190ee1 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 @@ -24,7 +24,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 033577987..780342d26 100644 --- a/common/src/main/resources/friendsandfoes-common.mixins.json +++ b/common/src/main/resources/friendsandfoes-common.mixins.json @@ -9,7 +9,6 @@ }, "mixins": [ "AddCustomEntityPoseMixin", - "AxeItemMixin", "BeeEntityAccessor", "BeeEntityMixin", "BeeEntityMoveToFlowerGoalMixin", @@ -21,7 +20,6 @@ "BundleItemAccessor", "CarvedPumpkinBlockMixin", "ChickenEntityMixin", - "HoneycombItemMixin", "IllusionerEntityMixin", "IllusionerHostileEntityMixin", "IllusionerRaiderEntityMixin", 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 b580bc0f9..7c3199483 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 9debd8aba..5dbd3356f 100644 --- a/forge/src/main/java/com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java +++ b/forge/src/main/java/com/faboslav/friendsandfoes/forge/FriendsAndFoesForge.java @@ -40,6 +40,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 {