repaired drills
This commit is contained in:
parent
51c4c6a00d
commit
507fdc1ba5
@ -0,0 +1,61 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public abstract class DrillBlockEntity extends BlockEntity {
|
||||||
|
|
||||||
|
private Integer drillstep;
|
||||||
|
private final Integer maxDrillStep;
|
||||||
|
|
||||||
|
public DrillBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, Integer maxDrillStep) {
|
||||||
|
super(type, pos, state);
|
||||||
|
this.maxDrillStep = maxDrillStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final void moveBlockWithEntity(BlockPos from, BlockPos to, World world) {
|
||||||
|
BlockEntity be = world.getBlockEntity(from);
|
||||||
|
BlockState bs = world.getBlockState(from);
|
||||||
|
if (be != null) {
|
||||||
|
world.setBlockState(from, Blocks.AIR.getDefaultState());
|
||||||
|
world.setBlockState(to, bs);
|
||||||
|
world.removeBlockEntity(from);
|
||||||
|
world.addBlockEntity(be);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final void drill(BlockPos pos, BlockPos to, World world) {
|
||||||
|
if (!world.getBlockState(to).isOf(Blocks.BEDROCK) && !world.getBlockState(to).isOf(QuickieBlocks.DRILLSTOP)) {
|
||||||
|
world.breakBlock(to, true);
|
||||||
|
if (pos.down() != to) { // no need for the falling one
|
||||||
|
moveBlockWithEntity(pos, to, world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tick(World world, BlockPos pos, BlockState state, DrillBlockEntity be, Integer maxDrillStep, BlockPos drillPosition) {
|
||||||
|
if (be.getDrillstep() < 1) {
|
||||||
|
be.setDrillstep(maxDrillStep);
|
||||||
|
drill(pos, drillPosition, world);
|
||||||
|
} else {
|
||||||
|
be.doDrillstep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doDrillstep() {
|
||||||
|
setDrillstep(getDrillstep() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDrillstep() {
|
||||||
|
return drillstep == null ? maxDrillStep : drillstep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDrillstep(Integer drillstep) {
|
||||||
|
this.drillstep = drillstep;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user