use of net.minecraft.block.entity.BlockEntity in project MasaGadget by plusls.
the class MixinWorldRenderer method postRender.
@Inject(method = "render", at = @At(value = "RETURN"))
private void postRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
MinecraftClient mc = MinecraftClient.getInstance();
World world = WorldUtils.getBestWorld(mc);
if (world == null || mc.player == null) {
return;
}
Entity cameraEntity = world.getPlayerByUuid(mc.player.getUuid());
if (cameraEntity == null) {
cameraEntity = mc.player;
}
if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) {
cameraEntity = mc.getCameraEntity();
}
if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || !Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_COMPARATOR.getBooleanValue() || cameraEntity == null) {
return;
}
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix());
RenderSystem.applyModelViewMatrix();
// 开始渲染
HitResult trace = RayTraceUtils.getRayTraceFromEntity(world, cameraEntity, false);
if (trace.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) trace).getBlockPos();
// 绕过线程检查
BlockEntity blockEntity = world.getWorldChunk(pos).getBlockEntity(pos);
if (blockEntity instanceof ComparatorBlockEntity) {
LiteralText literalText = new LiteralText(((ComparatorBlockEntity) blockEntity).getOutputSignal() + "");
literalText.formatted(Formatting.GREEN);
// literalText.formatted(Formatting.);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
// 不加 1.17 渲染会有问题
RenderSystem.disableDepthTest();
matrixStack.push();
matrixStack.translate(pos.getX() + 0.5 - camera.getPos().getX(), pos.getY() + 0.6 - camera.getPos().getY(), pos.getZ() + 0.5 - camera.getPos().getZ());
matrixStack.multiplyPositionMatrix(new Matrix4f(camera.getRotation()));
matrixStack.scale(-0.04F, -0.04F, -0.04F);
RenderSystem.applyModelViewMatrix();
Matrix4f lv = AffineTransformation.identity().getMatrix();
float xOffset = (float) (-mc.textRenderer.getWidth(literalText) / 2);
float g = mc.options.getTextBackgroundOpacity(0.25F);
int k = (int) (g * 255.0F) << 24;
mc.textRenderer.draw(literalText, xOffset, 0, 553648127, false, lv, immediate, true, k, 0xf00000);
immediate.draw();
mc.textRenderer.draw(literalText, xOffset, 0, -1, false, lv, immediate, true, 0, 0xf00000);
immediate.draw();
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.enableDepthTest();
}
}
// 结束渲染
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
}
use of net.minecraft.block.entity.BlockEntity in project Polymorph by TheIllusiveC4.
the class PolymorphMod method onInitialize.
@Override
public void onInitialize() {
PolymorphNetwork.setup();
PolymorphCommands.setup();
CommonEventsListener.setup();
PolymorphIntegrations.init();
PolymorphIntegrations.setup();
PolymorphCommon commonApi = PolymorphApi.common();
commonApi.registerBlockEntity2RecipeData(AbstractFurnaceBlockEntity.class, blockEntity -> new FurnaceRecipeData((AbstractFurnaceBlockEntity) blockEntity));
commonApi.registerScreenHandler2BlockEntity(container -> {
for (Slot inventorySlot : container.slots) {
Inventory inventory = inventorySlot.inventory;
if (inventory instanceof BlockEntity) {
return (BlockEntity) inventory;
}
}
return null;
});
}
use of net.minecraft.block.entity.BlockEntity in project Blockus by Brandcraf06.
the class BarrelBlockBase method onUse.
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
return ActionResult.SUCCESS;
} else {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof WoodenBarrelBlockEntity) {
player.openHandledScreen((WoodenBarrelBlockEntity) blockEntity);
player.incrementStat(Stats.OPEN_BARREL);
PiglinBrain.onGuardedBlockInteracted(player, true);
}
return ActionResult.CONSUME;
}
}
use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class PitKilnBlock method breakBlockEntity.
private void breakBlockEntity(World world, BlockPos pos, BlockState state) {
dropStack(world, pos, new ItemStack(PrimevalItems.STRAW, 1 + Math.min(state.get(BUILD_STEP), 4)));
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
for (ItemStack stack : ((PitKilnBlockEntity) blockEntity).getItems()) {
dropStack(world, pos, stack);
}
for (ItemStack stack : ((PitKilnBlockEntity) blockEntity).getLogs()) {
if (stack != null)
dropStack(world, pos, stack);
}
}
}
use of net.minecraft.block.entity.BlockEntity in project Primeval by devs-immortal.
the class PitKilnBlock method onUse.
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!player.getAbilities().allowModifyWorld) {
return ActionResult.PASS;
} else if (player.isSneaking()) {
int stage = state.get(BUILD_STEP);
if (stage == 0) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
Vec3d clicked = hit.getPos().subtract(hit.getBlockPos().getX(), 0, hit.getBlockPos().getZ());
int index = 0;
if (clicked.x > 0.5) {
index += 1;
}
if (clicked.z > 0.5) {
index += 2;
}
player.giveItemStack(((PitKilnBlockEntity) blockEntity).removeItem(index));
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else if (stage > 4) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
world.setBlockState(pos, state.with(BUILD_STEP, stage - 1));
player.giveItemStack(new ItemStack(((PitKilnBlockEntity) blockEntity).removeLog().getItem(), 1));
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else {
world.setBlockState(pos, state.with(BUILD_STEP, stage - 1));
player.giveItemStack(new ItemStack(PrimevalItems.STRAW, 1));
return ActionResult.SUCCESS;
}
} else {
ItemStack itemStack = player.getStackInHand(hand);
int stage = state.get(BUILD_STEP);
if (itemStack.isOf(PrimevalItems.STRAW) && stage < 4) {
world.setBlockState(pos, state.with(BUILD_STEP, stage + 1));
if (!player.isCreative()) {
player.getStackInHand(hand).decrement(1);
}
return ActionResult.SUCCESS;
} else if (itemStack.isIn(PrimevalItemTags.LOGS) && stage > 3 && stage < 8) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
((PitKilnBlockEntity) blockEntity).addLog(new ItemStack(itemStack.getItem(), 1));
world.setBlockState(pos, state.with(BUILD_STEP, stage + 1));
if (!player.isCreative()) {
player.getStackInHand(hand).decrement(1);
}
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else if (!itemStack.isEmpty() && stage == 0) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PitKilnBlockEntity) {
Vec3d clicked = hit.getPos().subtract(hit.getBlockPos().getX(), 0, hit.getBlockPos().getZ());
int index = 0;
if (clicked.x > 0.5) {
index += 1;
}
if (clicked.z > 0.5) {
index += 2;
}
ItemStack newStack = itemStack.copy();
newStack.setCount(1);
if (((PitKilnBlockEntity) blockEntity).addItem(newStack, index)) {
if (!player.isCreative()) {
player.getStackInHand(hand).decrement(1);
}
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
} else {
return ActionResult.FAIL;
}
} else {
return ActionResult.PASS;
}
}
}
Aggregations