Search in sources :

Example 1 with ScreenHandler

use of net.minecraft.screen.ScreenHandler in project Polymorph by TheIllusiveC4.

the class PolymorphNetwork method handleStackSelect.

private static void handleStackSelect(MinecraftServer pServer, ServerPlayerEntity pPlayer, ServerPlayNetworkHandler pHandler, PacketByteBuf pBuf, PacketSender pResponseSender) {
    Identifier identifier = pBuf.readIdentifier();
    pServer.execute(() -> {
        World world = pPlayer.getEntityWorld();
        Optional<? extends Recipe<?>> maybeRecipe = world.getRecipeManager().get(identifier);
        maybeRecipe.ifPresent(recipe -> {
            ScreenHandler screenHandler = pPlayer.currentScreenHandler;
            PolymorphApi.common().getRecipeDataFromBlockEntity(screenHandler).ifPresent(recipeData -> {
                recipeData.selectRecipe(recipe);
                for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
                    if (integration.selectRecipe(screenHandler, recipe)) {
                        return;
                    }
                }
            });
        });
    });
}
Also used : Identifier(net.minecraft.util.Identifier) ForgingScreenHandler(net.minecraft.screen.ForgingScreenHandler) ScreenHandler(net.minecraft.screen.ScreenHandler) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule) World(net.minecraft.world.World)

Example 2 with ScreenHandler

use of net.minecraft.screen.ScreenHandler in project Polymorph by TheIllusiveC4.

the class PolymorphClientMod method onInitializeClient.

@Override
public void onInitializeClient() {
    PolymorphClientNetwork.setup();
    ClientEventsListener.setup();
    PolymorphApi.client().registerWidget(handledScreen -> {
        ScreenHandler screenHandler = handledScreen.getScreenHandler();
        if (screenHandler instanceof SmithingScreenHandler) {
            return new PlayerRecipesWidget(handledScreen, screenHandler.slots.get(2));
        } else if (screenHandler instanceof AbstractFurnaceScreenHandler) {
            return new FurnaceRecipesWidget(handledScreen);
        }
        return null;
    });
    PolymorphIntegrations.clientSetup();
}
Also used : AbstractFurnaceScreenHandler(net.minecraft.screen.AbstractFurnaceScreenHandler) FurnaceRecipesWidget(top.theillusivec4.polymorph.client.recipe.widget.FurnaceRecipesWidget) PlayerRecipesWidget(top.theillusivec4.polymorph.client.recipe.widget.PlayerRecipesWidget) SmithingScreenHandler(net.minecraft.screen.SmithingScreenHandler) ScreenHandler(net.minecraft.screen.ScreenHandler) SmithingScreenHandler(net.minecraft.screen.SmithingScreenHandler) AbstractFurnaceScreenHandler(net.minecraft.screen.AbstractFurnaceScreenHandler)

Example 3 with ScreenHandler

use of net.minecraft.screen.ScreenHandler in project Polymorph by TheIllusiveC4.

the class CommonEventsListener method openScreenHandler.

public static void openScreenHandler(ServerPlayerEntity player) {
    ScreenHandler screenHandler = player.currentScreenHandler;
    PolymorphCommon commonApi = PolymorphApi.common();
    commonApi.getRecipeDataFromBlockEntity(screenHandler).ifPresent(recipeData -> {
        PolymorphPacketDistributor packetDistributor = commonApi.getPacketDistributor();
        if (recipeData.isFailing() || recipeData.isEmpty(null)) {
            packetDistributor.sendRecipesListS2C(player);
        } else {
            Pair<SortedSet<RecipePair>, Identifier> data = recipeData.getPacketData();
            packetDistributor.sendRecipesListS2C(player, data.getLeft(), data.getRight());
        }
    });
    for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
        if (integration.openScreenHandler(screenHandler, player)) {
            return;
        }
    }
}
Also used : Identifier(net.minecraft.util.Identifier) PolymorphPacketDistributor(top.theillusivec4.polymorph.api.common.base.PolymorphPacketDistributor) ScreenHandler(net.minecraft.screen.ScreenHandler) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) SortedSet(java.util.SortedSet)

Example 4 with ScreenHandler

use of net.minecraft.screen.ScreenHandler in project KahzerxMod by otakucraft.

the class SpoofExtension method spoofInv.

