Search in sources :

Example 1 with BlockWithEntity

use of net.minecraft.block.BlockWithEntity 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 2 with BlockWithEntity

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

the class IsoRenderCommand method executeBlockState.

private static int executeBlockState(FabricClientCommandSource source, BlockState state, CompoundTag tag) {
    IsometricRenderScreen screen = new IsometricRenderScreen();
    BlockEntity be = null;
    if (state.getBlock() instanceof BlockWithEntity) {
        be = ((BlockWithEntity) state.getBlock()).createBlockEntity(MinecraftClient.getInstance().world);
        ((BlockEntityAccessor) be).setCachedState(state);
        be.setLocation(MinecraftClient.getInstance().world, MinecraftClient.getInstance().player.getBlockPos());
        if (tag != null) {
            CompoundTag copyTag = tag.copy();
            copyTag.putInt("x", 0);
            copyTag.putInt("y", 0);
            copyTag.putInt("z", 0);
            be.fromTag(be.getCachedState(), copyTag);
        }
    }
    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) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity) BlockEntityAccessor(com.glisco.isometricrenders.mixin.BlockEntityAccessor)

Aggregations

AreaIsometricRenderScreen (com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen)2 IsometricRenderScreen (com.glisco.isometricrenders.client.gui.IsometricRenderScreen)2 BlockEntityAccessor (com.glisco.isometricrenders.mixin.BlockEntityAccessor)2 BlockWithEntity (net.minecraft.block.BlockWithEntity)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 BlockState (net.minecraft.block.BlockState)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1