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;
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations