net.minecraft.inventory.container.ContainerType Java Examples

The following examples show how to use net.minecraft.inventory.container.ContainerType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientPacketHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings ("unchecked")
private void handleOpenContainer(PacketCustom packet, Minecraft mc) {
    ContainerType<?> rawType = packet.readRegistryIdUnsafe(ForgeRegistries.CONTAINERS);
    int windowId = packet.readVarInt();
    ITextComponent name = packet.readTextComponent();
    if (rawType instanceof ICCLContainerType<?>) {
        ICCLContainerType<?> type = (ICCLContainerType<?>) rawType;
        ScreenManager.getScreenFactory(rawType, mc, windowId, name)//
                .map(e -> (ScreenManager.IScreenFactory<Container, ?>) e)//
                .ifPresent(screenFactory -> {
                    Container container = type.create(windowId, Minecraft.getInstance().player.inventory, packet);
                    Screen screen = screenFactory.create(container, mc.player.inventory, name);
                    mc.player.openContainer = ((IHasContainer<?>) screen).getContainer();
                    mc.displayGuiScreen(screen);
                });

    }
}
 
Example #2
Source File: ServerUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider, Consumer<MCDataOutput> packetConsumer) {
    if (player.world.isRemote()) {
        return;
    }
    player.closeContainer();
    player.getNextWindowId();
    int containerId = player.currentWindowId;

    Container container = containerProvider.createMenu(containerId, player.inventory, player);
    ContainerType<?> type = container.getType();

    PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_OPEN_CONTAINER);
    packet.writeRegistryIdUnsafe(ForgeRegistries.CONTAINERS, type);
    packet.writeVarInt(containerId);
    packet.writeTextComponent(containerProvider.getDisplayName());
    packetConsumer.accept(packet);

    packet.sendToPlayer(player);
    player.openContainer = container;
    player.openContainer.addListener(player);
    MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container));
}
 
Example #3
Source File: SurvivalistMod.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public SurvivalistMod()
{
    instance = this;

    ModLoadingContext modLoadingContext = ModLoadingContext.get();
    IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

    HELPER.subscribeEvents(modEventBus);
    SurvivalistBlocks.HELPER.subscribeEvents(modEventBus);
    SurvivalistItems.HELPER.subscribeEvents(modEventBus);
    SurvivalistTileEntityTypes.HELPER.subscribeEvents(modEventBus);

    modEventBus.addGenericListener(ContainerType.class, this::registerContainers);
    modEventBus.addGenericListener(IRecipeSerializer.class, this::registerRecipeSerializers);
    modEventBus.addGenericListener(GlobalLootModifierSerializer.class, this::lootModifiers);
    modEventBus.addListener(this::commonSetup);
    modEventBus.addListener(this::clientSetup);
    modEventBus.addListener(this::gatherData);

    MinecraftForge.EVENT_BUS.addListener(this::serverStarting);

    modLoadingContext.registerConfig(ModConfig.Type.SERVER, ConfigManager.SERVER_SPEC);
}
 
Example #4
Source File: SurvivalistMod.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void registerContainers(RegistryEvent.Register<ContainerType<?>> event)
{
    event.getRegistry().registerAll(
            withName(new ContainerType<>(DryingRackContainer::new), "rack"),
            withName(new ContainerType<>(SawmillContainer::new), "sawmill")
    );
}
 
Example #5
Source File: ModContent.java    From EnderStorage with MIT License 4 votes vote down vote up
@SubscribeEvent
public static void onRegisterContainers(RegistryEvent.Register<ContainerType<?>> event) {
    IForgeRegistry<ContainerType<?>> registry = event.getRegistry();
    registry.register(ICCLContainerType.create(ContainerEnderItemStorage::new).setRegistryName("item_storage"));
}
 
Example #6
Source File: ICCLContainerType.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
static <T extends Container> ContainerType<T> create(ICCLContainerFactory<T> factory) {
    return new CCLContainerType<>(factory);
}