Cleanup and drop when no log connected

This commit is contained in:
Justin Vitale 2020-07-08 03:34:36 +10:00
parent 7d04348853
commit 80716876b2
2 changed files with 48 additions and 54 deletions

View file

@ -24,21 +24,17 @@
package techreborn.blockentity.machine.tier1; package techreborn.blockentity.machine.tier1;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.HopperBlockEntity; import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import reborncore.common.blockentity.MachineBaseBlockEntity; import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.RebornInventory;
import techreborn.blocks.machine.tier1.ResinBasinBlock; import techreborn.blocks.machine.tier1.ResinBasinBlock;
import techreborn.blocks.misc.BlockRubberLog; import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
@ -46,9 +42,6 @@ import techreborn.init.ModSounds;
import techreborn.init.TRBlockEntities; import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import java.util.HashMap;
import java.util.Map;
import static reborncore.api.items.InventoryUtils.getInventoryAt; import static reborncore.api.items.InventoryUtils.getInventoryAt;
public class ResinBasinBlockEntity extends MachineBaseBlockEntity { public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
@ -91,8 +84,10 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
// Find a rubber log // Find a rubber log
Inventory invBelow = getInventoryBelow(); Inventory invBelow = getInventoryBelow();
if (invBelow != null) { if (invBelow != null) {
ItemStack out = new ItemStack(TRContent.Parts.SAP, 1); ItemStack out = new ItemStack(TRContent.Parts.SAP, 1);
out = HopperBlockEntity.transfer(null, invBelow, out, Direction.UP); out = HopperBlockEntity.transfer(null, invBelow, out, Direction.UP);
if (out.isEmpty()) { if (out.isEmpty()) {
// Successfully deposited // Successfully deposited
isFull = false; isFull = false;
@ -101,7 +96,18 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
} }
} }
if(!isFull && !isPouring) { boolean readyToHarvest = !isFull && !isPouring;
// Ensuring it's placed on a log
if ((readyToHarvest || world.getTime() % 20 == 0) && !validPlacement()) {
// Not placed on log, drop on ground
world.setBlockState(pos, Blocks.AIR.getDefaultState());
ItemEntity itemEntity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(TRContent.Machine.RESIN_BASIN));
world.spawnEntity(itemEntity);
return;
}
if (readyToHarvest) {
// Check for rubber // Check for rubber
if (world.getTime() % TechRebornConfig.checkForSapTime == 0) { if (world.getTime() % TechRebornConfig.checkForSapTime == 0) {
BlockPos targetRubber = getLogWithSap(); BlockPos targetRubber = getLogWithSap();
@ -153,16 +159,16 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
return getInventoryAt(this.getWorld(), this.pos.offset(Direction.DOWN)); return getInventoryAt(this.getWorld(), this.pos.offset(Direction.DOWN));
} }
private boolean validPlacement() {
return world.getBlockState(this.pos.offset(direction)).getBlock() == TRContent.RUBBER_LOG;
}
private BlockPos getLogWithSap() { private BlockPos getLogWithSap() {
// Checking origin block // Checking origin block
BlockPos originPos = this.pos.offset(direction); BlockPos originPos = this.pos.offset(direction);
BlockState originState = world.getBlockState(originPos); BlockState originState = world.getBlockState(originPos);
if(originState.getBlock() != TRContent.RUBBER_LOG){
return null;
}
if (originState.get(BlockRubberLog.HAS_SAP)) { if (originState.get(BlockRubberLog.HAS_SAP)) {
return originPos; return originPos;
} }

View file

@ -4,7 +4,6 @@ import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
@ -12,22 +11,13 @@ import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes; import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.BaseBlockEntityProvider; import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import techreborn.blocks.GenericMachineBlock;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -72,7 +62,6 @@ public class ResinBasinBlock extends BaseBlockEntityProvider {
@Override @Override
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.onPlaced(worldIn, pos, state, placer, stack); super.onPlaced(worldIn, pos, state, placer, stack);
if (worldIn.isClient) return; if (worldIn.isClient) return;
Direction facing = placer.getHorizontalFacing().getOpposite(); Direction facing = placer.getHorizontalFacing().getOpposite();
@ -84,7 +73,6 @@ public class ResinBasinBlock extends BaseBlockEntityProvider {
ItemEntity itemEntity = new ItemEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(this.asBlock())); ItemEntity itemEntity = new ItemEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(this.asBlock()));
worldIn.spawnEntity(itemEntity); worldIn.spawnEntity(itemEntity);
placer.sendSystemMessage(new LiteralText(new TranslatableText(this.getTranslationKey()).getString() + new TranslatableText("techreborn.tooltip.invalid_basin_placement").getString()), null); placer.sendSystemMessage(new LiteralText(new TranslatableText(this.getTranslationKey()).getString() + new TranslatableText("techreborn.tooltip.invalid_basin_placement").getString()), null);
return;
} }
} }