2020-04-13 21:48:35 +02:00
|
|
|
package de.ellpeck.prettypipes;
|
|
|
|
|
2020-04-16 15:45:11 +02:00
|
|
|
import de.ellpeck.prettypipes.items.ModuleItem;
|
2020-04-16 04:42:42 +02:00
|
|
|
import de.ellpeck.prettypipes.pipe.extraction.ExtractionModuleContainer;
|
|
|
|
import de.ellpeck.prettypipes.pipe.extraction.ExtractionModuleGui;
|
|
|
|
import de.ellpeck.prettypipes.pipe.extraction.ExtractionModuleItem;
|
2020-04-16 00:39:53 +02:00
|
|
|
import de.ellpeck.prettypipes.items.ModuleTier;
|
2020-04-13 22:54:18 +02:00
|
|
|
import de.ellpeck.prettypipes.items.WrenchItem;
|
2020-04-14 04:21:28 +02:00
|
|
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
2020-04-14 17:14:24 +02:00
|
|
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
2020-04-16 04:42:42 +02:00
|
|
|
import de.ellpeck.prettypipes.pipe.*;
|
|
|
|
import de.ellpeck.prettypipes.pipe.containers.*;
|
2020-04-13 21:48:35 +02:00
|
|
|
import net.minecraft.block.Block;
|
2020-04-14 01:38:48 +02:00
|
|
|
import net.minecraft.client.gui.ScreenManager;
|
2020-04-13 21:48:35 +02:00
|
|
|
import net.minecraft.client.renderer.RenderType;
|
|
|
|
import net.minecraft.client.renderer.RenderTypeLookup;
|
2020-04-14 01:38:48 +02:00
|
|
|
import net.minecraft.inventory.container.ContainerType;
|
2020-04-13 21:48:35 +02:00
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemGroup;
|
2020-04-13 22:54:18 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-04-14 04:21:28 +02:00
|
|
|
import net.minecraft.nbt.INBT;
|
2020-04-14 01:38:48 +02:00
|
|
|
import net.minecraft.tileentity.TileEntityType;
|
2020-04-14 04:21:28 +02:00
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.common.capabilities.CapabilityInject;
|
|
|
|
import net.minecraftforge.common.capabilities.CapabilityManager;
|
2020-04-14 01:38:48 +02:00
|
|
|
import net.minecraftforge.common.extensions.IForgeContainerType;
|
2020-04-13 21:48:35 +02:00
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2020-04-14 17:14:24 +02:00
|
|
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
2020-04-13 21:48:35 +02:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
|
|
import net.minecraftforge.registries.ForgeRegistries;
|
2020-04-16 00:39:53 +02:00
|
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
2020-04-13 21:48:35 +02:00
|
|
|
|
2020-04-14 04:21:28 +02:00
|
|
|
import javax.annotation.Nullable;
|
2020-04-16 00:39:53 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
2020-04-16 15:45:11 +02:00
|
|
|
import java.util.function.BiFunction;
|
2020-04-16 00:39:53 +02:00
|
|
|
import java.util.function.Function;
|
2020-04-14 04:21:28 +02:00
|
|
|
|
2020-04-13 21:48:35 +02:00
|
|
|
@Mod.EventBusSubscriber(bus = Bus.MOD)
|
|
|
|
public final class Registry {
|
|
|
|
|
2020-04-13 22:54:18 +02:00
|
|
|
public static final ItemGroup GROUP = new ItemGroup(PrettyPipes.ID) {
|
|
|
|
@Override
|
|
|
|
public ItemStack createIcon() {
|
2020-04-14 01:38:48 +02:00
|
|
|
return new ItemStack(wrenchItem);
|
2020-04-13 22:54:18 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-14 04:21:28 +02:00
|
|
|
@CapabilityInject(PipeNetwork.class)
|
|
|
|
public static Capability<PipeNetwork> pipeNetworkCapability;
|
|
|
|
|
2020-04-14 01:38:48 +02:00
|
|
|
public static Item wrenchItem;
|
|
|
|
|
|
|
|
public static Block pipeBlock;
|
|
|
|
public static TileEntityType<PipeTileEntity> pipeTileEntity;
|
2020-04-16 04:42:42 +02:00
|
|
|
|
|
|
|
public static ContainerType<MainPipeContainer> pipeContainer;
|
|
|
|
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
|
2020-04-13 21:48:35 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
|
|
|
event.getRegistry().registerAll(
|
2020-04-14 01:38:48 +02:00
|
|
|
pipeBlock = new PipeBlock().setRegistryName("pipe")
|
2020-04-13 21:48:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerItems(RegistryEvent.Register<Item> event) {
|
2020-04-16 00:39:53 +02:00
|
|
|
IForgeRegistry<Item> registry = event.getRegistry();
|
|
|
|
registry.registerAll(
|
|
|
|
wrenchItem = new WrenchItem().setRegistryName("wrench")
|
2020-04-13 22:54:18 +02:00
|
|
|
);
|
2020-04-16 00:39:53 +02:00
|
|
|
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
|
2020-04-13 22:54:18 +02:00
|
|
|
|
2020-04-13 21:48:35 +02:00
|
|
|
ForgeRegistries.BLOCKS.getValues().stream()
|
|
|
|
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
2020-04-16 00:39:53 +02:00
|
|
|
.forEach(b -> registry.register(new BlockItem(b, new Item.Properties().group(GROUP)).setRegistryName(b.getRegistryName())));
|
2020-04-13 21:48:35 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 01:38:48 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerTiles(RegistryEvent.Register<TileEntityType<?>> event) {
|
|
|
|
event.getRegistry().registerAll(
|
|
|
|
pipeTileEntity = (TileEntityType<PipeTileEntity>) TileEntityType.Builder.create(PipeTileEntity::new, pipeBlock).build(null).setRegistryName("pipe")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerContainer(RegistryEvent.Register<ContainerType<?>> event) {
|
|
|
|
event.getRegistry().registerAll(
|
2020-04-16 04:42:42 +02:00
|
|
|
pipeContainer = (ContainerType<MainPipeContainer>) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
|
|
|
|
extractionModuleContainer = (ContainerType<ExtractionModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new ExtractionModuleContainer(extractionModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("extraction_module"));
|
2020-04-16 00:39:53 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 21:48:35 +02:00
|
|
|
public static void setup(FMLCommonSetupEvent event) {
|
2020-04-14 04:21:28 +02:00
|
|
|
CapabilityManager.INSTANCE.register(PipeNetwork.class, new Capability.IStorage<PipeNetwork>() {
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public INBT writeNBT(Capability<PipeNetwork> capability, PipeNetwork instance, Direction side) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readNBT(Capability<PipeNetwork> capability, PipeNetwork instance, Direction side, INBT nbt) {
|
2020-04-13 21:48:35 +02:00
|
|
|
|
2020-04-14 04:21:28 +02:00
|
|
|
}
|
|
|
|
}, () -> null);
|
2020-04-14 17:14:24 +02:00
|
|
|
PacketHandler.setup();
|
2020-04-13 21:48:35 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:45:11 +02:00
|
|
|
private static Item[] createTieredModule(String name, BiFunction<String, ModuleTier, ModuleItem> item) {
|
2020-04-16 04:42:42 +02:00
|
|
|
List<Item> items = new ArrayList<>();
|
|
|
|
for (ModuleTier tier : ModuleTier.values())
|
2020-04-16 15:45:11 +02:00
|
|
|
items.add(item.apply(name, tier).setRegistryName(tier.name().toLowerCase(Locale.ROOT) + "_" + name));
|
2020-04-16 04:42:42 +02:00
|
|
|
return items.toArray(new Item[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final class Client {
|
|
|
|
public static void setup(FMLClientSetupEvent event) {
|
|
|
|
RenderTypeLookup.setRenderLayer(pipeBlock, RenderType.cutout());
|
|
|
|
ClientRegistry.bindTileEntityRenderer(pipeTileEntity, PipeRenderer::new);
|
|
|
|
|
|
|
|
ScreenManager.registerFactory(pipeContainer, MainPipeGui::new);
|
|
|
|
ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new);
|
|
|
|
}
|
2020-04-13 21:48:35 +02:00
|
|
|
}
|
|
|
|
}
|