From b66af8446ccbe5ba5f9c75f8ebd0dc256a96774a Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:33:59 -0600 Subject: [PATCH] * Fixed Farmer not playing well with non vanilla farmland. * Added the ability to change the farmers work area with a compass. * Code cleaning. --- CHANGELOG.md | 4 + gradle.properties | 2 +- .../mod/ActuallyAdditions.java | 11 +- .../mod/blocks/BlockAtomicReconstructor.java | 26 +---- .../mod/blocks/BlockCrusher.java | 14 --- .../mod/blocks/BlockDropper.java | 18 --- .../mod/blocks/BlockEnergizer.java | 8 -- .../mod/blocks/BlockFarmer.java | 36 +++--- .../mod/blocks/BlockFeeder.java | 5 - .../mod/blocks/BlockFluidCollector.java | 19 --- .../mod/blocks/BlockMisc.java | 108 ------------------ .../mod/blocks/base/BlockContainerBase.java | 78 ++----------- .../mod/blocks/blockhuds/FarmerHud.java | 37 ++++++ .../blocks/blockhuds/ReconstructorHud.java | 4 +- .../mod/config/CommonConfig.java | 3 + .../apiimpl/farmer/DefaultFarmerBehavior.java | 11 +- .../mod/tile/TileEntityFarmer.java | 32 +++++- .../assets/actuallyadditions/lang/en_us.json | 3 + 18 files changed, 122 insertions(+), 297 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockMisc.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/FarmerHud.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 99c6eba50..25f9ab4f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.3.11+mc1.21.1 +* Fixed Farmer not playing well with non vanilla farmland. +* Added the ability to change the farmers work area with a compass. + # 1.3.10+mc1.21.1 * Fixed Fluid placer not being harvestable. * PR #1438, Added config to disable energy overlay. diff --git a/gradle.properties b/gradle.properties index 94a6fa861..2877a9b6d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.parallel=true org.gradle.caching=true org.gradle.configuration-cache=false -mod_version=1.3.10 +mod_version=1.3.11 # Forge game_version=1.21.1 diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index fccf5bacd..0a94d1ea3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -40,7 +40,6 @@ import de.ellpeck.actuallyadditions.mod.util.ResourceReloader; import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; @@ -139,10 +138,12 @@ public class ActuallyAdditions { private void onConfigReload(ModConfigEvent event) { if (event.getConfig().getType() == ModConfig.Type.COMMON) { - Item item1 = BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(CommonConfig.Other.REDSTONECONFIGURATOR.get())); - Item item2 = BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(CommonConfig.Other.RELAYCONFIGURATOR.get())); - CommonConfig.Other.redstoneConfigureItem = item1 != null ? item1 : Items.AIR; - CommonConfig.Other.relayConfigureItem = item2 != null ? item2 : Items.AIR; + CommonConfig.Other.redstoneConfigureItem = + BuiltInRegistries.ITEM.getOptional(ResourceLocation.tryParse(CommonConfig.Other.REDSTONECONFIGURATOR.get())).orElse(Items.AIR); + CommonConfig.Other.relayConfigureItem = + BuiltInRegistries.ITEM.getOptional(ResourceLocation.tryParse(CommonConfig.Other.RELAYCONFIGURATOR.get())).orElse(Items.AIR); + CommonConfig.Other.farmerConfigureItem = + BuiltInRegistries.ITEM.getOptional(ResourceLocation.tryParse(CommonConfig.Other.FARMERCONFIG.get())).orElse(Items.AIR); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java index 5d7b13c4b..d136f13eb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java @@ -90,24 +90,6 @@ public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container im return ItemInteractionResult.CONSUME; } -/* @Override - public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - switch (state.getValue(FACING)) { - case UP: - return VoxelShapes.AtomicReconstructorShapes.SHAPE_U; - case DOWN: - return VoxelShapes.AtomicReconstructorShapes.SHAPE_D; - case EAST: - return VoxelShapes.AtomicReconstructorShapes.SHAPE_E; - case SOUTH: - return VoxelShapes.AtomicReconstructorShapes.SHAPE_S; - case WEST: - return VoxelShapes.AtomicReconstructorShapes.SHAPE_W; - default: - return VoxelShapes.AtomicReconstructorShapes.SHAPE_N; - } - }*/ - @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @@ -139,7 +121,7 @@ public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container im @Override - public void appendHoverText(@Nonnull ItemStack pStack, @Nullable TooltipContext context, @Nonnull List pTooltip, @Nonnull TooltipFlag pFlag) { + public void appendHoverText(@Nonnull ItemStack pStack, @Nonnull TooltipContext context, @Nonnull List pTooltip, @Nonnull TooltipFlag pFlag) { super.appendHoverText(pStack, context, pTooltip, pFlag); long sysTime = System.currentTimeMillis(); @@ -169,11 +151,7 @@ public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container im @Override protected boolean updateCustomBlockEntityTag(BlockPos pPos, Level pLevel, @Nullable Player pPlayer, ItemStack pStack, BlockState pState) { - boolean ret = super.updateCustomBlockEntityTag(pPos, pLevel, pPlayer, pStack, pState); - - - - return ret; + return super.updateCustomBlockEntityTag(pPos, pLevel, pPlayer, pStack, pState); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrusher.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrusher.java index a75a4531a..c9cd3b6b2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrusher.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrusher.java @@ -100,18 +100,4 @@ public class BlockCrusher extends BlockContainerBase { ? 12 : 0; } - -/* @Override - public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - switch (state.getValue(HORIZONTAL_FACING)) { - case EAST: - return VoxelShapes.GrinderShapes.SHAPE_E; - case SOUTH: - return VoxelShapes.GrinderShapes.SHAPE_S; - case WEST: - return VoxelShapes.GrinderShapes.SHAPE_W; - default: - return VoxelShapes.GrinderShapes.SHAPE_N; - } - }*/ } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDropper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDropper.java index c8a669c34..12be6baf8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDropper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDropper.java @@ -50,22 +50,4 @@ public class BlockDropper extends FullyDirectionalBlock.Container { return this.openGui(world, player, pos, TileEntityDropper.class); } - -/* @Override - public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - switch (state.getValue(FACING)) { - case UP: - return VoxelShapes.BlockBreakerShapes.SHAPE_U; - case DOWN: - return VoxelShapes.BlockBreakerShapes.SHAPE_D; - case EAST: - return VoxelShapes.BlockBreakerShapes.SHAPE_E; - case SOUTH: - return VoxelShapes.BlockBreakerShapes.SHAPE_S; - case WEST: - return VoxelShapes.BlockBreakerShapes.SHAPE_W; - default: - return VoxelShapes.BlockBreakerShapes.SHAPE_N; - } - }*/ } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEnergizer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEnergizer.java index a976d60fa..510fc1f2f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEnergizer.java @@ -58,12 +58,4 @@ public class BlockEnergizer extends BlockContainerBase { return this.openGui(world, player, pos, TileEntityEnervator.class); } } - -/* @Override - public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - if (this.isEnergizer) { - return VoxelShapes.ENERGIZER_SHAPE; - } - return VoxelShapes.ENERVATOR_SHAPE; - }*/ } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java index 65bcf6117..98fed33af 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java @@ -11,10 +11,16 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock; +import de.ellpeck.actuallyadditions.mod.blocks.blockhuds.FarmerHud; +import de.ellpeck.actuallyadditions.mod.blocks.blockhuds.IBlockHud; +import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.tile.TileEntityFarmer; import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntity; @@ -25,7 +31,8 @@ import net.minecraft.world.phys.BlockHitResult; import javax.annotation.Nullable; -public class BlockFarmer extends DirectionalBlock.Container { +public class BlockFarmer extends DirectionalBlock.Container implements IHudDisplay { + private static final IBlockHud HUD = new FarmerHud(); public BlockFarmer() { super(ActuallyBlocks.defaultPickProps().sound(SoundType.METAL)); @@ -48,17 +55,20 @@ public class BlockFarmer extends DirectionalBlock.Container { return this.openGui(world, player, pos, TileEntityFarmer.class); } -/* @Override - public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - switch (state.getValue(FACING)) { - case EAST: - return VoxelShapes.FarmerShapes.SHAPE_E; - case SOUTH: - return VoxelShapes.FarmerShapes.SHAPE_S; - case WEST: - return VoxelShapes.FarmerShapes.SHAPE_W; - default: - return VoxelShapes.FarmerShapes.SHAPE_N; + @Override + protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) { + ItemStack heldItem = player.getItemInHand(hand); + BlockEntity tile = level.getBlockEntity(pos); + if (heldItem.getItem() == CommonConfig.Other.farmerConfigureItem && tile instanceof TileEntityFarmer farmer) { + farmer.cycleArea(); + return ItemInteractionResult.SUCCESS; } - }*/ + + return super.useItemOn(stack, state, level, pos, player, hand, hitResult); + } + + @Override + public IBlockHud getHud() { + return HUD; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFeeder.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFeeder.java index e24b70619..f411f86d4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFeeder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFeeder.java @@ -46,9 +46,4 @@ public class BlockFeeder extends BlockContainerBase { protected InteractionResult useWithoutItem(BlockState pState, Level world, BlockPos pos, Player player, BlockHitResult pHitResult) { return this.openGui(world, player, pos, TileEntityFeeder.class); } - -/* @Override - public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - return VoxelShapes.FEEDER_SHAPE; - }*/ } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java index 8e0b1e483..d8092790d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java @@ -69,23 +69,4 @@ public class BlockFluidCollector extends FullyDirectionalBlock.Container { return this.openGui2(world, player, pos, TileEntityFluidCollector.class); } - -/* @Nonnull - @Override - public VoxelShape getShape(BlockState state, @Nonnull BlockGetter worldIn, @Nonnull BlockPos pos, @Nonnull CollisionContext context) { - switch (state.getValue(FACING)) { - case UP: - return VoxelShapes.FluidCollectorShapes.SHAPE_U; - case DOWN: - return VoxelShapes.FluidCollectorShapes.SHAPE_D; - case EAST: - return VoxelShapes.FluidCollectorShapes.SHAPE_E; - case SOUTH: - return VoxelShapes.FluidCollectorShapes.SHAPE_S; - case WEST: - return VoxelShapes.FluidCollectorShapes.SHAPE_W; - default: - return VoxelShapes.FluidCollectorShapes.SHAPE_N; - } - }*/ } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockMisc.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockMisc.java deleted file mode 100644 index 821cbf3d7..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockMisc.java +++ /dev/null @@ -1,108 +0,0 @@ -///* -// * This file ("BlockMisc.java") is part of the Actually Additions mod for Minecraft. -// * It is created and owned by Ellpeck and distributed -// * under the Actually Additions License to be found at -// * http://ellpeck.de/actaddlicense -// * View the source code at https://github.com/Ellpeck/ActuallyAdditions -// * -// * © 2015-2017 Ellpeck -// */ -// -//package de.ellpeck.actuallyadditions.mod.blocks; -// -//import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -//import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase; -//import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase; -//import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks; -//import de.ellpeck.actuallyadditions.mod.util.StringUtil; -//import net.minecraft.block.Block; -//import net.minecraft.block.material.Material; -//import net.minecraft.block.properties.PropertyEnum; -//import net.minecraft.block.state.BlockStateContainer; -//import net.minecraft.creativetab.CreativeTabs; -//import net.minecraft.item.EnumRarity; -//import net.minecraft.item.ItemStack; -//import net.minecraft.util.NonNullList; -// -//public class BlockMisc extends BlockBase { -// -// public static final TheMiscBlocks[] ALL_MISC_BLOCKS = TheMiscBlocks.values(); -// public static final PropertyEnum TYPE = PropertyEnum.create("type", TheMiscBlocks.class); -// -// public BlockMisc() { -// super(Material.ROCK); -// this.setHardness(1.5F); -// this.setResistance(10.0F); -// this.setHarvestLevel("pickaxe", 1); -// } -// -// @Override -// public int damageDropped(BlockState state) { -// return this.getMetaFromState(state); -// } -// -// @Override -// public void getSubBlocks(CreativeTabs tab, NonNullList list) { -// for (int j = 0; j < ALL_MISC_BLOCKS.length; j++) { -// list.add(new ItemStack(this, 1, j)); -// } -// } -// -// @Override -// protected ItemBlockBase getItemBlock() { -// return new TheItemBlock(this); -// } -// -// @Override -// public void registerRendering() { -// for (int i = 0; i < ALL_MISC_BLOCKS.length; i++) { -// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName() + "=" + ALL_MISC_BLOCKS[i].name); -// } -// } -// -// @Override -// public EnumRarity getRarity(ItemStack stack) { -// return stack.getItemDamage() >= ALL_MISC_BLOCKS.length -// ? EnumRarity.COMMON -// : ALL_MISC_BLOCKS[stack.getItemDamage()].rarity; -// } -// -// @Override -// public BlockState getStateFromMeta(int meta) { -// return this.getDefaultState().withProperty(TYPE, TheMiscBlocks.values()[meta]); -// } -// -// @Override -// public int getMetaFromState(BlockState state) { -// return state.getValue(TYPE).ordinal(); -// } -// -// @Override -// protected BlockStateContainer createBlockState() { -// return new BlockStateContainer(this, TYPE); -// } -// -// public static class TheItemBlock extends ItemBlockBase { -// -// public TheItemBlock(Block block) { -// super(block); -// this.setHasSubtypes(true); -// this.setMaxDamage(0); -// } -// -// @Override -// public String getTranslationKey(ItemStack stack) { -// return stack.getItemDamage() >= ALL_MISC_BLOCKS.length -// ? StringUtil.BUGGED_ITEM_NAME -// : this.getTranslationKey() + "_" + ALL_MISC_BLOCKS[stack.getItemDamage()].name; -// } -// -// @Override -// public int getItemBurnTime(ItemStack stack) { -// if (stack.getMetadata() == TheMiscBlocks.CHARCOAL_BLOCK.ordinal()) { -// return 16000; -// } -// return super.getItemBurnTime(stack); -// } -// } -//} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java index 91e3e4177..5203cc812 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java @@ -22,7 +22,6 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.MenuProvider; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -38,7 +37,6 @@ import net.neoforged.neoforge.fluids.FluidUtil; import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; -import javax.annotation.Nullable; public abstract class BlockContainerBase extends Block implements EntityBlock { public BlockContainerBase(Properties properties) { @@ -73,7 +71,7 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { if (!world.isClientSide) { BlockEntity aTile = world.getBlockEntity(position); if (aTile instanceof TileEntityInventoryBase tile) { - if (tile.inv.getSlots() > 0) { + if (tile.inv.getSlots() > 0) { for (int i = 0; i < tile.inv.getSlots(); i++) { this.dropSlotFromInventory(i, tile, world, position); } @@ -142,7 +140,7 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { } @Override - public void onNeighborChange(BlockState state, LevelReader world, BlockPos pos, BlockPos neighbor) { + public void onNeighborChange(@Nonnull BlockState state, @Nonnull LevelReader world, @Nonnull BlockPos pos, @Nonnull BlockPos neighbor) { super.onNeighborChange(state, world, pos, neighbor); if (world instanceof Level) { //TODO what? this.neighborsChangedCustom((Level) world, pos); @@ -181,19 +179,9 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { this.updateRedstoneState(worldIn, pos); } + @Nonnull @Override - public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { -// if (stack.hasTag()) { -// BlockEntity tile = world.getBlockEntity(pos); -// if (tile instanceof TileEntityBase base) { -// CompoundTag compound = stack.get(DataComponents.BLOCK_ENTITY_DATA).getCompound("Data"); -// base.readSyncableNBT(compound, world.registryAccess(), TileEntityBase.NBTType.SAVE_BLOCK); TODO: Check if this is still required -// } -// } - } - - @Override - public BlockState playerWillDestroy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, Player player) { + public BlockState playerWillDestroy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Player player) { BlockState theState = super.playerWillDestroy(world, pos, state, player); if (!player.isCreative() && world.getBlockEntity(pos) instanceof TileEntityBase tileBase && tileBase.stopFromDropping) { if (!world.isClientSide) @@ -204,12 +192,12 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { } @Override - public boolean hasAnalogOutputSignal(BlockState state) { + public boolean hasAnalogOutputSignal(@Nonnull BlockState state) { return true; } @Override - public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { + public int getAnalogOutputSignal(@Nonnull BlockState state, Level world, @Nonnull BlockPos pos) { BlockEntity tile = world.getBlockEntity(pos); if (tile instanceof TileEntityBase) { return ((TileEntityBase) tile).getComparatorStrength(); @@ -217,62 +205,14 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { return 0; } - // TODO: [port]: come back and fix this - - // @Override - // public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, BlockState state, int fortune) { - // TileEntity tile = world.getTileEntity(pos); - // if (tile instanceof TileEntityBase) { - // TileEntityBase base = (TileEntityBase) tile; - // if (!base.stopFromDropping) { - // CompoundNBT data = new CompoundNBT(); - // base.writeSyncableNBT(data, TileEntityBase.NBTType.SAVE_BLOCK); - // - // //Remove unnecessarily saved default values to avoid unstackability - // List keysToRemove = new ArrayList<>(); - // for (String key : data.getKeySet()) { - // NBTBase tag = data.getTag(key); - // //Remove only ints because they are the most common ones - // //Add else if below here to remove more types - // if (tag instanceof NBTTagInt) { - // if (((NBTTagInt) tag).getInt() == 0) { - // keysToRemove.add(key); - // } - // } - // } - // for (String key : keysToRemove) { - // data.removeTag(key); - // } - // - // ItemStack stack = new ItemStack(this.getItemDropped(state, tile.getWorld().rand, fortune), 1, this.damageDropped(state)); - // if (!data.isEmpty()) { - // stack.setTagCompound(new CompoundNBT()); - // stack.getTagCompound().setTag("Data", data); - // } - // - // drops.add(stack); - // } - // } else { - // super.getDrops(drops, world, pos, state, fortune); - // } - // } - - - // TODO: [port]: eval - - // @Override - // public EnumBlockRenderType getRenderType(BlockState state) { - // return EnumBlockRenderType.MODEL; - // } - - + @Nonnull @Override - public RenderShape getRenderShape(BlockState pState) { + public RenderShape getRenderShape(@Nonnull BlockState pState) { return RenderShape.MODEL; } @Override - public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) { + public void onRemove(BlockState state, @Nonnull Level world, @Nonnull BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { if (this.shouldDropInventory(world, pos)) { this.dropInventory(world, pos); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/FarmerHud.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/FarmerHud.java new file mode 100644 index 000000000..ba8018f48 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/FarmerHud.java @@ -0,0 +1,37 @@ +package de.ellpeck.actuallyadditions.mod.blocks.blockhuds; + +import com.mojang.blaze3d.platform.Window; +import de.ellpeck.actuallyadditions.mod.config.CommonConfig; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityFarmer; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; + +public class FarmerHud implements IBlockHud { + @Override + public void displayHud(GuiGraphics guiGraphics, Minecraft minecraft, Player player, ItemStack stack, HitResult rayCast, Window resolution) { + if (!(rayCast instanceof BlockHitResult) || minecraft.level == null) { + return; + } + + BlockEntity tile = minecraft.level.getBlockEntity(((BlockHitResult) rayCast).getBlockPos()); + if (tile instanceof TileEntityFarmer farmer) { + guiGraphics.drawString(minecraft.font, Component.translatable("info.actuallyadditions.farmer.area", farmer.getArea(), farmer.getArea()), (int) (resolution.getGuiScaledWidth() / 2.0f + 5), (int) (resolution.getGuiScaledHeight() / 2.0f - 0), 0xFFFFFF); + + Component message; + if (!stack.isEmpty() && stack.getItem() == CommonConfig.Other.farmerConfigureItem) { + message = Component.translatable("info.actuallyadditions.farmer.validItem").withStyle(ChatFormatting.GREEN); + } else { + message = Component.translatable("info.actuallyadditions.farmer.invalidItem", Component.translatable(CommonConfig.Other.farmerConfigureItem.asItem().getDescriptionId()).getString()).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC); + } + guiGraphics.drawString(minecraft.font, message, (int) (minecraft.getWindow().getGuiScaledWidth() / 2f + 5), (int) (minecraft.getWindow().getGuiScaledHeight() / 2f + 15), 0xFFFFFF); + + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/ReconstructorHud.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/ReconstructorHud.java index c46b57291..3a7f96738 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/ReconstructorHud.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/blockhuds/ReconstructorHud.java @@ -24,8 +24,8 @@ public class ReconstructorHud implements IBlockHud { } BlockEntity tile = minecraft.level.getBlockEntity(((BlockHitResult) rayCast).getBlockPos()); - if (tile instanceof TileEntityAtomicReconstructor) { - ItemStack slot = ((TileEntityAtomicReconstructor) tile).inv.getStackInSlot(0); + if (tile instanceof TileEntityAtomicReconstructor laser) { + ItemStack slot = laser.inv.getStackInSlot(0); Component lens_name; if (slot.isEmpty()) { lens_name = Component.translatable("info.actuallyadditions.nolens"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java index c3892768b..8534577f9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java @@ -107,8 +107,10 @@ public class CommonConfig { public static ModConfigSpec.BooleanValue MOST_BLAND_PERSON_EVER; public static ModConfigSpec.ConfigValue REDSTONECONFIGURATOR; public static ModConfigSpec.ConfigValue RELAYCONFIGURATOR; + public static ModConfigSpec.ConfigValue FARMERCONFIG; public static Item redstoneConfigureItem = Items.AIR; public static Item relayConfigureItem = Items.AIR; + public static Item farmerConfigureItem = Items.AIR; public static void build() { @@ -164,6 +166,7 @@ public class CommonConfig { REDSTONECONFIGURATOR = BUILDER.comment("define the item used to configure Redstone Mode").define("redstoneConfigurator", "minecraft:redstone_torch"); RELAYCONFIGURATOR = BUILDER.comment("define the item used to configure Direction in laser relays").define("relayConfigurator", "minecraft:compass"); + FARMERCONFIG = BUILDER.comment("define the item used to configure the area in a farmer").define("farmerConfigurator", "minecraft:compass"); BUILDER.pop(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java index 41e8cedee..6d02407ba 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java @@ -26,10 +26,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.CropBlock; -import net.minecraft.world.level.block.StemBlock; +import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.storage.loot.LootParams; @@ -47,8 +44,8 @@ public class DefaultFarmerBehavior implements IFarmerBehavior { public static boolean defaultPlant(Level world, BlockPos pos, BlockState toPlant, IFarmer farmer, int use) { if (toPlant != null) { BlockPos farmland = pos.below(); - BlockState farmlandState = world.getBlockState(farmland); - if (farmlandState.is(BlockTags.DIRT) || farmlandState.is(Blocks.GRASS_BLOCK)) { + BlockState targetBlockstate = world.getBlockState(farmland); + if (!(targetBlockstate.getBlock() instanceof FarmBlock) && (targetBlockstate.is(BlockTags.DIRT) || targetBlockstate.is(Blocks.GRASS_BLOCK))) { world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState()); useHoeAt(world, farmland); world.playSound(null, farmland, SoundEvents.HOE_TILL, SoundSource.BLOCKS, 1.0F, 1.0F); @@ -183,7 +180,7 @@ public class DefaultFarmerBehavior implements IFarmerBehavior { ItemStack itemstack = getHoeStack(); - if (!player.mayUseItemAt(pos.relative(Direction.UP), Direction.UP, itemstack)) { + if (!player.mayUseItemAt(pos.relative(Direction.UP), Direction.UP, itemstack)) { //TODO this does nothing. -Flanks return InteractionResult.FAIL; } else { // UseOnContext dummyContext = new UseOnContext(world, player, InteractionHand.MAIN_HAND, itemstack, new BlockHitResult(new Vec3(0.5, 0.5, 0.5), Direction.UP, pos, false)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java index 28925e44c..df1f3e113 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -56,6 +56,8 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer private int lastEnergy; + private int area; + public TileEntityFarmer(BlockPos pos, BlockState state) { super(ActuallyBlocks.FARMER.getTileEntityType(), pos, state, 12); } @@ -69,6 +71,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer compound.putInt("CheckX", this.checkX); compound.putInt("CheckY", this.checkY); } + compound.putInt("Area", this.area); this.storage.writeToNBT(compound); super.writeSyncableNBT(compound, lookupProvider, type); } @@ -82,6 +85,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer this.checkX = compound.getInt("CheckX"); this.checkY = compound.getInt("CheckY"); } + this.area = compound.contains("Area") ?compound.getInt("Area"):CommonConfig.Machines.FARMER_AREA.get(); this.storage.readFromNBT(compound); super.readSyncableNBT(compound, lookupProvider, type); } @@ -97,15 +101,15 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer tile.serverTick(); if (!tile.isRedstonePowered && tile.storage.getEnergyStored() > 0) { + int localArea = Math.min(tile.area, CommonConfig.Machines.FARMER_AREA.get()); if (tile.waitTime > 0) { tile.waitTime--; if (tile.waitTime <= 0) { - int area = CommonConfig.Machines.FARMER_AREA.get(); - if (area % 2 == 0) { - area++; + if (localArea % 2 == 0) { + localArea++; } - int radius = area / 2; + int radius = localArea / 2; BlockPos center = pos.relative(state.getValue(BlockStateProperties.HORIZONTAL_FACING), radius + 1); @@ -194,6 +198,26 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer return this.worldPosition; } + public int getArea() { + return this.area; + } + + public void setArea(int area) { + this.area = Math.min(area, CommonConfig.Machines.FARMER_AREA.get()); + } + + public int cycleArea() { + if (this.area >= CommonConfig.Machines.FARMER_AREA.get()) + this.area = 1; + else + this.area+= 2; + + this.checkY = 0; // Reset the current position so we dont go off the rails and plant behind the machine when spamming area changes. + this.checkX = 0; + + return this.area; + } + @Override public int getX() { return this.worldPosition.getX(); diff --git a/src/main/resources/assets/actuallyadditions/lang/en_us.json b/src/main/resources/assets/actuallyadditions/lang/en_us.json index 759964d57..b4eebd50f 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/main/resources/assets/actuallyadditions/lang/en_us.json @@ -507,6 +507,9 @@ "info.actuallyadditions.redstoneMode.deactivation": "Deactivation", "info.actuallyadditions.redstoneMode.invalidItem": "Hold a %s to toggle!", "info.actuallyadditions.redstoneMode.validItem": "Right-Click to toggle!", + "info.actuallyadditions.farmer.validItem": "Right-Click to change area!", + "info.actuallyadditions.farmer.invalidItem": "Hold a %s to modify farming area!", + "info.actuallyadditions.farmer.area": "Area: %dx%d", "info.actuallyadditions.laserRelay.item.extra": "Priority", "info.actuallyadditions.laserRelay.item.display.1": "Right-Click to increase!", "info.actuallyadditions.laserRelay.item.display.2": "Sneak-Right-Click to decrease!",