Cleanup and restructure of machine block
This commit is contained in:
parent
8538476bc9
commit
6365e06b08
8 changed files with 190 additions and 58 deletions
|
@ -9,6 +9,7 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
|
@ -21,12 +22,13 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|||
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import dark.core.hydraulic.helpers.FluidRestrictionHandler;
|
||||
import dark.library.machine.BlockMulti;
|
||||
import dark.library.saving.SaveManager;
|
||||
|
||||
/** @author HangCow, DarkGuardsman */
|
||||
@Mod(modid = DarkMain.MOD_ID, name = DarkMain.MOD_NAME, version = DarkMain.VERSION, useMetadata = true)
|
||||
@NetworkMod(channels = { DarkMain.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
|
||||
public class DarkMain
|
||||
public class DarkMain extends ModPrefab
|
||||
{
|
||||
// @Mod Prerequisites
|
||||
public static final String MAJOR_VERSION = "@MAJOR@";
|
||||
|
@ -47,62 +49,85 @@ public class DarkMain
|
|||
@Metadata(DarkMain.MOD_ID)
|
||||
public static ModMetadata meta;
|
||||
|
||||
/* RESOURCE FILE PATHS */
|
||||
public static final String DOMAIN = "dark";
|
||||
public static final String PREFIX = DOMAIN + ":";
|
||||
|
||||
public static final String DIRECTORY_NO_SLASH = "assets/" + DOMAIN + "/";
|
||||
public static final String DIRECTORY = "/" + DIRECTORY_NO_SLASH;
|
||||
public static final String LANGUAGE_PATH = DIRECTORY + "languages/";
|
||||
public static final String SOUND_PATH = DIRECTORY + "audio/";
|
||||
|
||||
public static final String TEXTURE_DIRECTORY = "textures/";
|
||||
public static final String BLOCK_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
|
||||
public static final String ITEM_DIRECTORY = TEXTURE_DIRECTORY + "items/";
|
||||
public static final String MODEL_DIRECTORY = TEXTURE_DIRECTORY + "models/";
|
||||
public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/";
|
||||
|
||||
/** Main config file */
|
||||
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "Dark/General.cfg"));
|
||||
/** Can over pressure of devices do area damage */
|
||||
public static boolean overPressureDamage;
|
||||
/** Main mod output to console */
|
||||
public static final Logger LOGGER = Logger.getLogger("DarkCore");
|
||||
|
||||
public static BlockMulti blockMulti;
|
||||
|
||||
public static DarkMain instance;
|
||||
|
||||
public DarkMain()
|
||||
{
|
||||
super("dark");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
LOGGER.setParent(FMLLog.getLogger());
|
||||
LOGGER.info("Initializing...");
|
||||
|
||||
instance = this;
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new FluidRestrictionHandler());
|
||||
|
||||
this.loadConfig();
|
||||
proxy.preInit();
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void generalLoad(FMLInitializationEvent event)
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
proxy.init();
|
||||
|
||||
/* MCMOD.INFO FILE BUILDER? */
|
||||
meta.modId = DarkMain.MOD_ID;
|
||||
meta.name = DarkMain.MOD_NAME;
|
||||
meta.description = "Main mod for several of the mods created by DarkGuardsman and his team. Doesn't add much of anything by itself but is needed for several mods to function correctly";
|
||||
meta.url = "www.BuiltBroken.com";
|
||||
|
||||
meta.logoFile = DarkMain.TEXTURE_DIRECTORY + "GP_Banner.png";
|
||||
meta.version = DarkMain.VERSION;
|
||||
meta.authorList = Arrays.asList(new String[] { "DarkGuardsman", "HangCow" });
|
||||
meta.credits = "Please see the website.";
|
||||
meta.autogenerated = false;
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postLoad(FMLPostInitializationEvent event)
|
||||
@Override
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
proxy.postInit();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig()
|
||||
{
|
||||
/* CONFIGS */
|
||||
CONFIGURATION.load();
|
||||
DarkMain.blockMulti = new BlockMulti(DarkMain.CONFIGURATION.getBlock("RestrictedPipes", BLOCK_ID_PREFIX++).getInt());
|
||||
if (CONFIGURATION.hasChanged())
|
||||
{
|
||||
CONFIGURATION.save();
|
||||
}
|
||||
/* CONFIG END */
|
||||
|
||||
proxy.preInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadModMeta()
|
||||
{
|
||||
/* MCMOD.INFO FILE BUILDER? */
|
||||
meta.modId = MOD_ID;
|
||||
meta.name = MOD_NAME;
|
||||
meta.description = "Main mod for several of the mods created by DarkGuardsman and his team. Doesn't add much of anything by itself but is needed for several mods to function correctly";
|
||||
meta.url = "www.BuiltBroken.com";
|
||||
|
||||
meta.logoFile = TEXTURE_DIRECTORY + "GP_Banner.png";
|
||||
meta.version = VERSION;
|
||||
meta.authorList = Arrays.asList(new String[] { "DarkGuardsman", "HangCow" });
|
||||
meta.credits = "Please see the website.";
|
||||
meta.autogenerated = false;
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldSave(WorldEvent.Save event)
|
||||
{
|
||||
|
|
57
src/minecraft/dark/core/ModPrefab.java
Normal file
57
src/minecraft/dark/core/ModPrefab.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package dark.core;
|
||||
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
public abstract class ModPrefab
|
||||
{
|
||||
|
||||
|
||||
public String DOMAIN = "dark";
|
||||
public String PREFIX = DOMAIN + ":";
|
||||
|
||||
public String DIRECTORY_NO_SLASH = "assets/" + DOMAIN + "/";
|
||||
public String DIRECTORY = "/" + DIRECTORY_NO_SLASH;
|
||||
public String LANGUAGE_PATH = DIRECTORY + "languages/";
|
||||
public String SOUND_PATH = DIRECTORY + "audio/";
|
||||
|
||||
public static final String TEXTURE_DIRECTORY = "textures/";
|
||||
public static final String BLOCK_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
|
||||
public static final String ITEM_DIRECTORY = TEXTURE_DIRECTORY + "items/";
|
||||
public static final String MODEL_DIRECTORY = TEXTURE_DIRECTORY + "models/";
|
||||
public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/";
|
||||
|
||||
/* START IDS */
|
||||
public static int BLOCK_ID_PREFIX = 3100;
|
||||
public static int ITEM_ID_PREFIX = 13200;
|
||||
|
||||
public ModPrefab(String domain)
|
||||
{
|
||||
DOMAIN = domain;
|
||||
this.loadModMeta();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
this.loadConfig();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public abstract void loadConfig();
|
||||
|
||||
public abstract void loadModMeta();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dark.core;
|
||||
package dark.core.api;
|
||||
|
||||
/** This class should be applied to all tile entities (mainly machines) that can be disabled (by
|
||||
* things like EMP, short circuit etc.).
|
|
@ -1,4 +1,4 @@
|
|||
package dark.core;
|
||||
package dark.core.api;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
|
@ -3,7 +3,7 @@ package dark.library.machine;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import buildcraft.api.power.PowerProvider;
|
||||
import dark.core.PowerSystems;
|
||||
import dark.core.api.PowerSystems;
|
||||
|
||||
public class BcToUeProvider extends PowerProvider
|
||||
{
|
||||
|
|
|
@ -2,50 +2,100 @@ package dark.library.machine;
|
|||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import universalelectricity.prefab.block.BlockAdvanced;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import dark.core.DarkMain;
|
||||
import dark.core.api.INetworkPart;
|
||||
|
||||
public class BlockMachine extends BlockAdvanced implements ITileEntityProvider
|
||||
/** Basic TileEntity Container class designed to be used by generic machines. It is suggested that
|
||||
* each mod using this create there own basic block extending this to reduce need to input config
|
||||
* file each time
|
||||
*
|
||||
* @author Rseifert */
|
||||
public abstract class BlockMachine extends BlockAdvanced implements ITileEntityProvider
|
||||
{
|
||||
|
||||
protected BlockMachine(int par1, Material par2Material)
|
||||
/** @param name - The name the block will use for both the config and translation file
|
||||
* @param config - configuration reference used to pull blockID from
|
||||
* @param blockID - Default block id to be used for the config
|
||||
* @param material - Block material used for tool refrence? */
|
||||
public BlockMachine(String name, Configuration config, int blockID, Material material)
|
||||
{
|
||||
super(par1, par2Material);
|
||||
super(config.getBlock(name, blockID).getInt(), material);
|
||||
this.isBlockContainer = true;
|
||||
this.setUnlocalizedName(name);
|
||||
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IconRegister iconReg)
|
||||
{
|
||||
this.blockIcon = iconReg.registerIcon(DarkMain.instance.PREFIX + "machine");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getBlockTexture(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5)
|
||||
{
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getIcon(int par1, int par2)
|
||||
{
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
/** Called whenever the block is added into the world. Args: world, x, y, z */
|
||||
public void onBlockAdded(World par1World, int par2, int par3, int par4)
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
super.onBlockAdded(par1World, par2, par3, par4);
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
if (tileEntity instanceof INetworkPart)
|
||||
{
|
||||
((INetworkPart) tileEntity).refresh();
|
||||
}
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
}
|
||||
|
||||
/** ejects contained items into the world, and notifies neighbours of an update, as appropriate */
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
this.dropEntireInventory(par1World, par2, par3, par4, par5, par6);
|
||||
par1World.removeBlockTileEntity(par2, par3, par4);
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
this.dropEntireInventory(world, x, y, z, par5, par6);
|
||||
world.removeBlockTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof INetworkPart)
|
||||
{
|
||||
((INetworkPart) tileEntity).refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when the block receives a BlockEvent - see World.addBlockEvent. By default, passes it
|
||||
* on to the tile entity at this location. Args: world, x, y, z, blockID, EventID, event
|
||||
* parameter */
|
||||
public boolean onBlockEventReceived(World par1World, int par2, int par3, int par4, int par5, int par6)
|
||||
@Override
|
||||
public boolean onBlockEventReceived(World world, int x, int y, int z, int blockID, int eventID)
|
||||
{
|
||||
super.onBlockEventReceived(par1World, par2, par3, par4, par5, par6);
|
||||
TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
return tileentity != null ? tileentity.receiveClientEvent(par5, par6) : false;
|
||||
super.onBlockEventReceived(world, x, y, z, blockID, eventID);
|
||||
TileEntity tileentity = world.getBlockTileEntity(x, y, z);
|
||||
return tileentity != null ? tileentity.receiveClientEvent(blockID, eventID) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dropEntireInventory(World par1World, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package dark.library.machine;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import dark.core.IDisableable;
|
||||
import dark.core.api.IDisableable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import dark.core.PowerSystems;
|
||||
import dark.core.api.PowerSystems;
|
||||
|
||||
public class TileEntityRunnableMachine extends TileEntityElectricMachine
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue