Search in sources :

Example 41 with BlockEntity

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();
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) ComparatorBlockEntity(net.minecraft.block.entity.ComparatorBlockEntity) Entity(net.minecraft.entity.Entity) MatrixStack(net.minecraft.client.util.math.MatrixStack) World(net.minecraft.world.World) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient) ComparatorBlockEntity(net.minecraft.block.entity.ComparatorBlockEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockEntity(net.minecraft.block.entity.BlockEntity) ComparatorBlockEntity(net.minecraft.block.entity.ComparatorBlockEntity) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 42 with BlockEntity

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;
    });
}
Also used : AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity) FurnaceRecipeData(top.theillusivec4.polymorph.common.component.FurnaceRecipeData) Slot(net.minecraft.screen.slot.Slot) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) Inventory(net.minecraft.inventory.Inventory) BlockEntity(net.minecraft.block.entity.BlockEntity) AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity)

Example 43 with BlockEntity

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;
    }
}
Also used : WoodenBarrelBlockEntity(com.brand.blockus.blocks.blockentity.WoodenBarrelBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) WoodenBarrelBlockEntity(com.brand.blockus.blocks.blockentity.WoodenBarrelBlockEntity)

Example 44 with BlockEntity

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);
        }
    }
}
Also used : PitKilnBlockEntity(net.cr24.primeval.block.entity.PitKilnBlockEntity) ItemStack(net.minecraft.item.ItemStack) BlockEntity(net.minecraft.block.entity.BlockEntity) PitKilnBlockEntity(net.cr24.primeval.block.entity.PitKilnBlockEntity)

Example 45 with BlockEntity

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;
        }
    }
}
Also used : PitKilnBlockEntity(net.cr24.primeval.block.entity.PitKilnBlockEntity) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) BlockEntity(net.minecraft.block.entity.BlockEntity) PitKilnBlockEntity(net.cr24.primeval.block.entity.PitKilnBlockEntity)

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