diff --git a/src/main/java/techreborn/blockentity/machine/tier1/ResinBasinBlockEntity.java b/src/main/java/techreborn/blockentity/machine/tier1/ResinBasinBlockEntity.java index 245823a50..f475e3df1 100644 --- a/src/main/java/techreborn/blockentity/machine/tier1/ResinBasinBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/tier1/ResinBasinBlockEntity.java @@ -95,7 +95,7 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity { Storage invBelow = getInventoryBelow(); if (invBelow != null) { try (Transaction tx = Transaction.openOuter()) { - int sentAmount = (Math.random() <= 0.5) ? 1 : 2; + int sentAmount = getSapAmount(); if (invBelow.insert(ItemVariant.of(TRContent.Parts.SAP), sentAmount, tx) > 0) { tx.commit(); isFull = false; @@ -136,13 +136,28 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity { } } + public int getSapAmount() { + if (!isFull) + return 0; + return (Math.random() <= 0.5) ? 1 : 2; + } + + public ItemStack empty() { + int sapAmount = getSapAmount(); + if (isFull) { + isFull = false; + setPouringState(false); + } + return new ItemStack(TRContent.Parts.SAP, sapAmount); + } + @Override public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) { super.onBreak(world, playerEntity, blockPos, blockState); // Drop a sap if full if (this.isFull) { - ItemStack out = new ItemStack(TRContent.Parts.SAP, (Math.random() <= 0.6) ? 1 : 2); + ItemStack out = new ItemStack(TRContent.Parts.SAP, getSapAmount()); WorldUtils.dropItem(out, world, pos); } } diff --git a/src/main/java/techreborn/blocks/machine/tier1/ResinBasinBlock.java b/src/main/java/techreborn/blocks/machine/tier1/ResinBasinBlock.java index 0144e4f65..ca056e34a 100644 --- a/src/main/java/techreborn/blocks/machine/tier1/ResinBasinBlock.java +++ b/src/main/java/techreborn/blocks/machine/tier1/ResinBasinBlock.java @@ -34,6 +34,9 @@ import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.DirectionProperty; import net.minecraft.state.property.Properties; import net.minecraft.text.TranslatableText; +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.Direction; import net.minecraft.util.shape.VoxelShape; @@ -43,6 +46,7 @@ import net.minecraft.world.World; import reborncore.common.BaseBlockEntityProvider; import reborncore.common.blockentity.MachineBaseBlockEntity; import reborncore.common.util.WorldUtils; +import techreborn.blockentity.machine.tier1.ResinBasinBlockEntity; import techreborn.init.TRContent; import java.util.UUID; @@ -53,6 +57,7 @@ public class ResinBasinBlock extends BaseBlockEntityProvider { public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; public static final BooleanProperty POURING = BooleanProperty.of("pouring"); public static final BooleanProperty FULL = BooleanProperty.of("full"); + protected static final VoxelShape SHAPE = Block.createCuboidShape(0d,0d, 0d, 16d, 8d, 16d); BiFunction blockEntityClass; public ResinBasinBlock(BiFunction blockEntityClass) { @@ -63,9 +68,10 @@ public class ResinBasinBlock extends BaseBlockEntityProvider { this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(POURING, false).with(FULL, false)); } + @SuppressWarnings("deprecation") @Override public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return VoxelShapes.cuboid(0, 0, 0, 1, 15 / 16f, 1); + return SHAPE; } public void setFacing(Direction facing, World world, BlockPos pos) { @@ -82,6 +88,19 @@ public class ResinBasinBlock extends BaseBlockEntityProvider { return state.get(FACING); } + @SuppressWarnings("deprecation") + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + if (world == null || world.isClient() || player == null || pos == null || !(world.getBlockEntity(pos) instanceof ResinBasinBlockEntity)) + return ActionResult.PASS; + ResinBasinBlockEntity basin = (ResinBasinBlockEntity)world.getBlockEntity(pos); + ItemStack sap = basin.empty(); + if (sap.isEmpty()) + return ActionResult.PASS; + player.getInventory().offerOrDrop(sap); + return ActionResult.SUCCESS; + } + @Override public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { super.onPlaced(worldIn, pos, state, placer, stack); diff --git a/src/main/resources/assets/techreborn/models/item/resin_basin.json b/src/main/resources/assets/techreborn/models/item/resin_basin.json index 7c08628bb..9616d9be2 100644 --- a/src/main/resources/assets/techreborn/models/item/resin_basin.json +++ b/src/main/resources/assets/techreborn/models/item/resin_basin.json @@ -1,3 +1,119 @@ { - "parent": "techreborn:block/machines/tier0_machines/resin_basin_empty" + "parent": "techreborn:block/machines/tier0_machines/resin_basin_empty", + "display": { + "thirdperson_righthand": { + "rotation": [ + 50, + 45, + 0 + ], + "translation": [ + 0, + 1.7, + 1.2 + ], + "scale": [ + 0.325, + 0.325, + 0.325 + ] + }, + "thirdperson_lefthand": { + "rotation": [ + 50, + -16, + 0 + ], + "translation": [ + 0, + 1.7, + 1.2 + ], + "scale": [ + 0.325, + 0.325, + 0.325 + ] + }, + "firstperson_righthand": { + "rotation": [ + 0, + -225, + 0 + ], + "translation": [ + 0, + 1.25, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ] + }, + "firstperson_lefthand": { + "rotation": [ + 0, + 135, + 0 + ], + "translation": [ + 0, + 1.25, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ] + }, + "gui": { + "rotation": [ + 30, + 225, + 0 + ], + "translation": [ + 0, + 0, + 0 + ], + "scale": [ + 0.625, + 0.625, + 0.625 + ] + }, + "ground": { + "translation": [ + 0, + 3, + 0 + ], + "scale": [ + 0.25, + 0.25, + 0.25 + ] + }, + "fixed": { + "rotation": [ + 0, + -90, + 0 + ], + "translation": [ + 0, + 0, + 0 + ], + "scale": [ + 0.5, + 0.5, + 0.5 + ] + } + } } \ No newline at end of file