use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class PitKilnBlock method breakBlockEntity.
private void breakBlockEntity(World world, BlockPos pos, BlockState state) {
dropStack(world, pos, new ItemStack(PrimevalItems.STRAW, 1 + Math.min(state.get(BUILD_STEP), 4)));
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
for (ItemStack stack : ((PitKilnBlockEntity) blockEntity).getItems()) {
dropStack(world, pos, stack);
}
for (ItemStack stack : ((PitKilnBlockEntity) blockEntity).getLogs()) {
if (stack != null)
dropStack(world, pos, stack);
}
}
}
use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class PitKilnBlock method onUse.
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!player.getAbilities().allowModifyWorld) {
return ActionResult.PASS;
} else if (player.isSneaking()) {
int stage = state.get(BUILD_STEP);
if (stage == 0) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
Vec3d clicked = hit.getPos().subtract(hit.getBlockPos().getX(), 0, hit.getBlockPos().getZ());
int index = 0;
if (clicked.x > 0.5) {
index += 1;
}
if (clicked.z > 0.5) {
index += 2;
}
player.giveItemStack(((PitKilnBlockEntity) blockEntity).removeItem(index));
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else if (stage > 4) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
world.setBlockState(pos, state.with(BUILD_STEP, stage - 1));
player.giveItemStack(new ItemStack(((PitKilnBlockEntity) blockEntity).removeLog().getItem(), 1));
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else {
world.setBlockState(pos, state.with(BUILD_STEP, stage - 1));
player.giveItemStack(new ItemStack(PrimevalItems.STRAW, 1));
return ActionResult.SUCCESS;
}
} else {
ItemStack itemStack = player.getStackInHand(hand);
int stage = state.get(BUILD_STEP);
if (itemStack.isOf(PrimevalItems.STRAW) && stage < 4) {
world.setBlockState(pos, state.with(BUILD_STEP, stage + 1));
if (!player.isCreative()) {
player.getStackInHand(hand).decrement(1);
}
return ActionResult.SUCCESS;
} else if (itemStack.isIn(PrimevalItemTags.LOGS) && stage > 3 && stage < 8) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
((PitKilnBlockEntity) blockEntity).addLog(new ItemStack(itemStack.getItem(), 1));
world.setBlockState(pos, state.with(BUILD_STEP, stage + 1));
if (!player.isCreative()) {
player.getStackInHand(hand).decrement(1);
}
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else if (!itemStack.isEmpty() && stage == 0) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
Vec3d clicked = hit.getPos().subtract(hit.getBlockPos().getX(), 0, hit.getBlockPos().getZ());
int index = 0;
if (clicked.x > 0.5) {
index += 1;
}
if (clicked.z > 0.5) {
index += 2;
}
ItemStack newStack = itemStack.copy();
newStack.setCount(1);
if (((PitKilnBlockEntity) blockEntity).addItem(newStack, index)) {
if (!player.isCreative()) {
player.getStackInHand(hand).decrement(1);
}
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else {
return ActionResult.FAIL;
}
} else {
return ActionResult.PASS;
}
}
}
use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class AshPileBlock method neighborUpdate.
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
super.neighborUpdate(state, world, pos, block, fromPos, notify);
if (!PitKilnBlock.isSoilSurrounded(world, pos)) {
// if not surrounded properly
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof AshPileBlockEntity) {
for (ItemStack stack : ((AshPileBlockEntity) blockEntity).getItems()) {
dropStack(world, pos, stack);
}
world.getBlockEntity(pos).markRemoved();
}
world.breakBlock(pos, true);
}
}
use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class AshPileBlock method onBreak.
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
super.onBreak(world, pos, state, player);
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof AshPileBlockEntity) {
for (ItemStack stack : ((AshPileBlockEntity) blockEntity).getItems()) {
dropStack(world, pos, stack);
}
}
world.getBlockEntity(pos).markRemoved();
}
use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class CollapsingBlockEntity method tick.
@Override
public void tick() {
if (this.block.isAir()) {
this.discard();
} else {
Block block = this.block.getBlock();
Block source = this.sourceBlock.getBlock();
BlockPos blockPos2;
if (this.timeFalling++ == 0) {
blockPos2 = this.origin;
if (this.world.getBlockState(blockPos2).isOf(block) || this.world.getBlockState(blockPos2).isOf(source)) {
this.world.removeBlock(blockPos2, false);
} else if (!this.world.isClient) {
this.discard();
return;
}
}
if (!this.hasNoGravity()) {
this.setVelocity(this.getVelocity().add(0.0D, -0.04D, 0.0D));
}
this.move(MovementType.SELF, this.getVelocity());
if (!this.world.isClient) {
blockPos2 = this.getBlockPos();
boolean bl = this.block.getBlock() instanceof ConcretePowderBlock;
boolean bl2 = bl && this.world.getFluidState(blockPos2).isIn(FluidTags.WATER);
double d = this.getVelocity().lengthSquared();
if (bl && d > 1.0D) {
BlockHitResult blockHitResult = this.world.raycast(new RaycastContext(new Vec3d(this.prevX, this.prevY, this.prevZ), this.getPos(), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.SOURCE_ONLY, this));
if (blockHitResult.getType() != HitResult.Type.MISS && this.world.getFluidState(blockHitResult.getBlockPos()).isIn(FluidTags.WATER)) {
blockPos2 = blockHitResult.getBlockPos();
bl2 = true;
}
}
if (!this.onGround && !bl2) {
if (!this.world.isClient && (this.timeFalling > 100 && (blockPos2.getY() < 1 || blockPos2.getY() > 256) || this.timeFalling > 600)) {
if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
this.dropItem(block);
}
this.discard();
}
} else {
BlockState blockState = this.world.getBlockState(blockPos2);
this.setVelocity(this.getVelocity().multiply(0.7D, -0.5D, 0.7D));
if (!blockState.isOf(Blocks.MOVING_PISTON)) {
this.discard();
// !destroyedOnLanding
if (this.block.contains(Properties.WATERLOGGED) && this.world.getFluidState(blockPos2).getFluid() == Fluids.WATER) {
this.block = this.block.with(Properties.WATERLOGGED, true);
}
if (this.world.setBlockState(blockPos2, this.block, 3)) {
if (block instanceof FallingBlock) {
((FallingBlock) block).onLanding(this.world, blockPos2, this.block, blockState, this);
}
if (this.blockEntityData != null && this.block.hasBlockEntity()) {
BlockEntity $$11 = this.world.getBlockEntity(blockPos2);
if ($$11 != null) {
NbtCompound $$12 = $$11.createNbt();
Iterator var13 = this.blockEntityData.getKeys().iterator();
while (var13.hasNext()) {
String $$13 = (String) var13.next();
$$12.put($$13, this.blockEntityData.get($$13).copy());
}
try {
$$11.readNbt($$12);
} catch (Exception var15) {
}
$$11.markDirty();
}
}
} else if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
this.dropItem(block);
}
}
}
}
this.setVelocity(this.getVelocity().multiply(0.98D));
}
}
Aggregations