diff --git a/src/main/java/net/dries007/tfc/CommonEventHandler.java b/src/main/java/net/dries007/tfc/CommonEventHandler.java index cede523341..5b5fc6f76a 100644 --- a/src/main/java/net/dries007/tfc/CommonEventHandler.java +++ b/src/main/java/net/dries007/tfc/CommonEventHandler.java @@ -155,10 +155,13 @@ public static void onRightClickItem(PlayerInteractEvent.RightClickItem event) { if (placeable.placeItemInWorld(world, pos, stack, player, event.getFace(), null)) { - player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, player, 1)); + if (placeable.consumeAmount() > 0) + { + player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, player, placeable.consumeAmount())); + } + event.setCancellationResult(EnumActionResult.SUCCESS); + event.setCanceled(true); } - event.setCancellationResult(EnumActionResult.SUCCESS); - event.setCanceled(true); } } @@ -182,10 +185,8 @@ public static void onUseHoe(UseHoeEvent event) event.setResult(Event.Result.ALLOW); } } - } - @SubscribeEvent public static void onLivingHurt(LivingHurtEvent event) { @@ -203,7 +204,6 @@ public static void onLivingHurt(LivingHurtEvent event) } } - @SubscribeEvent public static void attachItemCapabilities(AttachCapabilitiesEvent e) { diff --git a/src/main/java/net/dries007/tfc/objects/blocks/BlockTorchTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/BlockTorchTFC.java index d1e4ad52f2..dce1f639ef 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/BlockTorchTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/BlockTorchTFC.java @@ -11,6 +11,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import net.minecraft.block.BlockTorch; +import net.minecraft.block.SoundType; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -48,6 +49,7 @@ public BlockTorchTFC() setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.UP).withProperty(LIT, true)); setLightLevel(0.9375F); setTickRandomly(true); + setSoundType(SoundType.WOOD); Blocks.FIRE.setFireInfo(this, 5, 20); diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCactusTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCactusTFC.java index 1f8d334e4f..1d529fbaab 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCactusTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCactusTFC.java @@ -75,7 +75,7 @@ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockSt public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { worldIn.setBlockState(pos.up(), this.getDefaultState()); - IBlockState iblockstate = state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); + IBlockState iblockstate = state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, pos.up(), this, pos); } @@ -200,7 +200,7 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, AGE, GROWTHSTAGE, PART, DAYPERIOD); + return new BlockStateContainer(this, AGE, growthStageProperty, PART, DAYPERIOD); } @Override diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCreepingPlantTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCreepingPlantTFC.java index 2bf9e9a1d4..2c0b16a057 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCreepingPlantTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockCreepingPlantTFC.java @@ -158,13 +158,6 @@ public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAcces return NULL_AABB; } - @Override - @Nonnull - protected BlockStateContainer createPlantBlockState() - { - return new BlockStateContainer(this, DOWN, UP, NORTH, EAST, WEST, SOUTH, GROWTHSTAGE, DAYPERIOD, AGE); - } - @SuppressWarnings("deprecation") @Override @Nonnull @@ -173,13 +166,13 @@ public IBlockState withRotation(IBlockState state, Rotation rot) switch (rot) { case CLOCKWISE_180: - return state.withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST)); + return state.withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST)); case COUNTERCLOCKWISE_90: - return state.withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH)); + return state.withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH)); case CLOCKWISE_90: - return state.withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH)); + return state.withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH)); default: - return state.withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); + return state.withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); } } @@ -191,14 +184,21 @@ public IBlockState withMirror(IBlockState state, Mirror mirrorIn) switch (mirrorIn) { case LEFT_RIGHT: - return state.withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH)); + return state.withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH)); case FRONT_BACK: - return state.withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST)); + return state.withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST)); default: return super.withMirror(state, mirrorIn); } } + @Override + @Nonnull + protected BlockStateContainer createPlantBlockState() + { + return new BlockStateContainer(this, DOWN, UP, NORTH, EAST, WEST, SOUTH, growthStageProperty, DAYPERIOD, AGE); + } + @Override public boolean isPassable(IBlockAccess worldIn, BlockPos pos) { diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockEpiphyteTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockEpiphyteTFC.java index 89f88f318a..834d5c546f 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockEpiphyteTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockEpiphyteTFC.java @@ -76,7 +76,7 @@ public int getMetaFromState(IBlockState state) @Override public void onBlockAdded(World world, BlockPos pos, IBlockState state) { - world.setBlockState(pos, state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()])); + world.setBlockState(pos, state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()])); checkAndDropBlock(world, pos, state); } @@ -145,7 +145,7 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, FACING, GROWTHSTAGE, DAYPERIOD, AGE); + return new BlockStateContainer(this, FACING, growthStageProperty, DAYPERIOD, AGE); } @SuppressWarnings("deprecation") diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockFloatingWaterTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockFloatingWaterTFC.java index e8310c5491..eae7da52c2 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockFloatingWaterTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockFloatingWaterTFC.java @@ -46,7 +46,7 @@ public BlockFloatingWaterTFC(Plant plant) @Override public void onBlockAdded(World world, BlockPos pos, IBlockState state) { - world.setBlockState(pos, state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()])); + world.setBlockState(pos, state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()])); this.checkAndDropBlock(world, pos, state); } @@ -100,6 +100,6 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, GROWTHSTAGE, DAYPERIOD, AGE); + return new BlockStateContainer(this, growthStageProperty, DAYPERIOD, AGE); } } diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockHangingPlantTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockHangingPlantTFC.java index c590cccbdd..71de5a3a4f 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockHangingPlantTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockHangingPlantTFC.java @@ -66,7 +66,7 @@ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockSt public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { worldIn.setBlockState(pos.down(), this.getDefaultState()); - IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(BOTTOM, false); + IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(BOTTOM, false); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, pos.down(), this, pos); } @@ -120,7 +120,7 @@ public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, DOWN, UP, NORTH, EAST, WEST, SOUTH, GROWTHSTAGE, DAYPERIOD, AGE, BOTTOM); + return new BlockStateContainer(this, DOWN, UP, NORTH, EAST, WEST, SOUTH, growthStageProperty, DAYPERIOD, AGE, BOTTOM); } @Override @@ -220,7 +220,7 @@ private void growDiagonally(World worldIn, Random rand, BlockPos pos, IBlockStat if (rand.nextDouble() < 0.5D && worldIn.isAirBlock(sidePos) && worldIn.isAirBlock(sidePos.down())) { worldIn.setBlockState(sidePos.down(), this.getDefaultState()); - IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); + IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, sidePos.down(), this, pos); break; @@ -255,7 +255,7 @@ private void growHorizontally(World worldIn, Random rand, BlockPos pos, IBlockSt if (rand.nextDouble() < 0.01D && worldIn.isAirBlock(sidePos)) { worldIn.setBlockState(sidePos, this.getDefaultState()); - IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); + IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, sidePos, this, pos); break; diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockPlantTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockPlantTFC.java index 4c8cdf4341..3a5c4ac38a 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockPlantTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockPlantTFC.java @@ -65,7 +65,7 @@ public static BlockPlantTFC get(Plant plant) } /* Growth Stage of the plant, tied to the month of year */ - public final PropertyInteger GROWTHSTAGE; + public final PropertyInteger growthStageProperty; protected final Plant plant; protected final BlockStateContainer blockState; @@ -77,7 +77,7 @@ public BlockPlantTFC(Plant plant) plant.getOreDictName().ifPresent(name -> OreDictionaryHelper.register(this, name)); this.plant = plant; - GROWTHSTAGE = PropertyInteger.create("stage", 0, plant.getNumStages()); + this.growthStageProperty = PropertyInteger.create("stage", 0, plant.getNumStages()); this.setTickRandomly(true); setSoundType(SoundType.PLANT); setHardness(0.0F); @@ -105,7 +105,7 @@ public int getMetaFromState(IBlockState state) @Nonnull public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { - return state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); + return state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]); } @Override @@ -119,18 +119,18 @@ public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random ra { if (!worldIn.isAreaLoaded(pos, 1)) return; CalendarTFC.Month currentMonth = CalendarTFC.getMonthOfYear(); - int currentStage = state.getValue(GROWTHSTAGE); + int currentStage = state.getValue(growthStageProperty); int expectedStage = plant.getStages()[currentMonth.id()]; int currentTime = state.getValue(DAYPERIOD); int expectedTime = getDayPeriod(); if (currentTime != expectedTime) { - worldIn.setBlockState(pos, state.withProperty(DAYPERIOD, expectedTime).withProperty(GROWTHSTAGE, currentStage)); + worldIn.setBlockState(pos, state.withProperty(DAYPERIOD, expectedTime).withProperty(growthStageProperty, currentStage)); } if (currentStage != expectedStage && random.nextDouble() < 0.5) { - worldIn.setBlockState(pos, state.withProperty(DAYPERIOD, expectedTime).withProperty(GROWTHSTAGE, expectedStage)); + worldIn.setBlockState(pos, state.withProperty(DAYPERIOD, expectedTime).withProperty(growthStageProperty, expectedStage)); } this.updateTick(worldIn, pos, state, random); @@ -145,7 +145,7 @@ public int tickRate(World worldIn) @Override public void onBlockAdded(World world, BlockPos pos, IBlockState state) { - world.setBlockState(pos, state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()])); + world.setBlockState(pos, state.withProperty(DAYPERIOD, getDayPeriod()).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()])); checkAndDropBlock(world, pos, state); } @@ -162,6 +162,7 @@ public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, En { double movementMod = plant.getMovementMod(); //Entity X/Z motion is reduced by plants. + // todo: make this specific to the plant type (i.e. smaller grasses affect you less than larger ones) entityIn.motionX *= movementMod; entityIn.motionZ *= movementMod; } @@ -339,7 +340,7 @@ public Plant.EnumPlantTypeTFC getPlantTypeTFC() @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, GROWTHSTAGE, DAYPERIOD, AGE); + return new BlockStateContainer(this, growthStageProperty, DAYPERIOD, AGE); } int getDayPeriod() diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockShortGrassTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockShortGrassTFC.java index 5221c80b25..00cfbc035f 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockShortGrassTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockShortGrassTFC.java @@ -133,7 +133,7 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, AGE, GROWTHSTAGE, DAYPERIOD); + return new BlockStateContainer(this, AGE, growthStageProperty, DAYPERIOD); } @Override diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallGrassTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallGrassTFC.java index aed5b157eb..24902362f7 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallGrassTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallGrassTFC.java @@ -123,7 +123,7 @@ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockSt public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { worldIn.setBlockState(pos.up(), this.getDefaultState()); - IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); + IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, pos.up(), this, pos); } @@ -230,7 +230,7 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, AGE, GROWTHSTAGE, DAYPERIOD, PART); + return new BlockStateContainer(this, AGE, growthStageProperty, DAYPERIOD, PART); } @Override diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallPlantTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallPlantTFC.java index 19a76b88f9..ecaaa2966c 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallPlantTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallPlantTFC.java @@ -66,7 +66,7 @@ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockSt public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { worldIn.setBlockState(pos.up(), this.getDefaultState()); - IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); + IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, pos.up(), this, pos); } @@ -182,7 +182,7 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, AGE, GROWTHSTAGE, PART, DAYPERIOD); + return new BlockStateContainer(this, AGE, growthStageProperty, PART, DAYPERIOD); } private boolean canShrink(World worldIn, BlockPos pos) diff --git a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallWaterPlantTFC.java b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallWaterPlantTFC.java index b9e4b554dd..9d3d758493 100644 --- a/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallWaterPlantTFC.java +++ b/src/main/java/net/dries007/tfc/objects/blocks/plants/BlockTallWaterPlantTFC.java @@ -73,7 +73,7 @@ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockSt public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { worldIn.setBlockState(pos.up(), this.getDefaultState()); - IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(GROWTHSTAGE, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); + IBlockState iblockstate = state.withProperty(AGE, 0).withProperty(growthStageProperty, plant.getStages()[CalendarTFC.getMonthOfYear().id()]).withProperty(PART, getPlantPart(worldIn, pos)); worldIn.setBlockState(pos, iblockstate); iblockstate.neighborChanged(worldIn, pos.up(), this, pos); } @@ -183,7 +183,7 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc @Nonnull protected BlockStateContainer createPlantBlockState() { - return new BlockStateContainer(this, AGE, GROWTHSTAGE, PART, DAYPERIOD); + return new BlockStateContainer(this, AGE, growthStageProperty, PART, DAYPERIOD); } @Override diff --git a/src/main/java/net/dries007/tfc/objects/container/ContainerKnapping.java b/src/main/java/net/dries007/tfc/objects/container/ContainerKnapping.java index 551be9ad0a..7df44454e7 100644 --- a/src/main/java/net/dries007/tfc/objects/container/ContainerKnapping.java +++ b/src/main/java/net/dries007/tfc/objects/container/ContainerKnapping.java @@ -49,11 +49,15 @@ public void onButtonPress(int buttonID, @Nullable NBTTagCompound extraNBT) if (!hasBeenModified) { - ItemStack stack = Helpers.consumeItem(this.stack, type.getAmountToConsume()); + ItemStack stack = player.isCreative() ? this.stack : Helpers.consumeItem(this.stack, type.getAmountToConsume()); if (isOffhand) + { player.setHeldItem(EnumHand.OFF_HAND, stack); + } else + { player.setHeldItem(EnumHand.MAIN_HAND, stack); + } hasBeenModified = true; } diff --git a/src/main/java/net/dries007/tfc/objects/container/ContainerLogPile.java b/src/main/java/net/dries007/tfc/objects/container/ContainerLogPile.java index e443bbbbce..03e1023b6a 100644 --- a/src/main/java/net/dries007/tfc/objects/container/ContainerLogPile.java +++ b/src/main/java/net/dries007/tfc/objects/container/ContainerLogPile.java @@ -26,16 +26,13 @@ public class ContainerLogPile extends ContainerTE public ContainerLogPile(InventoryPlayer playerInv, TELogPile te) { super(playerInv, te); + te.setContainerOpen(true); } @Override public boolean canInteractWith(@Nonnull EntityPlayer player) { - if (this.tile.isBurning()) - { - return false; - } - return this.tile.countLogs() > 0; + return tile.canInteractWith(player); } @Override @@ -56,4 +53,12 @@ protected int[] getSlotShiftOrder(int containerSlots) { return SLOT_SHIFT_ORDER; } + + @Override + public void onContainerClosed(EntityPlayer playerIn) + { + // Marks the log pile as closed, allows it to delete itself if there aren't any logs in it + tile.setContainerOpen(false); + super.onContainerClosed(playerIn); + } } diff --git a/src/main/java/net/dries007/tfc/objects/container/ContainerTE.java b/src/main/java/net/dries007/tfc/objects/container/ContainerTE.java index 1d160c25fa..3ce2122f9b 100644 --- a/src/main/java/net/dries007/tfc/objects/container/ContainerTE.java +++ b/src/main/java/net/dries007/tfc/objects/container/ContainerTE.java @@ -59,6 +59,12 @@ public abstract class ContainerTE extends ContainerSimple addPlayerInventorySlots(playerInv); } + @Override + public boolean canInteractWith(EntityPlayer playerIn) + { + return tile.canInteractWith(player); + } + @Override public void detectAndSendChanges() { diff --git a/src/main/java/net/dries007/tfc/objects/te/TEInventory.java b/src/main/java/net/dries007/tfc/objects/te/TEInventory.java index c823aa3750..496c202716 100644 --- a/src/main/java/net/dries007/tfc/objects/te/TEInventory.java +++ b/src/main/java/net/dries007/tfc/objects/te/TEInventory.java @@ -9,6 +9,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryHelper; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; @@ -81,4 +82,12 @@ public void onBreakBlock(World world, BlockPos pos) InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inventory.getStackInSlot(i)); } } + + /** + * Delegated from {@link net.minecraft.inventory.Container#canInteractWith(EntityPlayer)} + */ + public boolean canInteractWith(EntityPlayer player) + { + return true; + } } diff --git a/src/main/java/net/dries007/tfc/objects/te/TELogPile.java b/src/main/java/net/dries007/tfc/objects/te/TELogPile.java index 4f5c147ac1..5bc5bca5b0 100644 --- a/src/main/java/net/dries007/tfc/objects/te/TELogPile.java +++ b/src/main/java/net/dries007/tfc/objects/te/TELogPile.java @@ -9,6 +9,7 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -35,6 +36,7 @@ public class TELogPile extends TEInventory implements ITickable private boolean burning; private int burnTicks; + private boolean isContainerOpen; public TELogPile() { @@ -44,6 +46,33 @@ public TELogPile() burning = false; } + public void setContainerOpen(boolean containerOpen) + { + isContainerOpen = containerOpen; + setAndUpdateSlots(-1); + } + + @Override + public void setAndUpdateSlots(int slot) + { + if (!world.isRemote) + { + for (int i = 0; i < 4; i++) + { + if (!inventory.getStackInSlot(i).isEmpty()) + { + super.setAndUpdateSlots(slot); + return; + } + } + if (!isContainerOpen) + { + world.setBlockToAir(pos); + } + } + super.setAndUpdateSlots(slot); + } + @Override public void update() { @@ -72,21 +101,9 @@ public void update() } @Override - public void setAndUpdateSlots(int slot) + public boolean canInteractWith(EntityPlayer player) { - if (!world.isRemote) - { - for (int i = 0; i < 4; i++) - { - if (!inventory.getStackInSlot(i).isEmpty()) - { - super.setAndUpdateSlots(slot); - return; - } - } - world.setBlockToAir(pos); - } - super.setAndUpdateSlots(slot); + return !burning && world.getTileEntity(pos) == this; } @Override diff --git a/src/main/java/net/dries007/tfc/objects/te/TEPitKiln.java b/src/main/java/net/dries007/tfc/objects/te/TEPitKiln.java index 64329d9a0b..3534ea59c7 100644 --- a/src/main/java/net/dries007/tfc/objects/te/TEPitKiln.java +++ b/src/main/java/net/dries007/tfc/objects/te/TEPitKiln.java @@ -189,8 +189,7 @@ public boolean onRightClick(EntityPlayer player, ItemStack stack, boolean x, boo if (stack.isEmpty() || player.isSneaking()) { // This will search through the logItems, then the strawItems - ItemStack dropStack = logItems.stream().filter(i -> !i.isEmpty()).findFirst().orElseGet(() -> - strawItems.stream().filter(i -> !i.isEmpty()).findFirst().orElse(ItemStack.EMPTY)); + ItemStack dropStack = logItems.stream().filter(i -> !i.isEmpty()).findFirst().orElseGet(() -> strawItems.stream().filter(i -> !i.isEmpty()).findFirst().orElse(ItemStack.EMPTY)); if (!dropStack.isEmpty()) { player.addItemStackToInventory(dropStack.splitStack(1)); diff --git a/src/main/java/net/dries007/tfc/types/DefaultRecipes.java b/src/main/java/net/dries007/tfc/types/DefaultRecipes.java index 281b8343a0..4a73643f9c 100644 --- a/src/main/java/net/dries007/tfc/types/DefaultRecipes.java +++ b/src/main/java/net/dries007/tfc/types/DefaultRecipes.java @@ -102,7 +102,8 @@ public static void onRegisterKnappingRecipeEvent(RegistryEvent.Register