2014-12-15 00:11:48 +00:00
|
|
|
package com.cricketcraft.chisel;
|
2014-12-14 20:05:39 +00:00
|
|
|
|
2014-12-15 00:11:48 +00:00
|
|
|
import com.cricketcraft.chisel.block.BlockCarvable;
|
|
|
|
|
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
|
|
|
|
|
import com.cricketcraft.chisel.block.tileentity.TileEntityPresent;
|
2015-01-06 20:29:22 -05:00
|
|
|
import com.cricketcraft.chisel.carving.Carving;
|
|
|
|
|
import com.cricketcraft.chisel.carving.CarvingVariation;
|
2014-12-15 00:11:48 +00:00
|
|
|
import com.cricketcraft.chisel.client.gui.GuiAutoChisel;
|
|
|
|
|
import com.cricketcraft.chisel.client.gui.GuiChisel;
|
|
|
|
|
import com.cricketcraft.chisel.client.gui.GuiPresent;
|
|
|
|
|
import com.cricketcraft.chisel.compat.Compatibility;
|
|
|
|
|
import com.cricketcraft.chisel.compat.FMPIntegration;
|
|
|
|
|
import com.cricketcraft.chisel.compat.ModIntegration;
|
|
|
|
|
import com.cricketcraft.chisel.init.ModBlocks;
|
|
|
|
|
import com.cricketcraft.chisel.init.ModItems;
|
|
|
|
|
import com.cricketcraft.chisel.init.ModTabs;
|
|
|
|
|
import com.cricketcraft.chisel.inventory.ContainerAutoChisel;
|
|
|
|
|
import com.cricketcraft.chisel.inventory.ContainerChisel;
|
|
|
|
|
import com.cricketcraft.chisel.inventory.ContainerPresent;
|
|
|
|
|
import com.cricketcraft.chisel.inventory.InventoryChiselSelection;
|
|
|
|
|
import com.cricketcraft.chisel.proxy.CommonProxy;
|
|
|
|
|
import com.cricketcraft.chisel.utils.General;
|
2015-01-06 20:29:22 -05:00
|
|
|
import com.cricketcraft.chisel.utils.GeneralClient;
|
2015-01-05 19:15:35 -05:00
|
|
|
import com.cricketcraft.chisel.world.GeneratorChisel;
|
2014-12-14 20:05:39 +00: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;
|
2014-12-23 20:16:31 -05:00
|
|
|
import cpw.mods.fml.common.event.*;
|
2014-12-14 20:05:39 +00:00
|
|
|
import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping;
|
|
|
|
|
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.GameRegistry;
|
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry.Type;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-12-23 20:16:31 -05:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.Item;
|
2015-01-06 20:29:22 -05:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-12-23 20:16:31 -05:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
import net.minecraftforge.common.config.Configuration;
|
2015-01-06 20:29:22 -05:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
2014-12-23 20:16:31 -05:00
|
|
|
|
|
|
|
|
import java.io.File;
|
2015-01-02 18:52:53 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2014-04-21 19:13:15 +01:00
|
|
|
|
|
|
|
|
|
2014-12-24 12:16:19 -05:00
|
|
|
@Mod(modid = Chisel.MOD_ID, name = Chisel.MOD_NAME, version = Chisel.VERSION, guiFactory = "com.cricketcraft.chisel.client.gui.GuiFactory", dependencies = "after:ForgeMultipart;after:Thaumcraft")
|
2014-04-21 19:13:15 +01:00
|
|
|
public class Chisel
|
|
|
|
|
{
|
2015-01-02 18:52:53 -05:00
|
|
|
public static final List<String> modsSupported = new ArrayList<String>();
|
2014-07-26 09:17:49 +01:00
|
|
|
public static final String MOD_ID = "chisel";
|
2014-11-27 13:07:59 -05:00
|
|
|
public static final BlockCarvable.SoundType soundTempleFootstep = new BlockCarvable.SoundType("dig.stone", MOD_ID + ":step.templeblock", 1.0f, 1.0f);
|
2014-11-02 16:53:36 -05:00
|
|
|
public static final String MOD_NAME = "Chisel 2";
|
2014-12-27 14:58:08 +01:00
|
|
|
public static final String VERSION = "2.2.1";
|
2014-09-15 03:52:47 +02:00
|
|
|
public static final BlockCarvable.SoundType soundHolystoneFootstep = new BlockCarvable.SoundType("holystone", 1.0f, 1.0f);
|
|
|
|
|
public static final BlockCarvable.SoundType soundMetalFootstep = new BlockCarvable.SoundType("metal", 1.0f, 1.0f);
|
2014-11-27 13:07:59 -05:00
|
|
|
public static boolean multipartLoaded = false;
|
2014-04-21 19:13:15 +01:00
|
|
|
public static int RenderEldritchId;
|
|
|
|
|
public static int RenderCTMId;
|
|
|
|
|
public static int RenderCarpetId;
|
|
|
|
|
|
2014-08-08 09:06:15 -04:00
|
|
|
@Instance(MOD_ID)
|
2014-04-21 19:13:15 +01:00
|
|
|
public static Chisel instance;
|
|
|
|
|
|
2014-12-15 00:11:48 +00:00
|
|
|
@SidedProxy(clientSide = "com.cricketcraft.chisel.proxy.ClientProxy", serverSide = "com.cricketcraft.chisel.proxy.CommonProxy")
|
2014-04-21 19:13:15 +01:00
|
|
|
public static CommonProxy proxy;
|
|
|
|
|
|
2014-11-27 13:07:59 -05:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
private static void initModIntegration() {
|
2014-12-02 21:00:52 -05:00
|
|
|
if(Configurations.enableFMP) {
|
|
|
|
|
ModIntegration.addMod(FMPIntegration.class);
|
|
|
|
|
}
|
2014-11-27 13:07:59 -05:00
|
|
|
|
|
|
|
|
ModIntegration.init();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
@EventHandler
|
2014-11-27 13:07:59 -05:00
|
|
|
public void missingMapping(FMLMissingMappingsEvent event) {
|
2014-10-07 22:07:46 +02:00
|
|
|
BlockNameConversion.init();
|
|
|
|
|
|
2014-11-27 13:07:59 -05:00
|
|
|
for (MissingMapping m : event.get()) {
|
2014-04-21 19:13:15 +01:00
|
|
|
// 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.
|
2014-11-27 13:07:59 -05:00
|
|
|
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-04-21 19:13:15 +01:00
|
|
|
}
|
2014-09-06 11:46:36 +01:00
|
|
|
|
|
|
|
|
// Fix mapping of snakestoneSand, snakestoneStone, limestoneStairs, marbleStairs when loading an old (1.5.4) save
|
2014-11-27 13:07:59 -05:00
|
|
|
else if (m.type == Type.BLOCK) {
|
2014-10-07 22:07:46 +02:00
|
|
|
final Block block = BlockNameConversion.findBlock(m.name);
|
2014-09-06 11:46:36 +01:00
|
|
|
|
2014-11-27 13:07:59 -05: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-11-27 13:07:59 -05:00
|
|
|
} else if (m.type == Type.ITEM) {
|
2014-10-07 22:07:46 +02:00
|
|
|
final Item item = BlockNameConversion.findItem(m.name);
|
2014-09-06 11:46:36 +01:00
|
|
|
|
2014-11-27 13:07:59 -05: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.");
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
2014-11-27 13:07:59 -05:00
|
|
|
public void preInit(FMLPreInitializationEvent event) {
|
2015-01-02 18:52:53 -05:00
|
|
|
modsSupported.add("Thaumcraft");
|
|
|
|
|
modsSupported.add("Twilight Forest");
|
|
|
|
|
modsSupported.add("appliedenergistics2");
|
|
|
|
|
modsSupported.add("Railcraft");
|
2015-01-02 21:22:46 -05:00
|
|
|
modsSupported.add("AWWayOfTime");
|
2015-01-02 18:52:53 -05:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
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-21 19:13:15 +01:00
|
|
|
|
2014-10-28 21:10:08 -04:00
|
|
|
ModTabs.load();
|
2014-12-24 12:16:19 -05:00
|
|
|
ModBlocks.load();
|
2014-10-31 19:47:22 -04:00
|
|
|
ModItems.load();
|
2014-04-21 19:13:15 +01:00
|
|
|
proxy.preInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void init(FMLInitializationEvent event)
|
|
|
|
|
{
|
|
|
|
|
Crafting.init();
|
|
|
|
|
|
2014-11-27 13:07:59 -05:00
|
|
|
NetworkRegistry.INSTANCE.registerGuiHandler(this, new IGuiHandler() {
|
2014-04-21 19:13:15 +01:00
|
|
|
@Override
|
2014-11-27 13:07:59 -05:00
|
|
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
|
|
|
switch (ID) {
|
2014-10-27 16:26:14 -04:00
|
|
|
case 0:
|
|
|
|
|
return new ContainerChisel(player.inventory, new InventoryChiselSelection(null));
|
|
|
|
|
case 1:
|
2014-11-27 13:07:59 -05:00
|
|
|
TileEntity tileentity = world.getTileEntity(x, y, z);
|
|
|
|
|
if (tileentity instanceof TileEntityAutoChisel)
|
|
|
|
|
return new ContainerAutoChisel(player.inventory, (TileEntityAutoChisel) tileentity);
|
|
|
|
|
case 2:
|
|
|
|
|
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
|
|
|
if (tileEntity instanceof TileEntityPresent)
|
|
|
|
|
return new ContainerPresent(player.inventory, (TileEntityPresent) tileEntity);
|
2014-10-27 16:26:14 -04:00
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-27 13:07:59 -05:00
|
|
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
|
|
|
switch (ID) {
|
2014-10-27 16:26:14 -04:00
|
|
|
case 0:
|
|
|
|
|
return new GuiChisel(player.inventory, new InventoryChiselSelection(null));
|
|
|
|
|
case 1:
|
2014-11-27 13:07:59 -05:00
|
|
|
TileEntity tileentity = world.getTileEntity(x, y, z);
|
|
|
|
|
if (tileentity instanceof TileEntityAutoChisel)
|
|
|
|
|
return new GuiAutoChisel(player.inventory, (TileEntityAutoChisel) tileentity);
|
|
|
|
|
case 2:
|
|
|
|
|
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
|
|
|
if (tileEntity instanceof TileEntityPresent)
|
|
|
|
|
return new GuiPresent(player.inventory, (TileEntityPresent) tileEntity);
|
2014-10-27 16:26:14 -04:00
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2015-01-05 18:17:57 -05:00
|
|
|
GameRegistry.registerWorldGenerator(new GeneratorChisel(ModBlocks.marble, 32, Configurations.marbleAmount), 1000);
|
|
|
|
|
GameRegistry.registerWorldGenerator(new GeneratorChisel(ModBlocks.limestone, 32, Configurations.limestoneAmount), 1000);
|
|
|
|
|
GameRegistry.registerWorldGenerator(new GeneratorChisel(ModBlocks.andesite, 32, Configurations.andesiteAmount), 1000);
|
|
|
|
|
GameRegistry.registerWorldGenerator(new GeneratorChisel(ModBlocks.granite, 32, Configurations.graniteAmount), 1000);
|
|
|
|
|
GameRegistry.registerWorldGenerator(new GeneratorChisel(ModBlocks.diorite, 32, Configurations.dioriteAmount), 1000);
|
2014-10-28 21:10:08 -04:00
|
|
|
|
2014-11-27 13:07:59 -05:00
|
|
|
if (event.getSide() == Side.CLIENT) {
|
2014-11-02 17:05:14 -05:00
|
|
|
initModIntegration();
|
2014-11-02 16:57:53 -05:00
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
|
|
|
|
|
proxy.init();
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
2014-06-27 18:07:23 -07:00
|
|
|
FMLCommonHandler.instance().bus().register(instance);
|
2014-08-08 09:06:15 -04:00
|
|
|
|
2014-12-15 00:11:48 +00:00
|
|
|
FMLInterModComms.sendMessage("Waila", "register", "com.cricketcraft.chisel.Waila.register");
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void postInit(FMLPostInitializationEvent event)
|
|
|
|
|
{
|
2015-01-01 00:24:37 +00:00
|
|
|
ModBlocks.postLoad();
|
2014-10-28 21:10:08 -04:00
|
|
|
ModIntegration.postInit();
|
2014-08-13 16:58:37 +01:00
|
|
|
Compatibility.init(event);
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|
2014-06-27 18:07:23 -07:00
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2014-11-27 13:07:59 -05:00
|
|
|
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
|
|
|
|
|
if (event.modID.equals("chisel")) {
|
2014-07-17 22:05:29 +01:00
|
|
|
Configurations.refreshConfig();
|
2014-06-27 18:07:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-01-06 20:29:22 -05:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onLeftClickBlock(PlayerInteractEvent event)
|
|
|
|
|
{
|
|
|
|
|
ItemStack held = event.entityPlayer.getCurrentEquippedItem();
|
|
|
|
|
int slot = event.entityPlayer.inventory.currentItem;
|
|
|
|
|
Carving carving = new Carving();
|
|
|
|
|
|
|
|
|
|
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK && held != null && held.getItem().equals(Configurations.featureEnabled("diamondChisel") ? ModItems.diamondChisel : ModItems.chisel))
|
|
|
|
|
{
|
|
|
|
|
int x = event.x, y = event.y, z = event.z;
|
|
|
|
|
Block block = event.world.getBlock(x, y, z);
|
|
|
|
|
int metadata = event.world.getBlockMetadata(x, y, z);
|
|
|
|
|
CarvingVariation[] variations = carving.getVariations(block, metadata);
|
|
|
|
|
|
|
|
|
|
if (variations != null)
|
|
|
|
|
{
|
|
|
|
|
ItemStack target = new ItemStack(block, metadata);
|
|
|
|
|
|
|
|
|
|
if (target != null)
|
|
|
|
|
{
|
|
|
|
|
for (CarvingVariation v : variations)
|
|
|
|
|
{
|
|
|
|
|
if (v.block == Block.getBlockFromItem(target.getItem()) && v.meta == target.getItemDamage())
|
|
|
|
|
{
|
|
|
|
|
event.world.setBlock(x, y, z, v.block);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < variations.length; i++)
|
|
|
|
|
{
|
|
|
|
|
CarvingVariation v = variations[i];
|
|
|
|
|
if (v.block == block && v.meta == metadata)
|
|
|
|
|
{
|
|
|
|
|
variations = ArrayUtils.remove(variations, i--);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-31 13:37:01 +02:00
|
|
|
|
2015-01-06 20:29:22 -05:00
|
|
|
int index = event.world.rand.nextInt(variations.length);
|
|
|
|
|
CarvingVariation newVar = variations[index];
|
|
|
|
|
event.world.setBlock(x, y, z, newVar.block);
|
|
|
|
|
GeneralClient.playChiselSound(event.world, x, y, z, MOD_ID + ":chisel.fallback");
|
|
|
|
|
event.entityPlayer.inventory.currentItem = slot;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|