Search in sources :

Example 1 with ChestBlockEntity

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

use of net.minecraft.block.entity.ChestBlockEntity in project SeedcrackerX by 19MisterX98.

the class ShipwreckFinder method findInChunk.

@Override
public List<BlockPos> findInChunk() {
    Biome biome = this.world.getBiomeForNoiseGen((this.chunkPos.x << 2) + 2, 64, (this.chunkPos.z << 2) + 2).value();
    if (!Features.SHIPWRECK.isValidBiome(BiomeFixer.swap(biome))) {
        return new ArrayList<>();
    }
    List<BlockPos> result = super.findInChunk();
    result.removeIf(pos -> {
        BlockState state = this.world.getBlockState(pos);
        if (state.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE)
            return true;
        BlockEntity blockEntity = this.world.getBlockEntity(pos);
        if (!(blockEntity instanceof ChestBlockEntity))
            return true;
        return !this.onChestFound(pos);
    });
    return result;
}
Also used : Biome(net.minecraft.world.biome.Biome) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity)

Example 3 with ChestBlockEntity

use of net.minecraft.block.entity.ChestBlockEntity in project EdenClient by HahaOO7.

the class ContainerInfo method interactBlock.

private ActionResult interactBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult blockHitResult) {
    BlockEntity be = world.getBlockEntity(blockHitResult.getBlockPos());
    boolean isLeftChest = false;
    if (be instanceof ChestBlockEntity) {
        BlockState blockState = world.getBlockState(blockHitResult.getBlockPos());
        isLeftChest = blockState.get(ChestBlock.CHEST_TYPE) == ChestType.LEFT;
    }
    if (be instanceof Inventory && !isLeftChest) {
        lastInteractedBlock = blockHitResult.getBlockPos();
    } else {
        lastInteractedBlock = null;
    }
    return ActionResult.PASS;
}
Also used : BlockState(net.minecraft.block.BlockState) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) Inventory(net.minecraft.inventory.Inventory) PlayerInventory(net.minecraft.entity.player.PlayerInventory) BlockEntity(net.minecraft.block.entity.BlockEntity) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity)

Example 4 with ChestBlockEntity

use of net.minecraft.block.entity.ChestBlockEntity in project lithium-fabric by CaffeineMC.

the class HopperHelper method vanillaGetBlockInventory.

/**
 * Gets the block inventory at the given position, exactly like vanilla gets it.
 * Needed because we don't want to search for entity inventories like the vanilla method does.
 *
 * @param world    world we are searching in
 * @param blockPos position of the block inventory
 * @return the block inventory at the given position
 */
@Nullable
public static Inventory vanillaGetBlockInventory(World world, BlockPos blockPos) {
    // [VanillaCopy]
    Inventory inventory = null;
    BlockState blockState = world.getBlockState(blockPos);
    Block block = blockState.getBlock();
    if (block instanceof InventoryProvider) {
        inventory = ((InventoryProvider) block).getInventory(blockState, world, blockPos);
    } else if (blockState.hasBlockEntity()) {
        BlockEntity blockEntity = world.getBlockEntity(blockPos);
        if (blockEntity instanceof Inventory) {
            inventory = (Inventory) blockEntity;
            if (inventory instanceof ChestBlockEntity && block instanceof ChestBlock) {
                inventory = ChestBlock.getInventory((ChestBlock) block, blockState, world, blockPos, true);
            }
        }
    }
    return inventory;
}
Also used : BlockState(net.minecraft.block.BlockState) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) Block(net.minecraft.block.Block) ChestBlock(net.minecraft.block.ChestBlock) InventoryProvider(net.minecraft.block.InventoryProvider) ChestBlock(net.minecraft.block.ChestBlock) SidedInventory(net.minecraft.inventory.SidedInventory) Inventory(net.minecraft.inventory.Inventory) BlockEntity(net.minecraft.block.entity.BlockEntity) LootableContainerBlockEntity(net.minecraft.block.entity.LootableContainerBlockEntity) HopperBlockEntity(net.minecraft.block.entity.HopperBlockEntity) ChestBlockEntity(net.minecraft.block.entity.ChestBlockEntity) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BlockEntity (net.minecraft.block.entity.BlockEntity)4 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)4 ArrayList (java.util.ArrayList)2 BlockState (net.minecraft.block.BlockState)2 ChestBlock (net.minecraft.block.ChestBlock)2 Inventory (net.minecraft.inventory.Inventory)2 BlockPos (net.minecraft.util.math.BlockPos)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Block (net.minecraft.block.Block)1 InventoryProvider (net.minecraft.block.InventoryProvider)1 HopperBlockEntity (net.minecraft.block.entity.HopperBlockEntity)1 LootableContainerBlockEntity (net.minecraft.block.entity.LootableContainerBlockEntity)1 HandledScreen (net.minecraft.client.gui.screen.ingame.HandledScreen)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 SidedInventory (net.minecraft.inventory.SidedInventory)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1