2019-07-11 19:55:11 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2019-08-27 17:35:34 +02:00
|
|
|
import com.simibubi.create.modules.logistics.block.FlexcrateContainer;
|
|
|
|
import com.simibubi.create.modules.logistics.block.FlexcrateScreen;
|
2019-07-23 12:54:53 +02:00
|
|
|
import com.simibubi.create.modules.schematics.block.SchematicTableContainer;
|
|
|
|
import com.simibubi.create.modules.schematics.block.SchematicTableScreen;
|
|
|
|
import com.simibubi.create.modules.schematics.block.SchematicannonContainer;
|
|
|
|
import com.simibubi.create.modules.schematics.block.SchematicannonScreen;
|
2019-07-11 19:55:11 +02:00
|
|
|
|
2019-07-16 16:01:51 +02:00
|
|
|
import net.minecraft.client.gui.IHasContainer;
|
2019-07-11 19:55:11 +02:00
|
|
|
import net.minecraft.client.gui.ScreenManager;
|
2019-07-16 16:01:51 +02:00
|
|
|
import net.minecraft.client.gui.ScreenManager.IScreenFactory;
|
|
|
|
import net.minecraft.client.gui.screen.Screen;
|
2019-07-11 19:55:11 +02:00
|
|
|
import net.minecraft.inventory.container.Container;
|
|
|
|
import net.minecraft.inventory.container.ContainerType;
|
2019-07-16 16:01:51 +02:00
|
|
|
import net.minecraft.inventory.container.ContainerType.IFactory;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-07-11 19:55:11 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
2019-07-16 16:01:51 +02:00
|
|
|
import net.minecraftforge.fml.network.IContainerFactory;
|
2019-07-11 19:55:11 +02:00
|
|
|
|
|
|
|
@EventBusSubscriber(bus = Bus.MOD)
|
|
|
|
public enum AllContainers {
|
|
|
|
|
2019-08-29 01:51:28 +02:00
|
|
|
SCHEMATIC_TABLE(SchematicTableContainer::new),
|
|
|
|
SCHEMATICANNON(SchematicannonContainer::new),
|
|
|
|
FLEXCRATE(FlexcrateContainer::new),
|
2019-08-06 19:00:51 +02:00
|
|
|
|
|
|
|
;
|
2019-07-11 19:55:11 +02:00
|
|
|
|
|
|
|
public ContainerType<? extends Container> type;
|
2019-07-16 16:01:51 +02:00
|
|
|
private IFactory<?> factory;
|
2019-07-11 19:55:11 +02:00
|
|
|
|
2019-07-16 16:01:51 +02:00
|
|
|
private <C extends Container> AllContainers(IContainerFactory<C> factory) {
|
|
|
|
this.factory = factory;
|
2019-07-11 19:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onContainerTypeRegistry(final RegistryEvent.Register<ContainerType<?>> e) {
|
2019-07-16 16:01:51 +02:00
|
|
|
|
|
|
|
for (AllContainers container : values()) {
|
|
|
|
container.type = new ContainerType<>(container.factory)
|
|
|
|
.setRegistryName(new ResourceLocation(Create.ID, container.name().toLowerCase()));
|
|
|
|
e.getRegistry().register(container.type);
|
|
|
|
}
|
2019-07-11 19:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void registerScreenFactories() {
|
2019-08-29 01:51:28 +02:00
|
|
|
bind(SCHEMATIC_TABLE, SchematicTableScreen::new);
|
|
|
|
bind(SCHEMATICANNON, SchematicannonScreen::new);
|
|
|
|
bind(FLEXCRATE, FlexcrateScreen::new);
|
2019-07-16 16:01:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private static <C extends Container, S extends Screen & IHasContainer<C>> void bind(AllContainers c, IScreenFactory<C, S> factory) {
|
|
|
|
ScreenManager.registerFactory((ContainerType<C>) c.type, factory);
|
2019-07-11 19:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|