use of com.glisco.isometricrenders.mixin.BlockEntityAccessor 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;
}
use of com.glisco.isometricrenders.mixin.BlockEntityAccessor 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;
}
Aggregations