Search in sources :

Example 1 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project roadrunner by MaxNeedsSnacks.

the class BlockEntityList method remove.

@Override
public boolean remove(Object o) {
    if (o instanceof BlockEntity) {
        BlockEntity blockEntity = (BlockEntity) o;
        if (currentlyOffThread()) {
            addOffThreadOperation(new OffThreadOperation(blockEntity, OperationType.REMOVE));
            return true;
        }
        checkOffThreadModifications(false);
        if (this.allBlockEntities.remove(o)) {
            if (this.posMap != null) {
                long pos = getEntityPos(blockEntity);
                List<BlockEntity> multiEntry = this.posMapMulti.get(pos);
                if (multiEntry != null) {
                    multiEntry.remove(blockEntity);
                    if (multiEntry.size() <= 1) {
                        this.posMapMulti.remove(pos);
                    }
                }
                if (multiEntry != null && multiEntry.size() > 0) {
                    this.posMap.put(pos, multiEntry.get(0));
                } else {
                    this.posMap.remove(pos);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) CommandBlockBlockEntity(net.minecraft.block.entity.CommandBlockBlockEntity)

Example 2 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project roadrunner by MaxNeedsSnacks.

the class BlockEntityList method addNoDoubleAdd.

private boolean addNoDoubleAdd(BlockEntity blockEntity, boolean exceptionOnDoubleAdd) {
    if (currentlyOffThread()) {
        // Off-thread adds are always treated as "if absent", otherwise the most typical case (race on
        // getBlockEntity) would always crash
        addOffThreadOperation(new OffThreadOperation(blockEntity, OperationType.ADD));
        return true;
    }
    checkOffThreadModifications(false);
    boolean added = this.allBlockEntities.add(blockEntity);
    if (!added && exceptionOnDoubleAdd && // Ignore double add when we encounter vanilla's command block double add bug
    !(blockEntity instanceof CommandBlockBlockEntity)) {
        this.throwException(blockEntity);
    }
    if (added && this.posMap != null) {
        long pos = getEntityPos(blockEntity);
        BlockEntity prev = this.posMap.putIfAbsent(pos, blockEntity);
        if (prev != null) {
            List<BlockEntity> multiEntry = this.posMapMulti.computeIfAbsent(pos, (long l) -> new ArrayList<>());
            if (multiEntry.size() == 0) {
                // newly created multi entry: make sure it contains all elements
                multiEntry.add(prev);
            }
            multiEntry.add(blockEntity);
        }
    }
    return added;
}
Also used : CommandBlockBlockEntity(net.minecraft.block.entity.CommandBlockBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) CommandBlockBlockEntity(net.minecraft.block.entity.CommandBlockBlockEntity)

Example 3 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project Polymorph by TheIllusiveC4.

the class CommonEventsListener method worldTick.

private static void worldTick(final ServerWorld serverWorld) {
    List<BlockEntity> toRemove = new ArrayList<>();
    for (Map.Entry<BlockEntity, BlockEntityRecipeData> entry : TICKABLE_BLOCKS.entrySet()) {
        BlockEntity be = entry.getKey();
        World beWorld = be.getWorld();
        if (be.isRemoved() || beWorld == null || beWorld.isClient()) {
            toRemove.add(be);
        } else {
            entry.getValue().tick();
        }
    }
    for (BlockEntity be : toRemove) {
        TICKABLE_BLOCKS.remove(be);
    }
}
Also used : ArrayList(java.util.ArrayList) BlockEntityRecipeData(top.theillusivec4.polymorph.api.common.component.BlockEntityRecipeData) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 4 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.

the class AutoSteal method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    currentTime++;
    for (Entry<BlockPos, Integer> e : new HashMap<>(opened).entrySet()) {
        if (e.getValue() <= 0)
            opened.remove(e.getKey());
        else
            opened.replace(e.getKey(), e.getValue() - 1);
    }
    if (currentItems != null && currentSyncId != -1) {
        if (currentTime - lastSteal >= getSetting(1).asSlider().getValue()) {
            for (int i = 0; i < currentItems.size(); i++) {
                if (!currentItems.get(i).isEmpty()) {
                    if (isBlacklisted(currentItems.get(i).getItem())) {
                        continue;
                    }
                    int fi = i;
                    boolean openSlot = InventoryUtils.getSlot(false, j -> mc.player.getInventory().getStack(j).isEmpty() || (mc.player.getInventory().getStack(j).isStackable() && mc.player.getInventory().getStack(j).getCount() < mc.player.getInventory().getStack(j).getMaxCount() && currentItems.get(fi).isItemEqual(mc.player.getInventory().getStack(j)))) != 1;
                    if (openSlot) {
                        mc.interactionManager.clickSlot(currentSyncId, i, 0, SlotActionType.QUICK_MOVE, mc.player);
                        currentItems.set(i, ItemStack.EMPTY);
                        lastSteal = currentTime + RandomUtils.nextInt(0, getSetting(2).asSlider().getValueInt() + 1);
                    }
                    return;
                }
            }
            if (getSetting(0).asMode().getMode() >= 1 || getSetting(3).asToggle().getState()) {
                mc.setScreen(null);
                mc.player.networkHandler.sendPacket(new CloseHandledScreenC2SPacket(currentSyncId));
            }
        }
    } else if (currentItems == null && currentSyncId == -1 && getSetting(3).asToggle().getState()) {
        for (BlockEntity be : WorldUtils.getBlockEntities()) {
            if (!opened.containsKey(be.getPos()) && be instanceof ChestBlockEntity && mc.player.getEyePos().distanceTo(Vec3d.ofCenter(be.getPos())) <= getSetting(3).asToggle().getChild(0).asSlider().getValue() + 0.25) {
                Vec3d lookVec = Vec3d.ofCenter(be.getPos()).add(0, 0.5, 0);
                if (getSetting(3).asToggle().getChild(2).asRotate().getState()) {
                    WorldUtils.facePosAuto(lookVec.x, lookVec.y, lookVec.z, getSetting(3).asToggle().getChild(2).asRotate());
                }
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(lookVec, Direction.UP, be.getPos(), false));
                opened.put(be.getPos(), getSetting(3).asToggle().getChild(1).asSlider().getValueInt() * 20);
                return;
            }
        }
    }
}
Also used : CloseHandledScreenC2SPacket(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket) RandomUtils(org.apache.commons.lang3.RandomUtils) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) LiteralText(net.minecraft.text.LiteralText) BlockEntity(net.minecraft.block.entity.BlockEntity) ModuleCategory(org.bleachhack.module.ModuleCategory) Item(net.minecraft.item.Item) EventOpenScreen(org.bleachhack.event.events.EventOpenScreen) InventoryUtils(org.bleachhack.util.InventoryUtils) HashMap(java.util.HashMap) SettingItemList(org.bleachhack.setting.module.SettingItemList) ArrayList(java.util.ArrayList) ScreenHandlerSlotUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket) Direction(net.minecraft.util.math.Direction) WorldUtils(org.bleachhack.util.world.WorldUtils) ItemStack(net.minecraft.item.ItemStack) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) Vec3d(net.minecraft.util.math.Vec3d) SettingMode(org.bleachhack.setting.module.SettingMode) Map(java.util.Map) Hand(net.minecraft.util.Hand) ChestBlock(net.minecraft.block.ChestBlock) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) EventPacket(org.bleachhack.event.events.EventPacket) SettingRotate(org.bleachhack.setting.module.SettingRotate) SettingSlider(org.bleachhack.setting.module.SettingSlider) ScreenHandler(net.minecraft.screen.ScreenHandler) WorldRenderer(org.bleachhack.util.render.WorldRenderer) InventoryS2CPacket(net.minecraft.network.packet.s2c.play.InventoryS2CPacket) BlockHitResult(net.minecraft.util.hit.BlockHitResult) EventWorldRender(org.bleachhack.event.events.EventWorldRender) BlockPos(net.minecraft.util.math.BlockPos) Module(org.bleachhack.module.Module) List(java.util.List) Entry(java.util.Map.Entry) SlotActionType(net.minecraft.screen.slot.SlotActionType) SettingToggle(org.bleachhack.setting.module.SettingToggle) HandledScreen(net.minecraft.client.gui.screen.ingame.HandledScreen) EventTick(org.bleachhack.event.events.EventTick) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) CloseHandledScreenC2SPacket(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket) BlockEntity(net.minecraft.block.entity.BlockEntity) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 5 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.

