forked from Tfarcenim/crafting-station
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
343 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/java/com/tfar/examplemod/CraftingInventoryPersistant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,74 @@ | ||
package com.tfar.examplemod; | ||
|
||
import com.tfar.examplemod.client.CraftingStationScreen; | ||
import com.tfar.examplemod.client.CraftingStationTileSpecialRenderer; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.client.gui.ScreenManager; | ||
import net.minecraft.inventory.container.ContainerType; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.tileentity.TileEntityType; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraft.item.ItemBlock; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.client.event.ModelRegistryEvent; | ||
import net.minecraftforge.client.model.ModelLoader; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.common.extensions.IForgeContainerType; | ||
import net.minecraftforge.event.RegistryEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.DistExecutor; | ||
import net.minecraftforge.fml.client.registry.ClientRegistry; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; | ||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; | ||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent; | ||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; | ||
import net.minecraftforge.registries.ObjectHolder; | ||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.network.NetworkRegistry; | ||
import net.minecraftforge.fml.common.registry.GameRegistry; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
// The value here should match an entry in the META-INF/mods.toml file | ||
@Mod(CraftingStation.MODID) | ||
@Mod.EventBusSubscriber | ||
@Mod(modid = CraftingStation.MODID, name = CraftingStation.NAME, version = CraftingStation.VERSION) | ||
public class CraftingStation { | ||
// Directly reference a log4j logger. | ||
|
||
public static final String MODID = "craftingstation"; | ||
public static final String NAME = "Crafting Station"; | ||
public static final String VERSION = "@VERSION@"; | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
public CraftingStation() { | ||
// Register the setup method for modloading | ||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); | ||
// Register the doClientStuff method for modloading | ||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); | ||
@Mod.Instance | ||
public static CraftingStation INSTANCE; | ||
|
||
// Register ourselves for server and other game events we are interested in | ||
public CraftingStation() { | ||
MinecraftForge.EVENT_BUS.register(this); | ||
} | ||
|
||
private void setup(final FMLCommonSetupEvent event) { | ||
} | ||
|
||
private void doClientStuff(final FMLClientSetupEvent event) { | ||
ScreenManager.registerFactory(Objects.crafting_station_container, CraftingStationScreen::new); | ||
DistExecutor.runWhenOn(Dist.CLIENT,() -> () -> ClientRegistry.bindTileEntitySpecialRenderer(CraftingStationTile.class, new CraftingStationTileSpecialRenderer())); | ||
@Mod.EventHandler | ||
public void preInit(final FMLPreInitializationEvent event) { | ||
NetworkRegistry.INSTANCE.registerGuiHandler(this,new GuiHandler()); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void doClientStuff(final ModelRegistryEvent event) { | ||
ClientRegistry.bindTileEntitySpecialRenderer(CraftingStationTile.class, new CraftingStationTileSpecialRenderer()); | ||
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(Objects.crafting_station),0,new ModelResourceLocation(Item.getItemFromBlock(Objects.crafting_station).getRegistryName(), "inventory")); | ||
} | ||
|
||
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD | ||
// Event bus for receiving Registry Events) | ||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) | ||
@Mod.EventBusSubscriber | ||
public static class RegistryEvents { | ||
@SubscribeEvent | ||
public static void block(final RegistryEvent.Register<Block> event) { | ||
// register a new block here | ||
event.getRegistry().register(new CraftingStationBlock(Block.Properties | ||
.create(Material.WOOD) | ||
.hardnessAndResistance(2,2)).setRegistryName("crafting_station")); | ||
event.getRegistry().register(new CraftingStationBlock(Material.WOOD).setRegistryName("crafting_station")); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void item(final RegistryEvent.Register<Item> event) { | ||
// register a new block here | ||
event.getRegistry().register(new BlockItem(Objects.crafting_station, new Item.Properties() | ||
.group(ItemGroup.DECORATIONS)).setRegistryName("crafting_station")); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void container(final RegistryEvent.Register<ContainerType<?>> event){ | ||
event.getRegistry().register(IForgeContainerType.create((windowId, inv, data) -> | ||
new CraftingStationContainer(windowId, inv, inv.player.world, data.readBlockPos(), inv.player)).setRegistryName("crafting_station_container")); | ||
|
||
} | ||
|
||
@SubscribeEvent | ||
public static void tile(final RegistryEvent.Register<TileEntityType<?>> event){ | ||
event.getRegistry().register(TileEntityType.Builder.create(CraftingStationTile::new, Objects.crafting_station).build(null).setRegistryName("crafting_station_tile")); | ||
event.getRegistry().register(new ItemBlock(Objects.crafting_station).setRegistryName(Objects.crafting_station.getRegistryName()).setCreativeTab(CreativeTabs.DECORATIONS)); | ||
GameRegistry.registerTileEntity(CraftingStationTile.class, new ResourceLocation(MODID, "crafting_station_tile")); | ||
} | ||
} | ||
@ObjectHolder(MODID) | ||
|
||
@GameRegistry.ObjectHolder(MODID) | ||
public static class Objects { | ||
public static final Block crafting_station = null; | ||
public static final ContainerType<CraftingStationContainer> crafting_station_container = null; | ||
public static final ContainerType<SideContainerInventory> side_container = null; | ||
public static final TileEntityType<CraftingStationTile> crafting_station_tile = null; | ||
} | ||
} |
Oops, something went wrong.