Search in sources :

Example 21 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project beyond-earth-fabricated by SomeoneIs404.

the class Fluid method beforeBreakingBlock.

@Override
protected void beforeBreakingBlock(WorldAccess world, BlockPos pos, BlockState state) {
    final BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
    Block.dropStacks(state, world, pos, blockEntity);
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 22 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project Carrier by GabrielOlvH.

the class CarriableGeneric method tryPlace.

@Override
@NotNull
public ActionResult tryPlace(@NotNull CarrierComponent carrier, @NotNull World world, @NotNull CarriablePlacementContext ctx) {
    if (world.isClient)
        return ActionResult.PASS;
    CarryingData carrying = carrier.getCarryingData();
    if (carrying == null)
        return ActionResult.PASS;
    BlockPos pos = ctx.getBlockPos();
    BlockState state = carrying.getBlockState() == null ? parent.getDefaultState() : carrying.getBlockState();
    world.setBlockState(pos, state);
    BlockEntity blockEntity = world.getBlockEntity(pos);
    if (blockEntity != null) {
        NbtCompound tag = carrying.getBlockEntityTag();
        ((AccessorBlockEntity) blockEntity).carrier_writeIdentifyingData(tag);
        blockEntity.readNbt(tag);
    }
    carrier.setCarryingData(null);
    world.updateNeighbors(pos, state.getBlock());
    return ActionResult.SUCCESS;
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) NbtCompound(net.minecraft.nbt.NbtCompound) BlockPos(net.minecraft.util.math.BlockPos) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project Carrier by GabrielOlvH.

the class CarriableChest method tryPlace.

@Override
@NotNull
public ActionResult tryPlace(@NotNull CarrierComponent carrier, @NotNull World world, @NotNull CarriablePlacementContext ctx) {
    if (world.isClient)
        return ActionResult.PASS;
    CarryingData carrying = carrier.getCarryingData();
    if (carrying == null)
        return ActionResult.PASS;
    BlockPos pos = ctx.getBlockPos();
    BlockState state = parent.getPlacementState(new ItemPlacementContext(carrier.getOwner(), Hand.MAIN_HAND, ItemStack.EMPTY, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), ctx.getSide(), ctx.getBlockPos(), false)));
    world.setBlockState(pos, state);
    BlockEntity blockEntity = world.getBlockEntity(pos);
    if (blockEntity != null) {
        NbtCompound tag = carrying.getBlockEntityTag();
        ((AccessorBlockEntity) blockEntity).carrier_writeIdentifyingData(tag);
        blockEntity.readNbt(tag);
    }
    carrier.setCarryingData(null);
    return ActionResult.SUCCESS;
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) NbtCompound(net.minecraft.nbt.NbtCompound) BlockPos(net.minecraft.util.math.BlockPos) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project Carrier by GabrielOlvH.

the class CarriableGeneric method tryPickup.

@Override
@NotNull
public ActionResult tryPickup(@NotNull CarrierComponent carrier, @NotNull World world, @NotNull BlockPos blockPos, @Nullable Entity entity) {
    if (world.isClient)
        return ActionResult.PASS;
    BlockEntity blockEntity = world.getBlockEntity(blockPos);
    BlockState blockState = world.getBlockState(blockPos);
    CarryingData carrying = new CarryingData(type, blockState, blockEntity);
    world.removeBlockEntity(blockPos);
    world.removeBlock(blockPos, false);
    carrier.setCarryingData(carrying);
    return ActionResult.SUCCESS;
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) BlockState(net.minecraft.block.BlockState) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorld method getFullBlock.

@Override
public BaseBlock getFullBlock(BlockVector3 position) {
    BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    // Avoid creation by using the CHECK mode -- if it's needed, it'll be re-created anyways
    BlockEntity tile = ((WorldChunk) getWorld().getChunk(pos)).getBlockEntity(pos, WorldChunk.CreationType.CHECK);
    if (tile != null) {
        net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
        tile.toTag(tag);
        return getBlock(position).toBaseBlock(NBTConverter.fromNative(tag));
    } else {
        return getBlock(position).toBaseBlock();
    }
}
Also used : WorldChunk(net.minecraft.world.chunk.WorldChunk) BlockPos(net.minecraft.util.math.BlockPos) CompoundTag(com.sk89q.jnbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

BlockEntity (net.minecraft.block.entity.BlockEntity)61 BlockPos (net.minecraft.util.math.BlockPos)26 BlockState (net.minecraft.block.BlockState)19 BlockHitResult (net.minecraft.util.hit.BlockHitResult)13 ItemStack (net.minecraft.item.ItemStack)10 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)8 Vec3d (net.minecraft.util.math.Vec3d)8 World (net.minecraft.world.World)7 Block (net.minecraft.block.Block)6 Inject (org.spongepowered.asm.mixin.injection.Inject)6 MatrixStack (net.minecraft.client.util.math.MatrixStack)5 FluidState (net.minecraft.fluid.FluidState)5 Random (java.util.Random)4 AbstractFurnaceBlockEntity (net.minecraft.block.entity.AbstractFurnaceBlockEntity)4 CommandBlockBlockEntity (net.minecraft.block.entity.CommandBlockBlockEntity)4 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)4 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)4 Inventory (net.minecraft.inventory.Inventory)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 ServerWorld (net.minecraft.server.world.ServerWorld)4