Search in sources :

Example 16 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project friends-and-foes by Faboslav.

the class BeeEntityMixin method isHiveValid.

@Inject(method = "isHiveValid", at = @At(value = "RETURN", ordinal = 1), cancellable = true)
private void isHiveValid(CallbackInfoReturnable<Boolean> cir) {
    var isHiveValid = cir.getReturnValue();
    if (isHiveValid) {
        cir.setReturnValue(isHiveValid);
    }
    BlockEntity blockEntity = this.world.getBlockEntity(this.hivePos);
    isHiveValid = blockEntity != null && blockEntity.getType() == ModBlockEntityTypes.FRIENDS_AND_FOES_BEEHIVES;
    if (!info.getReturnValueZ() && be instanceof ApiaryBlockEntity)
        info.setReturnValue(true);
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 17 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project Fabric-Course-118 by Kaupenjoe.

the class HoneyFluid method beforeBreakingBlock.

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

Example 18 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project isometric-renders by gliscowo.

the class IsoRenderCommand method executeBlockTarget.

private static int executeBlockTarget(FabricClientCommandSource source) {
    final MinecraftClient client = MinecraftClient.getInstance();
    IsometricRenderScreen screen = new IsometricRenderScreen();
    if (client.crosshairTarget.getType() != HitResult.Type.BLOCK) {
        source.sendError(Text.of("You're not looking at a block"));
        return 0;
    }
    final BlockPos hitPos = ((BlockHitResult) client.crosshairTarget).getBlockPos();
    BlockState state = client.world.getBlockState(hitPos);
    BlockEntity be = null;
    if (state.getBlock() instanceof BlockWithEntity) {
        CompoundTag tag = client.world.getBlockEntity(hitPos).toTag(new CompoundTag());
        be = ((BlockWithEntity) state.getBlock()).createBlockEntity(client.world);
        ((BlockEntityAccessor) be).setCachedState(state);
        be.setLocation(client.world, MinecraftClient.getInstance().player.getBlockPos());
        CompoundTag copyTag = tag.copy();
        copyTag.putInt("x", 0);
        copyTag.putInt("y", 0);
        copyTag.putInt("z", 0);
        be.fromTag(be.getCachedState(), copyTag);
        be.setLocation(client.world, MinecraftClient.getInstance().player.getBlockPos());
    }
    if (be != null) {
        IsometricRenderPresets.setupBlockEntityRender(screen, be);
    } else {
        IsometricRenderPresets.setupBlockStateRender(screen, state);
    }
    IsometricRenderHelper.scheduleScreen(screen);
    return 0;
}
Also used : IsometricRenderScreen(com.glisco.isometricrenders.client.gui.IsometricRenderScreen) AreaIsometricRenderScreen(com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen) BlockWithEntity(net.minecraft.block.BlockWithEntity) BlockState(net.minecraft.block.BlockState) MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity) BlockEntityAccessor(com.glisco.isometricrenders.mixin.BlockEntityAccessor)

Example 19 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project Client by MatHax.

the class GhostHand method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (!mc.options.useKey.isPressed() || mc.player.isSneaking())
        return;
    for (BlockEntity blockEntity : Utils.blockEntities()) {
        if (new BlockPos(mc.player.raycast(mc.interactionManager.getReachDistance(), mc.getTickDelta(), false).getPos()).equals(blockEntity.getPos()))
            return;
    }
    Vec3d nextPos = new Vec3d(0, 0, 0.1).rotateX(-(float) Math.toRadians(mc.player.getPitch())).rotateY(-(float) Math.toRadians(mc.player.getYaw()));
    for (int i = 1; i < mc.interactionManager.getReachDistance() * 10; i++) {
        BlockPos curPos = new BlockPos(mc.player.getCameraPosVec(mc.getTickDelta()).add(nextPos.multiply(i)));
        if (posList.contains(curPos))
            continue;
        posList.add(curPos);
        for (BlockEntity blockEntity : Utils.blockEntities()) {
            if (blockEntity.getPos().equals(curPos)) {
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), Direction.UP, curPos, true));
                return;
            }
        }
    }
    posList.clear();
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) BlockEntity(net.minecraft.block.entity.BlockEntity) EventHandler(mathax.client.eventbus.EventHandler)

Example 20 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project AurorasDecorations by LambdAurora.

the class BlockEntityHelper method sync.

default void sync() {
    World world = ((BlockEntity) this).getWorld();
    // Maintain distinct failure case from below
    Preconditions.checkNotNull(world);
    if (!(world instanceof ServerWorld))
        throw new IllegalStateException("Cannot call sync() on the logical client! Did you check world.isClient first?");
    ((ServerWorld) world).getChunkManager().markForUpdate(((BlockEntity) this).getPos());
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) 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