blockentity trials
This commit is contained in:
parent
2a2ae5ec56
commit
bf0a718d24
@ -4,7 +4,6 @@ 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.util.Tickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -13,13 +12,13 @@ import net.minecraft.world.World;
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class DrillBlockDownEntity extends BlockEntity implements Tickable {
|
||||
public class DrillBlockDownEntity extends BlockEntity {
|
||||
|
||||
private static final Integer MAXDRILLSTEP = 20;
|
||||
private Integer drillstep;
|
||||
|
||||
public DrillBlockDownEntity() {
|
||||
super(QuickieFabricBlockEntity.DRILL_DOWN);
|
||||
public DrillBlockDownEntity(BlockPos pos, BlockState state) {
|
||||
super(QuickieFabricBlockEntity.DRILL_DOWN, pos, state);
|
||||
}
|
||||
|
||||
protected static final void moveBlockWithEntity(BlockPos from, BlockPos to, World world) {
|
||||
@ -29,7 +28,7 @@ public class DrillBlockDownEntity extends BlockEntity implements Tickable {
|
||||
world.setBlockState(from, Blocks.AIR.getDefaultState());
|
||||
world.setBlockState(to, bs);
|
||||
world.removeBlockEntity(from);
|
||||
world.setBlockEntity(to, be);
|
||||
world.addBlockEntity(be);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,13 +41,24 @@ public class DrillBlockDownEntity extends BlockEntity implements Tickable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
drillstep = drillstep == null ? MAXDRILLSTEP : drillstep - 1;
|
||||
if (drillstep < 1) {
|
||||
drillstep = MAXDRILLSTEP;
|
||||
drill(getPos(), getPos().down(), getWorld());
|
||||
public static void tick(World world, BlockPos pos, BlockState state, DrillBlockDownEntity be) {
|
||||
if (be.getDrillstep() < 1) {
|
||||
be.setDrillstep(MAXDRILLSTEP);
|
||||
drill(pos, pos.down(), 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;
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,18 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.blockentity.DrillBlockDownEntity;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FallingBlock;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext.Builder;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -26,7 +30,7 @@ public class BlockDrillDown extends FallingBlock implements BlockEntityProvider
|
||||
}
|
||||
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
|
||||
return new DrillBlockDownEntity();
|
||||
return new DrillBlockDownEntity(pos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,4 +39,10 @@ public class BlockDrillDown extends FallingBlock implements BlockEntityProvider
|
||||
list.add(new ItemStack(QuickieBlocks.DRILL_DOWN));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
|
||||
BlockEntityType<T> type) {
|
||||
return DrillBlockDownEntity::tick;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user