Search in sources :

Example 36 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project carpet-extra by gnembon.

the class HopperMinecartEntity_transferItemsOutFeatureMixin method getOutputInventory.

private Inventory getOutputInventory() {
    Vec3d offsetToInventory = getBlockBelowCartOffset();
    // The visual rotation point of the minecart is roughly 0.5 above its feet (determined visually ingame)
    // Search 0.5 Blocks below the feet for an inventory
    Inventory inv = HopperBlockEntity.getInventoryAt(this.world, new BlockPos(this.getX() + offsetToInventory.x, this.getY() + 0.5 + offsetToInventory.y, this.getZ() + offsetToInventory.z));
    // There is probably a way nicer way to determine the access side of the target inventory
    if (inv instanceof BlockEntity) {
        BlockPos pos = ((BlockEntity) inv).getPos();
        if (pos.getY() < MathHelper.floor(this.getY()))
            outputDirection = Direction.DOWN;
        else if (pos.getX() > MathHelper.floor(this.getX()))
            outputDirection = Direction.EAST;
        else if (pos.getX() < MathHelper.floor(this.getX()))
            outputDirection = Direction.WEST;
        else if (pos.getZ() > MathHelper.floor(this.getZ()))
            outputDirection = Direction.SOUTH;
        else if (pos.getZ() < MathHelper.floor(this.getZ()))
            outputDirection = Direction.NORTH;
        else
            outputDirection = Direction.DOWN;
    } else
        outputDirection = Direction.DOWN;
    return inv;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) Inventory(net.minecraft.inventory.Inventory) SidedInventory(net.minecraft.inventory.SidedInventory) BlockEntity(net.minecraft.block.entity.BlockEntity) HopperBlockEntity(net.minecraft.block.entity.HopperBlockEntity)

Example 37 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project malum-fabric by RealRTTV.

the class BlockHelper method getBlockEntities.

public static <T> ArrayList<T> getBlockEntities(Class<T> type, World world, Box box) {
    ArrayList<T> tileList = new ArrayList<>();
    for (int i = (int) Math.floor(box.minX); i < (int) Math.ceil(box.maxX) + 16; i += 16) {
        for (int j = (int) Math.floor(box.minZ); j < (int) Math.ceil(box.maxZ) + 16; j += 16) {
            Chunk chunk = world.getChunk(new BlockPos(i, 0, j));
            Set<BlockPos> tiles = chunk.getBlockEntityPositions();
            for (BlockPos p : tiles) if (box.contains(p.getX() + 0.5, p.getY() + 0.5, p.getZ() + 0.5)) {
                BlockEntity t = world.getBlockEntity(p);
                if (type.isInstance(t)) {
                    // noinspection unchecked
                    tileList.add((T) t);
                }
            }
        }
    }
    return tileList;
}
Also used : ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 38 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project malum-fabric by RealRTTV.

the class AbstractItemPedestalBlock method onStateReplaced.

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
    if (!state.isOf(newState.getBlock())) {
        BlockEntity blockEntity = world.getBlockEntity(pos);
        if (blockEntity instanceof AbstractItemDisplayBlockEntity) {
            ItemScatterer.spawn(world, pos, (Inventory) blockEntity);
            world.updateComparators(pos, this);
        }
        super.onStateReplaced(state, world, pos, newState, moved);
    }
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) ItemPedestalBlockEntity(ca.rttv.malum.block.entity.ItemPedestalBlockEntity) AbstractItemDisplayBlockEntity(ca.rttv.malum.block.entity.AbstractItemDisplayBlockEntity) AbstractItemDisplayBlockEntity(ca.rttv.malum.block.entity.AbstractItemDisplayBlockEntity)

Example 39 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project malum-fabric by RealRTTV.

the class SpiritJarBlock method onStateReplaced.

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
    if (!state.isOf(newState.getBlock())) {
        BlockEntity blockEntity = world.getBlockEntity(pos);
        if (blockEntity instanceof SpiritJarBlockEntity) {
            ItemScatterer.spawn(world, pos, (Inventory) blockEntity);
            world.updateComparators(pos, this);
        }
        super.onStateReplaced(state, world, pos, newState, moved);
    }
}
Also used : SpiritJarBlockEntity(ca.rttv.malum.block.entity.SpiritJarBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) SpiritJarBlockEntity(ca.rttv.malum.block.entity.SpiritJarBlockEntity)

Example 40 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)

Aggregations

BlockEntity (net.minecraft.block.entity.BlockEntity)93 BlockPos (net.minecraft.util.math.BlockPos)34 BlockState (net.minecraft.block.BlockState)24 BlockHitResult (net.minecraft.util.hit.BlockHitResult)16 ItemStack (net.minecraft.item.ItemStack)14 Block (net.minecraft.block.Block)11 Vec3d (net.minecraft.util.math.Vec3d)11 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)10 NbtCompound (net.minecraft.nbt.NbtCompound)8 World (net.minecraft.world.World)8 FluidState (net.minecraft.fluid.FluidState)6 Inject (org.spongepowered.asm.mixin.injection.Inject)6 AbstractFurnaceBlockEntity (net.minecraft.block.entity.AbstractFurnaceBlockEntity)5 MatrixStack (net.minecraft.client.util.math.MatrixStack)5 ServerWorld (net.minecraft.server.world.ServerWorld)5 Random (java.util.Random)4 CommandBlockBlockEntity (net.minecraft.block.entity.CommandBlockBlockEntity)4 Inventory (net.minecraft.inventory.Inventory)4 ArrayList (java.util.ArrayList)3 JinericCampfireBlockEntity (jingy.jineric.block.entity.custom.JinericCampfireBlockEntity)3