Resin Basin updated. Thanks to Spearkiller and Ayutac. (#2777)
* Resin Basin updated. Thanks to Spearkiller and Ayutac. Hitbox has been updated to half a block, better matching the model. Item model has been updated by Spearkiller to look nice. There was a weird inconsistency about the amount of sap given to player depending on either putting it into an inventory or breaking the block. Right click to harvest basin didn't work as intended, so removed for now. Also it seems the block states (full/pouring/pouringTime) are not saved via nbt? Also also wow the warnings. * Added removal of sap from basin when right -clicking. The error was me not understanding that "setFullState" had nothing to do with the variable "isFull". My bad, my bad. For some reason one right click triggers the onUse twice, and previously I didn't correctly update the sap after the first one, but now it should work. Testing went off without a hitch.
This commit is contained in:
parent
612657ecf4
commit
08ed4abcd4
3 changed files with 154 additions and 4 deletions
|
@ -95,7 +95,7 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
|
|||
Storage<ItemVariant> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<BlockPos, BlockState, BlockEntity> blockEntityClass;
|
||||
|
||||
public ResinBasinBlock(BiFunction<BlockPos, BlockState, BlockEntity> 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);
|
||||
|
|
|
@ -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
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue