mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Add IContainerFactory for reading custom container data on the client
This commit is contained in:
1 parent
5dc944c1c3
commit
d5ee80a70a
6 files changed
+117
-9
No files matched your search
@@ -0,0 +1,16 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public interface IForgeContainerType<T>
|
||||
{
|
||||
static <T extends Container> ContainerType<T> create(net.minecraftforge.fml.network.IContainerFactory<T> factory)
|
||||
{
|
||||
return new ContainerType<>(factory);
|
||||
}
|
||||
|
||||
T create(int windowId, PlayerInventory playerInv, PacketBuffer extraData);
|
||||
}
|
||||
@@ -21,11 +21,13 @@ package net.minecraftforge.fml.network;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.IHasContainer;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -208,8 +210,14 @@ public class FMLPlayMessages
|
||||
public static void handle(OpenContainer msg, Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
// TODO extend IScreenFactory to allow for extra data
|
||||
ScreenManager.openScreen(msg.getType(), Minecraft.getInstance(), msg.getWindowId(), msg.getName());
|
||||
ScreenManager.getScreenFactory(msg.getType(), Minecraft.getInstance(), msg.getWindowId(), msg.getName())
|
||||
.ifPresent(f -> {
|
||||
Container c = msg.getType().create(msg.getWindowId(), Minecraft.getInstance().player.inventory, msg.getAdditionalData());
|
||||
@SuppressWarnings("unchecked")
|
||||
Screen s = ((ScreenManager.IScreenFactory<Container, ?>)f).create(c, Minecraft.getInstance().player.inventory, msg.getName());
|
||||
Minecraft.getInstance().player.openContainer = ((IHasContainer<?>)s).getContainer();
|
||||
Minecraft.getInstance().displayGuiScreen(s);
|
||||
});
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.minecraftforge.fml.network;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public interface IContainerFactory<T extends Container> extends ContainerType.IFactory<T>
|
||||
{
|
||||
T create(int windowId, PlayerInventory inv, PacketBuffer data);
|
||||
|
||||
@Override
|
||||
default T create(int p_create_1_, PlayerInventory p_create_2_)
|
||||
{
|
||||
return create(p_create_1_, p_create_2_, null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user