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;
}
}
});
});
});
}
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();
}
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;
}
}
}
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;
}
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;
}
}
}
}
Aggregations