Search in sources :

Example 1 with CloseHandledScreenC2SPacket

use of net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket in project FabricWaystones by LordDeatHunter.

the class UniversalWaystoneScreenHandler method closeOnClient.

protected void closeOnClient() {
    ((ClientPlayerEntityAccessor) player).getNetworkHandler().sendPacket(new CloseHandledScreenC2SPacket(this.syncId));
    setCursorStack(ItemStack.EMPTY);
    player.currentScreenHandler = player.playerScreenHandler;
    MinecraftClient.getInstance().setScreen(null);
}
Also used : CloseHandledScreenC2SPacket(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket)

Example 2 with CloseHandledScreenC2SPacket

use of net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket 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 3 with CloseHandledScreenC2SPacket

use of net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket in project BleachHack by BleachDrinker420.

the class AutoSteal method onSendPacket.

@BleachSubscribe
public void onSendPacket(EventPacket.Send event) {
    if (event.getPacket() instanceof CloseHandledScreenC2SPacket) {
        currentItems = null;
        currentSyncId = -1;
    }
    if (event.getPacket() instanceof PlayerInteractBlockC2SPacket) {
        BlockPos pos = ((PlayerInteractBlockC2SPacket) event.getPacket()).getBlockHitResult().getBlockPos();
        if (mc.world.getBlockState(pos).getBlock() instanceof ChestBlock) {
            currentPos = pos;
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ChestBlock(net.minecraft.block.ChestBlock) CloseHandledScreenC2SPacket(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 4 with CloseHandledScreenC2SPacket

use of net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket in project BleachHack by BleachDrinker420.

the class AutoSteal method onOpenScreen.

@BleachSubscribe
public void onOpenScreen(EventOpenScreen event) {
    currentSyncId = -1;
    if (mc.player != null) {
        if (event.getScreen() instanceof HandledScreen) {
            ScreenHandler handler = ((HandledScreen<?>) event.getScreen()).getScreenHandler();
            if (handler instanceof GenericContainerScreenHandler) {
                currentSyncId = handler.syncId;
                lastOpen = currentTime;
                if (getSetting(0).asMode().getMode() >= 1) {
                    event.setCancelled(true);
                }
            } else {
                currentItems = null;
                mc.player.networkHandler.sendPacket(new CloseHandledScreenC2SPacket(currentSyncId));
            }
        } else {
            currentItems = null;
            mc.player.networkHandler.sendPacket(new CloseHandledScreenC2SPacket(currentSyncId));
        }
    }
}
Also used : HandledScreen(net.minecraft.client.gui.screen.ingame.HandledScreen) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) ScreenHandler(net.minecraft.screen.ScreenHandler) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) CloseHandledScreenC2SPacket(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Aggregations

CloseHandledScreenC2SPacket (net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket)4 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)3 ChestBlock (net.minecraft.block.ChestBlock)2 HandledScreen (net.minecraft.client.gui.screen.ingame.HandledScreen)2 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)2 GenericContainerScreenHandler (net.minecraft.screen.GenericContainerScreenHandler)2 ScreenHandler (net.minecraft.screen.ScreenHandler)2 BlockPos (net.minecraft.util.math.BlockPos)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 InventoryS2CPacket (net.minecraft.network.packet.s2c.play.InventoryS2CPacket)1 ScreenHandlerSlotUpdateS2CPacket (net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket)1 SlotActionType (net.minecraft.screen.slot.SlotActionType)1