Files
Chisel/src/main/java/info/jbcs/minecraft/chisel/Chisel.java
T

243 lines
10 KiB
Java
Raw Normal View History

package info.jbcs.minecraft.chisel;
2014-10-27 16:26:14 -04:00
import info.jbcs.minecraft.chisel.block.BlockAutoChisel;
import info.jbcs.minecraft.chisel.block.BlockCarvable;
2014-10-27 16:26:14 -04:00
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityAutoChisel;
import info.jbcs.minecraft.chisel.client.gui.GuiAutoChisel;
import info.jbcs.minecraft.chisel.client.gui.GuiChisel;
import info.jbcs.minecraft.chisel.entity.EntityBallOMoss;
import info.jbcs.minecraft.chisel.entity.EntityCloudInABottle;
import info.jbcs.minecraft.chisel.entity.EntitySmashingRock;
2014-10-27 16:26:14 -04:00
import info.jbcs.minecraft.chisel.inventory.ContainerAutoChisel;
import info.jbcs.minecraft.chisel.inventory.ContainerChisel;
import info.jbcs.minecraft.chisel.inventory.InventoryChiselSelection;
import info.jbcs.minecraft.chisel.item.ItemBallOMoss;
import info.jbcs.minecraft.chisel.item.ItemChisel;
import info.jbcs.minecraft.chisel.item.ItemCloudInABottle;
import info.jbcs.minecraft.chisel.item.ItemSmashingRock;
import info.jbcs.minecraft.chisel.world.GeneratorLimestone;
import info.jbcs.minecraft.chisel.world.GeneratorMarble;
2014-09-06 11:46:36 +01:00
import info.jbcs.minecraft.utilities.General;
2014-10-27 16:26:14 -04:00
import java.io.File;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
2014-10-27 16:26:14 -04:00
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
2014-10-27 16:26:14 -04:00
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.Type;
2014-08-08 09:06:15 -04:00
@Mod(modid = Chisel.MOD_ID, name = Chisel.MOD_NAME, version = "@MOD_VERSION@", guiFactory = "info.jbcs.minecraft.chisel.client.gui.GuiFactory"/*, dependencies = "after:ForgeMicroblock;"*/)
public class Chisel
{
2014-07-26 09:17:49 +01:00
public static final String MOD_ID = "chisel";
public static final String MOD_NAME = "Chisel";
public static ItemChisel chisel;
2014-05-23 22:44:19 +01:00
// public static ItemChisel needle;
public static ItemCloudInABottle itemCloudInABottle;
public static ItemBallOMoss itemBallOMoss;
public static ItemSmashingRock smashingRock;
public static CreativeTabs tabChisel;
2014-06-09 21:32:33 +01:00
public static boolean multipartLoaded = false;
public static final BlockCarvable.SoundType soundHolystoneFootstep = new BlockCarvable.SoundType("holystone", 1.0f, 1.0f);
public static final BlockCarvable.SoundType soundTempleFootstep = new BlockCarvable.SoundType("dig.stone", MOD_ID+":step.templeblock", 1.0f, 1.0f);
public static final BlockCarvable.SoundType soundMetalFootstep = new BlockCarvable.SoundType("metal", 1.0f, 1.0f);
2014-10-27 16:26:14 -04:00
public static Block autoChisel;
public static int RenderEldritchId;
public static int RenderCTMId;
public static int RenderCarpetId;
2014-08-08 09:06:15 -04:00
@Instance(MOD_ID)
public static Chisel instance;
@SidedProxy(clientSide = "info.jbcs.minecraft.chisel.ClientProxy", serverSide = "info.jbcs.minecraft.chisel.CommonProxy")
public static CommonProxy proxy;
@EventHandler
public void missingMapping(FMLMissingMappingsEvent event)
{
2014-10-07 22:07:46 +02:00
BlockNameConversion.init();
for(MissingMapping m : event.get())
{
// This bug was introduced along with Chisel 1.5.2, and was fixed in 1.5.3.
// Ice Stairs were called null.0-7 instead of other names, and Marble/Limestone stairs did not exist.
// This fixes the bug.
if(m.name.startsWith("null.") && m.name.length() == 6 && m.type == Type.BLOCK)
{
2014-06-23 20:19:11 -07:00
m.warn();//(Action.WARN);
}
2014-09-06 11:46:36 +01:00
// Fix mapping of snakestoneSand, snakestoneStone, limestoneStairs, marbleStairs when loading an old (1.5.4) save
2014-09-15 11:27:15 +01:00
else if(m.type == Type.BLOCK)
2014-09-06 11:46:36 +01:00
{
2014-10-07 22:07:46 +02:00
final Block block = BlockNameConversion.findBlock(m.name);
2014-09-06 11:46:36 +01:00
2014-09-15 11:27:15 +01:00
if(block != null)
2014-09-06 11:46:36 +01:00
{
m.remap(block);
FMLLog.getLogger().info("Remapping block " + m.name + " to " + General.getName(block));
2014-09-15 11:27:15 +01:00
} else
2014-09-06 11:46:36 +01:00
FMLLog.getLogger().warn("Block " + m.name + " could not get remapped.");
2014-09-15 11:27:15 +01:00
} else if(m.type == Type.ITEM)
2014-09-06 11:46:36 +01:00
{
2014-10-07 22:07:46 +02:00
final Item item = BlockNameConversion.findItem(m.name);
2014-09-06 11:46:36 +01:00
2014-09-15 11:27:15 +01:00
if(item != null)
2014-09-06 11:46:36 +01:00
{
m.remap(item);
FMLLog.getLogger().info("Remapping item " + m.name + " to " + General.getName(item));
2014-09-15 11:27:15 +01:00
} else
2014-09-06 11:46:36 +01:00
FMLLog.getLogger().warn("Item " + m.name + " could not get remapped.");
}
}
}
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
File configFile = event.getSuggestedConfigurationFile();
2014-07-17 22:05:29 +01:00
Configurations.configExists = configFile.exists();
Configurations.config = new Configuration(configFile);
Configurations.config.load();
Configurations.refreshConfig();
2014-04-23 15:09:02 +01:00
tabChisel = new CreativeTabs("tabChisel")
{
@Override
public Item getTabIconItem()
{
return chisel;
}
};
2014-10-27 16:26:14 -04:00
chisel = (ItemChisel) new ItemChisel().setTextureName("chisel:chisel").setCreativeTab(CreativeTabs.tabTools);
GameRegistry.registerItem(chisel, "chisel");
2014-10-27 16:26:14 -04:00
if(Configurations.featureEnabled("autoChisel")){
autoChisel = new BlockAutoChisel().setBlockTextureName("Chisel:autoChisel").setCreativeTab(CreativeTabs.tabTools);
GameRegistry.registerBlock(autoChisel, autoChisel.getUnlocalizedName());
proxy.registerTileEntities();
}
2014-07-26 09:17:49 +01:00
if(Configurations.featureEnabled("cloud"))
{
itemCloudInABottle = (ItemCloudInABottle) new ItemCloudInABottle().setTextureName("Chisel:cloudinabottle").setCreativeTab(CreativeTabs.tabTools);
EntityRegistry.registerModEntity(EntityCloudInABottle.class, "CloudInABottle", 1, this, 40, 1, true);
GameRegistry.registerItem(itemCloudInABottle, "cloudinabottle");
}
2014-07-26 09:17:49 +01:00
if(Configurations.featureEnabled("ballOfMoss"))
{
itemBallOMoss = (ItemBallOMoss) new ItemBallOMoss().setTextureName("Chisel:ballomoss").setCreativeTab(CreativeTabs.tabTools);
EntityRegistry.registerModEntity(EntityBallOMoss.class, "BallOMoss", 2, this, 40, 1, true);
GameRegistry.registerItem(itemBallOMoss, "ballomoss");
}
2014-07-26 09:17:49 +01:00
if(Configurations.featureEnabled("smashingRock"))
{
smashingRock = (ItemSmashingRock) new ItemSmashingRock().setTextureName("Chisel:smashingrock").setCreativeTab(CreativeTabs.tabTools);
EntityRegistry.registerModEntity(EntitySmashingRock.class, "SmashingRock", 2, this, 40, 1, true);
GameRegistry.registerItem(smashingRock, "smashingrock");
}
ChiselBlocks.load();
proxy.preInit();
}
@EventHandler
public void init(FMLInitializationEvent event)
{
Crafting.init();
NetworkRegistry.INSTANCE.registerGuiHandler(this, new IGuiHandler()
{
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
2014-10-27 16:26:14 -04:00
switch (ID){
case 0:
return new ContainerChisel(player.inventory, new InventoryChiselSelection(null));
case 1:
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityAutoChisel)
return new ContainerAutoChisel(player.inventory, (TileEntityAutoChisel) tileentity);
default:
return null;
}
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
2014-10-27 16:26:14 -04:00
switch (ID){
case 0:
return new GuiChisel(player.inventory, new InventoryChiselSelection(null));
case 1:
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityAutoChisel)
return new GuiAutoChisel(player.inventory, (TileEntityAutoChisel) tileentity);
default:
return null;
}
}
});
GameRegistry.registerWorldGenerator(new GeneratorMarble(ChiselBlocks.blockMarble, 32, Configurations.marbleAmount), 1000);
GameRegistry.registerWorldGenerator(new GeneratorLimestone(ChiselBlocks.blockLimestone, 32, Configurations.limestoneAmount), 1000);
proxy.init();
MinecraftForge.EVENT_BUS.register(this);
2014-09-15 11:14:40 +01:00
MinecraftForge.EVENT_BUS.register(new ChiselLeftClick());
FMLCommonHandler.instance().bus().register(instance);
2014-08-08 09:06:15 -04:00
FMLInterModComms.sendMessage("Waila", "register", "info.jbcs.minecraft.chisel.Waila.register");
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
2014-08-13 16:58:37 +01:00
Compatibility.init(event);
}
2014-07-17 22:05:29 +01:00
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event)
{
if(event.modID.equals("chisel"))
{
2014-07-17 22:05:29 +01:00
Configurations.refreshConfig();
}
}
}