public int spoofInv(ServerCommandSource source, String playerE) throws CommandSyntaxException {
    int invSize = 54;
    int hotBarSize = 9;
    int hotBarStartPos = 27;
    int invStartPos = 9;
    Inventory inventory = new SimpleInventory(invSize);
    ServerPlayerEntity player = source.getPlayer();
    ServerPlayerEntity player2 = source.getServer().getPlayerManager().getPlayer(playerE);
    assert player2 != null;
    for (int i = 0; i < player2.getInventory().main.size(); i++) {
        if (i < hotBarSize) {
            inventory.setStack(i + hotBarStartPos, player2.getInventory().main.get(i));
        } else {
            inventory.setStack(i - invStartPos, player2.getInventory().main.get(i));
        }
    }
    int armorSlotStartPos = 45;
    for (int j = 0; j < player2.getInventory().armor.size(); j++) {
        inventory.setStack(j + armorSlotStartPos, player2.getInventory().armor.get(j));
    }
    int offHandSlotPos = 36;
    inventory.setStack(offHandSlotPos, player2.getInventory().offHand.get(0));
    ScreenHandlerListener listener = new ScreenHandlerListener() {

        @Override
        public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
        // source.getServer().getPlayerManager().saveAllPlayerData();
        }

        @Override
        public void onPropertyUpdate(ScreenHandler handler, int property, int value) {
        }
    };
    player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> {
        GenericContainerScreenHandler invCont = GenericContainerScreenHandler.createGeneric9x6(i, playerInventory, inventory);
        invCont.addListener(listener);
        return invCont;
    }, new LiteralText(String.format("%s stop hax >:(", player.getName().getString()))));
    return 1;
}
Also used : ExtensionSettings(com.kahzerx.kahzerxmod.extensions.ExtensionSettings) LiteralText(net.minecraft.text.LiteralText) ScreenHandler(net.minecraft.screen.ScreenHandler) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) GenericExtension(com.kahzerx.kahzerxmod.extensions.GenericExtension) EnderChestInventory(net.minecraft.inventory.EnderChestInventory) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ScreenHandlerListener(net.minecraft.screen.ScreenHandlerListener) SimpleNamedScreenHandlerFactory(net.minecraft.screen.SimpleNamedScreenHandlerFactory) Extensions(com.kahzerx.kahzerxmod.Extensions) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) ItemStack(net.minecraft.item.ItemStack) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) ScreenHandlerListener(net.minecraft.screen.ScreenHandlerListener) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) SimpleNamedScreenHandlerFactory(net.minecraft.screen.SimpleNamedScreenHandlerFactory) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ScreenHandler(net.minecraft.screen.ScreenHandler) GenericContainerScreenHandler(net.minecraft.screen.GenericContainerScreenHandler) ItemStack(net.minecraft.item.ItemStack) EnderChestInventory(net.minecraft.inventory.EnderChestInventory) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) LiteralText(net.minecraft.text.LiteralText)

Example 5 with ScreenHandler

use of net.minecraft.screen.ScreenHandler in project KiwiClient by TangyKiwi.

the class Dupe method packetSent.

public static void packetSent(Packet<?> p) {
    if (shouldDupe() && p instanceof PlayerActionC2SPacket) {
        PlayerActionC2SPacket packet = (PlayerActionC2SPacket) p;
        if (packet.getAction() == PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK) {
            ScreenHandler var3 = MinecraftClient.getInstance().player.currentScreenHandler;
            if (var3 instanceof ShulkerBoxScreenHandler) {
                ShulkerBoxScreenHandler screenHandler = (ShulkerBoxScreenHandler) var3;
                Int2ObjectArrayMap<ItemStack> stack = new Int2ObjectArrayMap();
                stack.put(0, screenHandler.getSlot(0).getStack());
                ClickSlotC2SPacket cs = new ClickSlotC2SPacket(screenHandler.syncId, 0, 0, 0, SlotActionType.PICKUP, screenHandler.getSlot(0).getStack(), stack);
                MinecraftClient.getInstance().getNetworkHandler().sendPacket(cs);
                actuallyPullThrough = false;
                preDoDupe = false;
            }
        }
    }
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) ShulkerBoxScreenHandler(net.minecraft.screen.ShulkerBoxScreenHandler) Int2ObjectArrayMap(it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap) ScreenHandler(net.minecraft.screen.ScreenHandler) ShulkerBoxScreenHandler(net.minecraft.screen.ShulkerBoxScreenHandler) ItemStack(net.minecraft.item.ItemStack) ClickSlotC2SPacket(net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket)

Aggregations

ScreenHandler (net.minecraft.screen.ScreenHandler)13 Identifier (net.minecraft.util.Identifier)5 ItemStack (net.minecraft.item.ItemStack)4 AbstractCompatibilityModule (top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule)4 ForgingScreenHandler (net.minecraft.screen.ForgingScreenHandler)3 GenericContainerScreenHandler (net.minecraft.screen.GenericContainerScreenHandler)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ShulkerBoxScreenHandler (net.minecraft.screen.ShulkerBoxScreenHandler)2 Extensions (com.kahzerx.kahzerxmod.Extensions)1 ExtensionSettings (com.kahzerx.kahzerxmod.extensions.ExtensionSettings)1 GenericExtension (com.kahzerx.kahzerxmod.extensions.GenericExtension)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 SlotReference (dev.emi.trinkets.api.SlotReference)1 TrinketRenderer (dev.emi.trinkets.api.client.TrinketRenderer)1 Int2ObjectArrayMap (it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap)1 SortedSet (java.util.SortedSet)1 GunTableScreenHandler (mod.azure.doom.client.gui.GunTableScreenHandler)1 BroomEntityModel (moriyashiine.bewitchment.api.client.model.BroomEntityModel)1 BroomEntity (moriyashiine.bewitchment.api.entity.BroomEntity)1