2019-07-11 19:55:11 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
|
|
|
import com.simibubi.create.block.SchematicTableContainer;
|
2019-07-16 16:01:51 +02:00
|
|
|
import com.simibubi.create.block.SchematicannonContainer;
|
2019-07-11 19:55:11 +02:00
|
|
|
import com.simibubi.create.gui.SchematicTableScreen;
|
2019-07-16 16:01:51 +02:00
|
|
|
import com.simibubi.create.gui.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-07-16 16:01:51 +02:00
|
|
|
SchematicTable(SchematicTableContainer::new),
|
|
|
|
Schematicannon(SchematicannonContainer::new);
|
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-07-16 16:01:51 +02:00
|
|
|
bind(SchematicTable, SchematicTableScreen::new);
|
|
|
|
bind(Schematicannon, SchematicannonScreen::new);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
|
|
}
|