the class BlockHighlight method onWorldRender.

@BleachSubscribe
public void onWorldRender(EventWorldRender.Post event) {
    int mode = getSetting(0).asMode().getMode();
    if (!(mc.crosshairTarget instanceof BlockHitResult))
        return;
    BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
    BlockState state = mc.world.getBlockState(pos);
    if (state.getMaterial() == Material.AIR || !mc.world.getWorldBorder().contains(pos))
        return;
    int[] color = this.getSetting(4).asColor().getRGBArray();
    if (mode == 0) {
        shader.prepare();
        shader.clearFramebuffer("main");
        Vec3d offset = state.getModelOffset(mc.world, pos);
        MatrixStack matrices = Renderer.matrixFrom(pos.getX() + offset.x, pos.getY() + offset.y, pos.getZ() + offset.z);
        BlockEntity be = mc.world.getBlockEntity(pos);
        BlockEntityRenderer<BlockEntity> renderer = be != null ? mc.getBlockEntityRenderDispatcher().get(be) : null;
        if (renderer != null) {
            renderer.render(be, mc.getTickDelta(), matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()), LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV);
        } else {
            mc.getBlockRenderManager().getModelRenderer().renderFlat(mc.world, mc.getBlockRenderManager().getModel(state), state, pos, matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()).getBuffer(RenderLayers.getMovingBlockLayer(state)), false, new Random(), 0L, OverlayTexture.DEFAULT_UV);
        }
        colorVertexer.draw();
        shader.render();
        shader.drawFramebufferToMain("main");
    } else {
        Box box = state.getOutlineShape(mc.world, pos).getBoundingBox().offset(pos);
        float width = getSetting(2).asSlider().getValueFloat();
        int fill = getSetting(3).asSlider().getValueInt();
        if (width != 0)
            Renderer.drawBoxOutline(box, QuadColor.single(color[0], color[1], color[2], 255), width);
        if (fill != 0)
            Renderer.drawBoxFill(box, QuadColor.single(color[0], color[1], color[2], fill));
    }
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) MatrixStack(net.minecraft.client.util.math.MatrixStack) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) BlockEntity(net.minecraft.block.entity.BlockEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

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