diff --git a/.gitmodules b/.gitmodules index 849727e7..d19bbbc2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,9 +5,6 @@ [submodule "Dark-Library"] path = Dark-Library url = git@github.com:DarkGuardsman/Dark-Library.git -[submodule "Basic-Compoents"] - path = Basic-Compoents - url = git://github.com/calclavia/Basic-Components.git [submodule "API-Bank"] path = API-Bank url = git://github.com/DarkGuardsman/API-Bank.git diff --git a/Basic-Compoents b/Basic-Compoents deleted file mode 160000 index f3030ef0..00000000 --- a/Basic-Compoents +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f3030ef09eb2f8ed6f28b4ffbf4fe8c1145ce2ea diff --git a/buildFiles/buildnumber.txt b/buildFiles/buildnumber.txt deleted file mode 100644 index 47e0b6a4..00000000 --- a/buildFiles/buildnumber.txt +++ /dev/null @@ -1 +0,0 @@ -90 diff --git a/buildFiles/info.txt b/buildFiles/info.txt deleted file mode 100644 index 7afa568c..00000000 --- a/buildFiles/info.txt +++ /dev/null @@ -1 +0,0 @@ -* 1.5.1 AssemblyLine_mc1.5.1_v0.3.0.90.jar AssemblyLine_mc1.5.1_v0.3.0.90_api.zip \ No newline at end of file diff --git a/buildFiles/mcver.txt b/buildFiles/mcver.txt deleted file mode 100644 index 8e03717d..00000000 --- a/buildFiles/mcver.txt +++ /dev/null @@ -1 +0,0 @@ -1.5.1 \ No newline at end of file diff --git a/buildFiles/obf.rgs b/buildFiles/obf.rgs deleted file mode 100644 index edb8d86b..00000000 --- a/buildFiles/obf.rgs +++ /dev/null @@ -1,9 +0,0 @@ - -# Ignore all classes -.class ** - -# Except a specific class -!class assemblyline/** - -.option Annotations -.option Trim \ No newline at end of file diff --git a/buildFiles/server.txt b/buildFiles/server.txt deleted file mode 100644 index 0697ecd4..00000000 --- a/buildFiles/server.txt +++ /dev/null @@ -1 +0,0 @@ -assemblyline-mod.com \ No newline at end of file diff --git a/buildFiles/username.txt b/buildFiles/username.txt deleted file mode 100644 index 1d191d20..00000000 --- a/buildFiles/username.txt +++ /dev/null @@ -1 +0,0 @@ -al \ No newline at end of file diff --git a/src/minecraft/assemblyline/api/IArmbot.java b/src/minecraft/assemblyline/api/IArmbot.java index bd84dd8e..1835384b 100644 --- a/src/minecraft/assemblyline/api/IArmbot.java +++ b/src/minecraft/assemblyline/api/IArmbot.java @@ -5,35 +5,22 @@ import java.util.List; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; -/** - * An interface applied to Armbots. - * - * @author Calclavia - */ +/** Should be used to interact with the armbot and not to create a new armbot */ public interface IArmbot { - /** - * Adds an entity to the Armbot's grab list. - */ + /** Adds an entity to the Armbot's grab list. */ public void grabEntity(Entity entity); public void grabItem(ItemStack itemStack); - /** - * Drops a specific entity from the Armbot's hand. - */ - public void dropEntity(Entity entity); + /** Drops the given object + * + * @param object - Entity or ItemStack + * + * String "All" should cause the armbot to drop all items */ + public void drop(Object object); - public void dropItem(ItemStack itemStack); - - /** - * Drops all entities in the Armbot's hand. - */ - public void dropAll(); - - /** - * @return Returns all entities being grabbed by the Armbot. - */ + /** @return Returns all entities being grabbed by the Armbot. */ public List getGrabbedEntities(); public List getGrabbedItems(); diff --git a/src/minecraft/assemblyline/api/IBelt.java b/src/minecraft/assemblyline/api/IBelt.java index 24ce951b..3a7c0b3a 100644 --- a/src/minecraft/assemblyline/api/IBelt.java +++ b/src/minecraft/assemblyline/api/IBelt.java @@ -4,25 +4,16 @@ import java.util.List; import net.minecraft.entity.Entity; -/** - * An interface applied to the tile entity of a conveyor belt. - * - * @author Calclavia - * - */ +/** An interface applied to the tile entity of a conveyor belt */ public interface IBelt { - /** - * Used to get a list of entities the belt exerts an effect upon. + /** Used to get a list of entities the belt exerts an effect upon. * - * @return list of entities in the belts are of effect - */ + * @return list of entities in the belts are of effect */ public List getAffectedEntities(); - - /** - * Adds and entity to the ignore list so its not moved - * has to be done every 20 ticks - * @param entity - */ - public void IgnoreEntity(Entity entity); + + /** Adds and entity to the ignore list so its not moved has to be done every 20 ticks + * + * @param entity */ + public void ignoreEntity(Entity entity); } diff --git a/src/minecraft/assemblyline/api/IBotArm.java b/src/minecraft/assemblyline/api/IBotArm.java deleted file mode 100644 index 129eff99..00000000 --- a/src/minecraft/assemblyline/api/IBotArm.java +++ /dev/null @@ -1,8 +0,0 @@ -package assemblyline.api; - -public interface IBotArm -{ - // TODO will add methods here to change the - // arms task, target, location,etc as need by - // other mods -} diff --git a/src/minecraft/assemblyline/client/ClientProxy.java b/src/minecraft/assemblyline/client/ClientProxy.java index d7a84f78..73acc12b 100644 --- a/src/minecraft/assemblyline/client/ClientProxy.java +++ b/src/minecraft/assemblyline/client/ClientProxy.java @@ -21,8 +21,8 @@ import assemblyline.client.render.RenderManipulator; import assemblyline.client.render.RenderRejector; import assemblyline.common.CommonProxy; import assemblyline.common.armbot.TileEntityArmbot; -import assemblyline.common.block.TileEntityCrate; import assemblyline.common.imprinter.TileEntityImprinter; +import assemblyline.common.machine.TileEntityCrate; import assemblyline.common.machine.TileEntityManipulator; import assemblyline.common.machine.TileEntityRejector; import assemblyline.common.machine.belt.TileEntityConveyorBelt; @@ -72,10 +72,13 @@ public class ClientProxy extends CommonProxy switch (ID) { case GUI_IMPRINTER: + { return new GuiImprinter(player.inventory, (TileEntityImprinter) tileEntity); + } case GUI_ENCODER: - if (tileEntity != null && tileEntity instanceof TileEntityEncoder) - return new GuiEncoder(player.inventory, (TileEntityEncoder) tileEntity); + { + return new GuiEncoder(player.inventory, (TileEntityEncoder) tileEntity); + } } } @@ -87,16 +90,14 @@ public class ClientProxy extends CommonProxy { return GuiScreen.isCtrlKeyDown(); } - - /** - * Renders a laser beam from one power to another by a set color for a set time + + /** Renders a laser beam from one power to another by a set color for a set time * * @param world - world this laser is to be rendered in * @param position - start vector3 * @param target - end vector3 * @param color - color of the beam - * @param age - life of the beam in 1/20 secs - */ + * @param age - life of the beam in 1/20 secs */ public void renderBeam(World world, Vector3 position, Vector3 target, Color color, int age) { if (world.isRemote || FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) diff --git a/src/minecraft/assemblyline/client/render/RenderCrate.java b/src/minecraft/assemblyline/client/render/RenderCrate.java index 3a237846..92baa34f 100644 --- a/src/minecraft/assemblyline/client/render/RenderCrate.java +++ b/src/minecraft/assemblyline/client/render/RenderCrate.java @@ -18,7 +18,7 @@ import net.minecraftforge.common.ForgeDirection; import org.lwjgl.opengl.GL11; import universalelectricity.core.vector.Vector3; -import assemblyline.common.block.TileEntityCrate; +import assemblyline.common.machine.TileEntityCrate; public class RenderCrate extends TileEntitySpecialRenderer { diff --git a/src/minecraft/assemblyline/common/AssemblyLine.java b/src/minecraft/assemblyline/common/AssemblyLine.java index a373c61d..8a3e89f4 100644 --- a/src/minecraft/assemblyline/common/AssemblyLine.java +++ b/src/minecraft/assemblyline/common/AssemblyLine.java @@ -1,7 +1,5 @@ package assemblyline.common; -import ic2.api.item.Items; - import java.io.File; import java.util.Arrays; import java.util.logging.Logger; @@ -10,30 +8,38 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.Configuration; -import net.minecraftforge.oredict.ShapedOreRecipe; -import net.minecraftforge.oredict.ShapelessOreRecipe; import org.modstats.ModstatInfo; import org.modstats.Modstats; import universalelectricity.prefab.TranslationHelper; import universalelectricity.prefab.multiblock.BlockMulti; +import universalelectricity.prefab.multiblock.TileEntityMulti; import universalelectricity.prefab.network.PacketManager; import assemblyline.common.armbot.BlockArmbot; -import assemblyline.common.armbot.command.GrabDictionary; -import assemblyline.common.block.BlockCrate; -import assemblyline.common.block.BlockTurntable; -import assemblyline.common.block.ItemBlockCrate; +import assemblyline.common.armbot.TileEntityArmbot; import assemblyline.common.imprinter.BlockImprinter; import assemblyline.common.imprinter.ItemImprinter; +import assemblyline.common.imprinter.TileEntityImprinter; +import assemblyline.common.machine.BlockCrate; import assemblyline.common.machine.BlockManipulator; import assemblyline.common.machine.BlockRejector; +import assemblyline.common.machine.BlockTurntable; +import assemblyline.common.machine.ItemBlockCrate; +import assemblyline.common.machine.TileEntityCrate; +import assemblyline.common.machine.TileEntityManipulator; +import assemblyline.common.machine.TileEntityRejector; import assemblyline.common.machine.belt.BlockConveyorBelt; +import assemblyline.common.machine.belt.TileEntityConveyorBelt; import assemblyline.common.machine.crane.BlockCraneController; import assemblyline.common.machine.crane.BlockCraneFrame; +import assemblyline.common.machine.crane.TileEntityCraneController; +import assemblyline.common.machine.crane.TileEntityCraneRail; import assemblyline.common.machine.detector.BlockDetector; +import assemblyline.common.machine.detector.TileEntityDetector; import assemblyline.common.machine.encoder.BlockEncoder; import assemblyline.common.machine.encoder.ItemDisk; +import assemblyline.common.machine.encoder.TileEntityEncoder; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; @@ -50,8 +56,6 @@ import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; -import dark.core.DarkMain; -import dark.core.PowerSystems; @ModstatInfo(prefix = "asmline") @Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.MOD_NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents; after:IC2", useMetadata = true) @@ -94,11 +98,11 @@ public class AssemblyLine public static final String TEXTURE_NAME_PREFIX = "assemblyline:"; - private static final String[] LANGUAGES_SUPPORTED = new String[] { "en_US","nl_NL","fr_FR" }; + private static final String[] LANGUAGES_SUPPORTED = new String[] { "en_US", "nl_NL", "fr_FR" }; public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/AssemblyLine.cfg")); - public static final int BLOCK_ID_PREFIX = 3030; + public static int BLOCK_ID_PREFIX = 3030; public static Block blockConveyorBelt; public static Block blockManipulator; @@ -123,39 +127,44 @@ public class AssemblyLine // TODO: MAKE THIS FALSE EVERY BUILD! public static final boolean DEBUG = false; public static boolean REQUIRE_NO_POWER = false; + public static boolean VINALLA_RECIPES = false; @PreInit public void preInit(FMLPreInitializationEvent event) { FMLog.setParent(FMLLog.getLogger()); - // UniversalElectricity.register(this, 1, 2, 6, false); instance = this; - + /* UPDATE NOTIFIER */ Modstats.instance().getReporter().registerMod(this); CONFIGURATION.load(); - blockConveyorBelt = new BlockConveyorBelt(CONFIGURATION.getBlock("Conveyor Belt", BLOCK_ID_PREFIX).getInt()); - blockManipulator = new BlockManipulator(CONFIGURATION.getBlock("Manipulator", BLOCK_ID_PREFIX + 1).getInt()); - blockCrate = new BlockCrate(CONFIGURATION.getBlock("Crate", BLOCK_ID_PREFIX + 3).getInt(), 0); - blockImprinter = new BlockImprinter(CONFIGURATION.getBlock("Imprinter", BLOCK_ID_PREFIX + 4).getInt(), 4); - blockDetector = new BlockDetector(CONFIGURATION.getBlock("Detector", BLOCK_ID_PREFIX + 5).getInt(), 1); - blockRejector = new BlockRejector(CONFIGURATION.getBlock("Rejector", BLOCK_ID_PREFIX + 6).getInt()); - blockEncoder = new BlockEncoder(CONFIGURATION.getBlock("Encoder", BLOCK_ID_PREFIX + 7).getInt(), 7); - blockArmbot = new BlockArmbot(CONFIGURATION.getBlock("Armbot", BLOCK_ID_PREFIX + 8).getInt()); - blockMulti = new BlockMulti(CONFIGURATION.getBlock("Multiblock", BLOCK_ID_PREFIX + 9).getInt()); - blockCraneController = new BlockCraneController(CONFIGURATION.getBlock("Crane Controller", BLOCK_ID_PREFIX + 10).getInt()); - blockCraneFrame = new BlockCraneFrame(CONFIGURATION.getBlock("Crane Frame", BLOCK_ID_PREFIX + 11).getInt()); - blockTurntable = new BlockTurntable(CONFIGURATION.getBlock("Turntable", BLOCK_ID_PREFIX + 12).getInt()); + blockConveyorBelt = new BlockConveyorBelt(BLOCK_ID_PREFIX); + blockManipulator = new BlockManipulator(BLOCK_ID_PREFIX++); + blockCrate = new BlockCrate(BLOCK_ID_PREFIX++); + blockImprinter = new BlockImprinter(BLOCK_ID_PREFIX++); + blockDetector = new BlockDetector(BLOCK_ID_PREFIX++); + blockRejector = new BlockRejector(BLOCK_ID_PREFIX++); + blockEncoder = new BlockEncoder(BLOCK_ID_PREFIX++); + blockArmbot = new BlockArmbot(BLOCK_ID_PREFIX++); + blockMulti = new BlockMulti(BLOCK_ID_PREFIX++); + blockCraneController = new BlockCraneController(BLOCK_ID_PREFIX++); + blockCraneFrame = new BlockCraneFrame(BLOCK_ID_PREFIX++); + blockTurntable = new BlockTurntable(BLOCK_ID_PREFIX++); itemImprint = new ItemImprinter(CONFIGURATION.getItem("Imprint", ITEM_ID_PREFIX).getInt()); itemDisk = new ItemDisk(CONFIGURATION.getItem("Disk", ITEM_ID_PREFIX + 1).getInt()); - REQUIRE_NO_POWER = !CONFIGURATION.get("general", "requirePower", true).getBoolean(true) || PowerSystems.runPowerLess(PowerSystems.INDUSTRIALCRAFT, PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM); - CONFIGURATION.save(); + AssemblyLine.REQUIRE_NO_POWER = !CONFIGURATION.get("general", "requirePower", true).getBoolean(true); + AssemblyLine.VINALLA_RECIPES = CONFIGURATION.get("general", "Vinalla_Recipes", false).getBoolean(false); + if (CONFIGURATION.hasChanged()) + { + CONFIGURATION.save(); + } NetworkRegistry.instance().registerGuiHandler(this, this.proxy); - GameRegistry.registerBlock(blockConveyorBelt, "Conveyor Belt"); + + GameRegistry.registerBlock(blockConveyorBelt, "ConveyorBelt"); GameRegistry.registerBlock(blockCrate, ItemBlockCrate.class, "Crate"); GameRegistry.registerBlock(blockManipulator, "Manipulator"); GameRegistry.registerBlock(blockImprinter, "Imprinter"); @@ -164,9 +173,21 @@ public class AssemblyLine GameRegistry.registerBlock(blockRejector, "Rejector"); GameRegistry.registerBlock(blockArmbot, "Armbot"); GameRegistry.registerBlock(blockTurntable, "Turntable"); - GameRegistry.registerBlock(blockCraneController, "Crane Controller"); + GameRegistry.registerBlock(blockCraneController, "CraneController"); GameRegistry.registerBlock(blockCraneFrame, "Crane Frame"); + GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, "ALConveyorBelt"); + GameRegistry.registerTileEntity(TileEntityRejector.class, "ALSorter"); + GameRegistry.registerTileEntity(TileEntityManipulator.class, "ALManipulator"); + GameRegistry.registerTileEntity(TileEntityCrate.class, "ALCrate"); + GameRegistry.registerTileEntity(TileEntityDetector.class, "ALDetector"); + GameRegistry.registerTileEntity(TileEntityEncoder.class, "ALEncoder"); + GameRegistry.registerTileEntity(TileEntityArmbot.class, "ALArmbot"); + GameRegistry.registerTileEntity(TileEntityCraneController.class, "ALCraneController"); + GameRegistry.registerTileEntity(TileEntityCraneRail.class, "ALCraneRail"); + GameRegistry.registerTileEntity(TileEntityImprinter.class, "ALImprinter"); + GameRegistry.registerTileEntity(TileEntityMulti.class, "ALMulti"); + TabAssemblyLine.itemStack = new ItemStack(AssemblyLine.blockConveyorBelt); proxy.preInit(); @@ -176,155 +197,26 @@ public class AssemblyLine public void load(FMLInitializationEvent evt) { proxy.init(); - GrabDictionary.registerList(); FMLog.info("Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " languages."); /* MCMOD.INFO FILE BUILDER? */ meta.modId = AssemblyLine.MOD_ID; meta.name = AssemblyLine.MOD_NAME; - meta.description = "A mod that brings conveyor belt transporting systems to Minecraft."; + meta.description = "Simi Realistic factory system for minecraft bring in conveyor belts, robotic arms, and simple machines"; - meta.url = "http://calclavia.com/universalelectricity/?m=18"; + meta.url = "http://universalelectricity.com/assembly-line"; meta.logoFile = "/al_logo.png"; meta.version = AssemblyLine.VERSION; - meta.authorList = Arrays.asList(new String[] { "DarkGuardsman, Briaman, Calclavia" }); + meta.authorList = Arrays.asList(new String[] { "DarkGuardsman" }); meta.credits = "Please see the website."; meta.autogenerated = false; - this.createStandardRecipes(); - this.createUERecipes(); - if (PowerSystems.isPowerSystemLoaded(PowerSystems.INDUSTRIALCRAFT, true)) - { - createIC2Recipes(); - } + Recipes.loadRecipes(); } - private void createVanillaRecipes() - { - System.out.println("No crafting ingredient source found. Creating cheap-o vanilla recipes."); - // Armbot - GameRegistry.addRecipe(new ShapedOreRecipe(blockArmbot, new Object[] { "II ", "SIS", "MCM", 'S', "ingotIron", 'C', Item.redstoneRepeater, 'I', "ingotIron", 'M', Block.pistonBase })); - // Disk - GameRegistry.addRecipe(new ShapedOreRecipe(itemDisk, new Object[] { "III", "ICI", "III", 'I', itemImprint, 'C', Item.redstoneRepeater })); - // Encoder - GameRegistry.addRecipe(new ShapedOreRecipe(blockEncoder, new Object[] { "SIS", "SCS", "SSS", 'I', itemImprint, 'S', "ingotIron", 'C', Item.redstoneRepeater })); - // Detector - GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, new Object[] { "SES", "SCS", "S S", 'S', "ingotIron", 'C', Block.torchRedstoneActive, 'E', Item.eyeOfEnder })); - // Conveyor Belt - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 10), new Object[] { "III", "WMW", 'I', "ingotIron", 'W', Block.planks, 'M', Block.pistonBase })); - // Rejector - GameRegistry.addRecipe(new ShapedOreRecipe(blockRejector, new Object[] { "WPW", "@R@", '@', "ingotIron", 'R', Item.redstone, 'P', Block.pistonBase, 'C', Block.torchRedstoneActive, 'W', Item.redstone })); - // Turntable - GameRegistry.addRecipe(new ShapedOreRecipe(blockTurntable, new Object[] { "P", "P", 'P', Block.pistonBase })); - // Manipulator - GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockManipulator, 2), new Object[] { Block.dispenser, Block.torchRedstoneActive })); - } - - private void createUERecipes() - { - DarkMain.forceLoadBCItems(this, AssemblyLine.CHANNEL); - System.out.println("BasicComponents Found...adding UE recipes for Assembly Line."); - // Armbot - GameRegistry.addRecipe(new ShapedOreRecipe(blockArmbot, new Object[] { - "II ", - "SIS", - "MCM", - 'S', "plateSteel", - 'C', "advancedCircuit", - 'I', "ingotSteel", - 'M', "motor" })); - // Disk - GameRegistry.addRecipe(new ShapedOreRecipe(itemDisk, new Object[] { - "III", - "ICI", - "III", - 'I', itemImprint, - 'C', "advancedCircuit" })); - // Encoder - GameRegistry.addRecipe(new ShapedOreRecipe(blockEncoder, new Object[] { - "SIS", - "SCS", - "SSS", - 'I', itemImprint, - 'S', "ingotSteel", - 'C', "advancedCircuit" })); - // Detector - GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, new Object[] { - "SES", - "SCS", - "S S", - 'S', "ingotSteel", - 'C', "basicCircuit", - 'E', Item.eyeOfEnder })); - // Conveyor Belt - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 10), new Object[] { - "III", - "WMW", - 'I', "ingotSteel", - 'W', Block.planks, - 'M', "motor" })); - // Rejector - GameRegistry.addRecipe(new ShapedOreRecipe(blockRejector, new Object[] { - "CPC", - "@R@", - '@', "ingotSteel", - 'R', Item.redstone, - 'P', Block.pistonBase, - 'C', "basicCircuit"})); - // Turntable - GameRegistry.addRecipe(new ShapedOreRecipe(blockTurntable, new Object[] { - "M", - "P", - 'M', "motor", - 'P', Block.pistonBase })); - // Manipulator - GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockManipulator, 2), new Object[] { Block.dispenser, "basicCircuit" })); - } - - private void createIC2Recipes() - { - try - { - System.out.println("IC2 Found...adding IC2 recipes for Assembly Line."); - // Armbot - GameRegistry.addRecipe(new ItemStack(blockArmbot, 1), "II ", "SIS", "MCM", 'S', Items.getItem("advancedAlloy"), 'C', Items.getItem("electronicCircuit"), 'I', "ingotRefinedIron", 'M', Items.getItem("generator")); - // Disk - GameRegistry.addRecipe(new ItemStack(itemDisk, 1), "III", "ICI", "III", 'I', itemImprint, 'C', Items.getItem("advancedCircuit")); - // Encoder - GameRegistry.addRecipe(new ItemStack(blockEncoder, 1), "SIS", "SCS", "SSS", 'I', itemImprint, 'S', "ingotRefinedIron", 'C', Items.getItem("advancedCircuit")); - // Detector - GameRegistry.addRecipe(new ItemStack(blockDetector, 1), "SES", "SCS", "S S", 'S', "ingotRefinedIron", 'C', Items.getItem("electronicCircuit"), 'E', Item.eyeOfEnder); - // Conveyor Belt - GameRegistry.addRecipe(new ItemStack(blockConveyorBelt, 10), "III", "WMW", 'I', "ingotRefinedIron", 'W', Block.planks, 'M', Items.getItem("generator")); - // Rejector - GameRegistry.addRecipe(new ItemStack(blockRejector, 1), "WPW", "@R@", '@', "ingotRefinedIron", 'R', Item.redstone, 'P', Block.pistonBase, 'C', Items.getItem("electronicCircuit"), 'W', Items.getItem("insulatedCopperCableItem")); - // Turntable - GameRegistry.addRecipe(new ItemStack(blockTurntable, 1), "M", "P", 'M', Items.getItem("generator"), 'P', Block.pistonBase); - // Manipulator - GameRegistry.addShapelessRecipe(new ItemStack(blockManipulator, 2), Block.dispenser, Items.getItem("electronicCircuit")); - } - catch (Exception e) - { - System.out.print("AssemblyLine: Failed to load IC2 recipes"); - e.printStackTrace(); - } - } - - private void createStandardRecipes() - { - // Imprint - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemImprint, 2), new Object[] { "R", "P", "I", 'P', Item.paper, 'R', Item.redstone, 'I', new ItemStack(Item.dyePowder, 1, 0) })); - // Imprinter - GameRegistry.addRecipe(new ShapedOreRecipe(blockImprinter, new Object[] { "SIS", "SPS", "WCW", 'S', Item.ingotIron, 'C', Block.chest, 'W', Block.workbench, 'P', Block.pistonBase, 'I', new ItemStack(Item.dyePowder, 1, 0) })); - // Crate - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCrate, 1, 0), new Object[] { "TST", "S S", "TST", 'S', Item.ingotIron, 'T', Block.wood })); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCrate, 1, 1), new Object[] { "TST", "SCS", "TST", 'C', new ItemStack(blockCrate, 1, 0), 'S', Item.ingotIron, 'T', Block.wood })); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCrate, 1, 2), new Object[] { "TST", "SCS", "TST", 'C', new ItemStack(blockCrate, 1, 1), 'S', Item.ingotIron, 'T', Block.wood })); - } - public static void printSidedData(String data) { System.out.print(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT ? "[C]" : "[S]"); diff --git a/src/minecraft/assemblyline/common/CommonProxy.java b/src/minecraft/assemblyline/common/CommonProxy.java index 8baa6077..839cb595 100644 --- a/src/minecraft/assemblyline/common/CommonProxy.java +++ b/src/minecraft/assemblyline/common/CommonProxy.java @@ -13,9 +13,9 @@ import net.minecraft.world.World; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.multiblock.TileEntityMulti; import assemblyline.common.armbot.TileEntityArmbot; -import assemblyline.common.block.TileEntityCrate; import assemblyline.common.imprinter.ContainerImprinter; import assemblyline.common.imprinter.TileEntityImprinter; +import assemblyline.common.machine.TileEntityCrate; import assemblyline.common.machine.TileEntityManipulator; import assemblyline.common.machine.TileEntityRejector; import assemblyline.common.machine.belt.TileEntityConveyorBelt; @@ -40,17 +40,7 @@ public class CommonProxy implements IGuiHandler public void init() { - GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, "ALConveyorBelt"); - GameRegistry.registerTileEntity(TileEntityRejector.class, "ALSorter"); - GameRegistry.registerTileEntity(TileEntityManipulator.class, "ALManipulator"); - GameRegistry.registerTileEntity(TileEntityCrate.class, "ALCrate"); - GameRegistry.registerTileEntity(TileEntityDetector.class, "ALDetector"); - GameRegistry.registerTileEntity(TileEntityEncoder.class, "ALEncoder"); - GameRegistry.registerTileEntity(TileEntityArmbot.class, "ALArmbot"); - GameRegistry.registerTileEntity(TileEntityCraneController.class, "ALCraneController"); - GameRegistry.registerTileEntity(TileEntityCraneRail.class, "ALCraneRail"); - GameRegistry.registerTileEntity(TileEntityImprinter.class, "ALImprinter"); - GameRegistry.registerTileEntity(TileEntityMulti.class, "ALMulti"); + } private void extractZipToLocation(File zipFile, String sourceFolder, String destFolder) diff --git a/src/minecraft/assemblyline/common/Recipes.java b/src/minecraft/assemblyline/common/Recipes.java new file mode 100644 index 00000000..c17b55d6 --- /dev/null +++ b/src/minecraft/assemblyline/common/Recipes.java @@ -0,0 +1,87 @@ +package assemblyline.common; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; +import cpw.mods.fml.common.registry.GameRegistry; + +public class Recipes +{ + static Object circuit; + static Object circuit2; + static Object circuit3; + static Object steel; + static Object steelPlate; + static Object motor; + + public static void loadRecipes() + { + circuit = Item.redstoneRepeater; + circuit2 = Item.comparator; + steel = Item.ingotIron; + steelPlate = Item.ingotGold; + motor = Block.pistonBase; + + if (!AssemblyLine.VINALLA_RECIPES) + { + if (OreDictionary.getOres("basicCircuit").size() > 0) + { + circuit = "basicCircuit"; + } + if (OreDictionary.getOres("advancedCircuit").size() > 0) + { + circuit = "advancedCircuit"; + } + if (OreDictionary.getOres("ingotSteel").size() > 0) + { + steel = "ingotSteel"; + } + if (OreDictionary.getOres("plateSteel").size() > 0) + { + steelPlate = "plateSteel"; + } + if (OreDictionary.getOres("motor").size() > 0) + { + motor = "motor"; + } + + } + Recipes.createStandardRecipes(); + Recipes.createUERecipes(); + } + + private static void createUERecipes() + { + // Armbot + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.blockArmbot, new Object[] { "II ", "SIS", "MCM", 'S', Recipes.steelPlate, 'C', Recipes.circuit2, 'I', Recipes.steel, 'M', Recipes.motor })); + // Disk + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.itemDisk, new Object[] { "III", "ICI", "III", 'I', AssemblyLine.itemImprint, 'C', Recipes.circuit2 })); + // Encoder + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.blockEncoder, new Object[] { "SIS", "SCS", "SSS", 'I', AssemblyLine.itemImprint, 'S', Recipes.steel, 'C', Recipes.circuit2 })); + // Detector + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.blockDetector, new Object[] { "SES", "SCS", "S S", 'S', Recipes.steel, 'C', Recipes.circuit, 'E', Item.eyeOfEnder })); + // Conveyor Belt + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(AssemblyLine.blockConveyorBelt, 10), new Object[] { "III", "WMW", 'I', Recipes.steel, 'W', Block.planks, 'M', Recipes.motor })); + // Rejector + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.blockRejector, new Object[] { "CPC", "@R@", '@', Recipes.steel, 'R', Item.redstone, 'P', Block.pistonBase, 'C', Recipes.circuit })); + // Turntable + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.blockTurntable, new Object[] { "IMI", " P ", 'M', Recipes.motor, 'P', Block.pistonBase, 'I', Recipes.steel })); + // Manipulator + GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(AssemblyLine.blockManipulator, 2), new Object[] { Block.dispenser, Recipes.circuit })); + } + + private static void createStandardRecipes() + { + // Imprint + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(AssemblyLine.itemImprint, 2), new Object[] { "R", "P", "I", 'P', Item.paper, 'R', Item.redstone, 'I', new ItemStack(Item.dyePowder, 1, 0) })); + // Imprinter + GameRegistry.addRecipe(new ShapedOreRecipe(AssemblyLine.blockImprinter, new Object[] { "SIS", "SPS", "WCW", 'S', Item.ingotIron, 'C', Block.chest, 'W', Block.workbench, 'P', Block.pistonBase, 'I', new ItemStack(Item.dyePowder, 1, 0) })); + // Crate + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(AssemblyLine.blockCrate, 1, 0), new Object[] { "TST", "S S", "TST", 'S', Item.ingotIron, 'T', Block.planks })); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(AssemblyLine.blockCrate, 1, 1), new Object[] { "TST", "SCS", "TST", 'C', new ItemStack(AssemblyLine.blockCrate, 1, 0), 'S', Recipes.steel, 'T', Block.wood })); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(AssemblyLine.blockCrate, 1, 2), new Object[] { "TST", "SCS", "TST", 'C', new ItemStack(AssemblyLine.blockCrate, 1, 1), 'S', Recipes.steelPlate, 'T', Block.wood })); + } +} diff --git a/src/minecraft/assemblyline/common/armbot/BlockArmbot.java b/src/minecraft/assemblyline/common/armbot/BlockArmbot.java index 65149df7..5fcf25a7 100644 --- a/src/minecraft/assemblyline/common/armbot/BlockArmbot.java +++ b/src/minecraft/assemblyline/common/armbot/BlockArmbot.java @@ -11,17 +11,15 @@ import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.multiblock.IMultiBlock; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockArmbot extends BlockALMachine +public class BlockArmbot extends BlockAssembly { public BlockArmbot(int id) { - super(id, UniversalElectricity.machine); - this.setUnlocalizedName("armbot"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(id, UniversalElectricity.machine,"armbot"); } @Override diff --git a/src/minecraft/assemblyline/common/armbot/TileEntityArmbot.java b/src/minecraft/assemblyline/common/armbot/TileEntityArmbot.java index 45de0a3e..dcc22a0c 100644 --- a/src/minecraft/assemblyline/common/armbot/TileEntityArmbot.java +++ b/src/minecraft/assemblyline/common/armbot/TileEntityArmbot.java @@ -1,8 +1,5 @@ package assemblyline.common.armbot; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -15,14 +12,11 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.block.IElectricityStorage; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.TranslationHelper; import universalelectricity.prefab.multiblock.IMultiBlock; @@ -39,62 +33,45 @@ import assemblyline.common.armbot.command.CommandReturn; import assemblyline.common.armbot.command.CommandRotateBy; import assemblyline.common.armbot.command.CommandRotateTo; import assemblyline.common.armbot.command.CommandUse; -import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.TileEntityAssembly; import assemblyline.common.machine.encoder.ItemDisk; - -import com.google.common.io.ByteArrayDataInput; - import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.relauncher.Side; import dan200.computer.api.IComputerAccess; import dan200.computer.api.IPeripheral; import dark.helpers.ItemFindingHelper; -public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IElectricityStorage, IArmbot, IPeripheral +public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IInventory, IPacketReceiver, IArmbot, IPeripheral { private final CommandManager commandManager = new CommandManager(); - private static final int PACKET_COMMANDS = 128; - - /** - * The items this container contains. - */ + /** The items this container contains. */ protected ItemStack disk = null; public final double WATT_REQUEST = 20; - public double wattsReceived = 0; - private int playerUsing = 0; private int computersAttached = 0; private List connectedComputers = new ArrayList(); - /** - * The rotation of the arms. In Degrees. - */ + /** The rotation of the arms. In Degrees. */ public float rotationPitch = 0; public float rotationYaw = 0; public float renderPitch = 0; public float renderYaw = 0; - private int ticksSincePower = 0; public final float ROTATION_SPEED = 2.0f; private String displayText = ""; public boolean isProvidingPower = false; - /** - * An entity that the Armbot is grabbed onto. Entity Items are held separately. - */ + /** An entity that the Armbot is grabbed onto. Entity Items are held separately. */ private final List grabbedEntities = new ArrayList(); private final List grabbedItems = new ArrayList(); - /** - * Client Side Object Storage - */ + /** Client Side Object Storage */ public EntityItem renderEntityItem = null; @Override public void initiate() { super.initiate(); - if(!this.commandManager.hasTasks()) + if (!this.commandManager.hasTasks()) { this.onInventoryChanged(); } @@ -150,12 +127,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult } if (!this.worldObj.isRemote) this.commandManager.onUpdate(); - - this.ticksSincePower = 0; } else { - this.ticksSincePower++; } if (!this.worldObj.isRemote) @@ -280,9 +254,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult return null; } - /** - * @return The current hand position of the armbot. - */ + /** @return The current hand position of the armbot. */ public Vector3 getHandPosition() { Vector3 position = new Vector3(this); @@ -306,46 +278,16 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult return delta; } + /** Data */ @Override public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); - writeToNBT(nbt); - return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.powerTransferRange, nbt); + this.writeToNBT(nbt); + return PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.NBT, nbt); } - /** - * Data - */ - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - if (this.worldObj.isRemote) - { - try - { - ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); - DataInputStream dis = new DataInputStream(bis); - int id, x, y, z; - id = dis.readInt(); - x = dis.readInt(); - y = dis.readInt(); - z = dis.readInt(); - this.powerTransferRange = dis.readInt(); - NBTTagCompound tag = Packet.readNBTTagCompound(dis); - readFromNBT(tag); - } - catch (IOException e) - { - FMLLog.severe("Failed to receive packet for Armbot"); - e.printStackTrace(); - } - } - } - - /** - * Inventory - */ + /** Inventory */ @Override public int getSizeInventory() { @@ -358,9 +300,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult return TranslationHelper.getLocal("tile.armbot.name"); } - /** - * Inventory functions. - */ + /** Inventory functions. */ @Override public ItemStack getStackInSlot(int par1) { @@ -435,13 +375,11 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult @Override public void openChest() { - this.playerUsing++; } @Override public void closeChest() { - this.playerUsing--; } public String getCommandDisplayText() @@ -449,9 +387,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult return this.displayText; } - /** - * NBT Data - */ + /** NBT Data */ @Override public void readFromNBT(NBTTagCompound nbt) { @@ -506,9 +442,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult } } - /** - * Writes a tile entity to NBT. - */ + /** Writes a tile entity to NBT. */ @Override public void writeToNBT(NBTTagCompound nbt) { @@ -559,24 +493,6 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult nbt.setTag("items", items); } - @Override - public double getJoules() - { - return this.wattsReceived; - } - - @Override - public void setJoules(double joules) - { - this.wattsReceived = joules; - } - - @Override - public double getMaxJoules() - { - return 1000; - } - @Override public boolean onActivated(EntityPlayer player) { @@ -913,45 +829,44 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult } @Override - public void dropEntity(Entity entity) + public void drop(Object object) { - this.grabbedEntities.remove(entity); - } - - @Override - public void dropItem(ItemStack itemStack) - { - Vector3 handPosition = this.getHandPosition(); - this.worldObj.spawnEntityInWorld(new EntityItem(worldObj, handPosition.x, handPosition.y, handPosition.z, itemStack)); - this.grabbedItems.remove(itemStack); - } - - @Override - public void dropAll() - { - Vector3 handPosition = this.getHandPosition(); - Iterator it = this.grabbedItems.iterator(); - - while (it.hasNext()) + if (object instanceof Entity) { - ItemFindingHelper.dropItemStackExact(worldObj, handPosition.x, handPosition.y, handPosition.z, it.next()); + this.grabbedEntities.remove((Entity) object); } + if (object instanceof ItemStack) + { + Vector3 handPosition = this.getHandPosition(); + ItemFindingHelper.dropItemStackExact(worldObj, handPosition.x, handPosition.y, handPosition.z, (ItemStack) object); + this.grabbedItems.remove((ItemStack) object); + } + if (object instanceof String) + { + String string = ((String) object).toLowerCase(); + if (string.equalsIgnoreCase("all")) + { + Vector3 handPosition = this.getHandPosition(); + Iterator it = this.grabbedItems.iterator(); - this.grabbedEntities.clear(); - this.grabbedItems.clear(); + while (it.hasNext()) + { + ItemFindingHelper.dropItemStackExact(worldObj, handPosition.x, handPosition.y, handPosition.z, it.next()); + } + + this.grabbedEntities.clear(); + this.grabbedItems.clear(); + } + } } - /** - * called by the block when another checks it too see if it is providing power to a direction - */ + /** called by the block when another checks it too see if it is providing power to a direction */ public boolean isProvidingPowerSide(ForgeDirection dir) { return this.isProvidingPower && dir.getOpposite() == this.getFacingDirectionFromAngle(); } - /** - * gets the facing direction using the yaw angle - */ + /** gets the facing direction using the yaw angle */ public ForgeDirection getFacingDirectionFromAngle() { float angle = MathHelper.wrapAngleTo180_float(this.rotationYaw); @@ -993,4 +908,13 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult return false; } + @Override + public double getWattLoad() + { + if (this.getCurrentCommand() != null) + { + return 2; + } + return .1; + } } diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandDrop.java b/src/minecraft/assemblyline/common/armbot/command/CommandDrop.java index 35a2042a..31a3c1b6 100644 --- a/src/minecraft/assemblyline/common/armbot/command/CommandDrop.java +++ b/src/minecraft/assemblyline/common/armbot/command/CommandDrop.java @@ -7,7 +7,7 @@ public class CommandDrop extends Command { super.doTask(); - this.tileEntity.dropAll(); + this.tileEntity.drop("all"); this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true); return false; diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandGive.java b/src/minecraft/assemblyline/common/armbot/command/CommandGive.java index 783f987b..7ffe24cd 100644 --- a/src/minecraft/assemblyline/common/armbot/command/CommandGive.java +++ b/src/minecraft/assemblyline/common/armbot/command/CommandGive.java @@ -9,7 +9,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; -import assemblyline.common.machine.InvExtractionHelper; +import assemblyline.common.machine.InvInteractionHelper; public class CommandGive extends Command { @@ -63,7 +63,7 @@ public class CommandGive extends Command { stacks.add(stack); } - InvExtractionHelper invEx = new InvExtractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false); + InvInteractionHelper invEx = new InvInteractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false); Iterator targetIt = this.tileEntity.getGrabbedItems().iterator(); boolean flag = true; diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandGrab.java b/src/minecraft/assemblyline/common/armbot/command/CommandGrab.java index 8c9c1cca..5a6d56cd 100644 --- a/src/minecraft/assemblyline/common/armbot/command/CommandGrab.java +++ b/src/minecraft/assemblyline/common/armbot/command/CommandGrab.java @@ -90,7 +90,7 @@ public class CommandGrab extends Command { this.tileEntity.grabEntity(found.get(i)); this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true); - if(this.belt != null){belt.IgnoreEntity(found.get(i));} + if(this.belt != null){belt.ignoreEntity(found.get(i));} return false; } } diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandPlace.java b/src/minecraft/assemblyline/common/armbot/command/CommandPlace.java index 95a30c58..2cfaf524 100644 --- a/src/minecraft/assemblyline/common/armbot/command/CommandPlace.java +++ b/src/minecraft/assemblyline/common/armbot/command/CommandPlace.java @@ -47,7 +47,7 @@ public class CommandPlace extends Command { ((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage()); - this.tileEntity.dropEntity(entity); + this.tileEntity.drop(entity); return false; } else if (itemStack.getItem() instanceof IPlantable) @@ -68,7 +68,7 @@ public class CommandPlace extends Command { Block.blocksList[blockID].onBlockPlacedBy(world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), null, itemStack); Block.blocksList[blockID].onPostBlockPlaced(world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockMetadata); - this.tileEntity.dropEntity(entity); + this.tileEntity.drop(entity); return false; } } diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandTake.java b/src/minecraft/assemblyline/common/armbot/command/CommandTake.java index fa5d38e0..b48d0e90 100644 --- a/src/minecraft/assemblyline/common/armbot/command/CommandTake.java +++ b/src/minecraft/assemblyline/common/armbot/command/CommandTake.java @@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; -import assemblyline.common.machine.InvExtractionHelper; +import assemblyline.common.machine.InvInteractionHelper; public class CommandTake extends Command { @@ -62,7 +62,7 @@ public class CommandTake extends Command { stacks.add(stack); } - InvExtractionHelper invEx = new InvExtractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false); + InvInteractionHelper invEx = new InvInteractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false); this.tileEntity.grabItem(invEx.tryGrabFromPosition(new Vector3(targetTile), direction, this.stack != null ? stack.stackSize : 1)); return !(this.tileEntity.getGrabbedItems().size() > 0); diff --git a/src/minecraft/assemblyline/common/armbot/command/GrabDictionary.java b/src/minecraft/assemblyline/common/armbot/command/GrabDictionary.java index 3d7e8737..5dced9c0 100644 --- a/src/minecraft/assemblyline/common/armbot/command/GrabDictionary.java +++ b/src/minecraft/assemblyline/common/armbot/command/GrabDictionary.java @@ -113,7 +113,7 @@ public class GrabDictionary } } - public static void registerList() + static { registerGrabableEntity("chicken", EntityChicken.class); registerGrabableEntity("cow", EntityCow.class); diff --git a/src/minecraft/assemblyline/common/block/BlockALMachine.java b/src/minecraft/assemblyline/common/block/BlockALMachine.java deleted file mode 100644 index 0ae9a338..00000000 --- a/src/minecraft/assemblyline/common/block/BlockALMachine.java +++ /dev/null @@ -1,42 +0,0 @@ -package assemblyline.common.block; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.util.Icon; -import net.minecraft.world.IBlockAccess; -import universalelectricity.prefab.block.BlockAdvanced; -import assemblyline.common.AssemblyLine; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class BlockALMachine extends BlockAdvanced -{ - public Icon machine_icon; - - public BlockALMachine(int id, Material material) - { - super(id, material); - } - - @SideOnly(Side.CLIENT) - @Override - public void registerIcons(IconRegister iconReg) - { - this.machine_icon = iconReg.registerIcon(AssemblyLine.TEXTURE_NAME_PREFIX + "machine"); - } - - @Override - @SideOnly(Side.CLIENT) - public Icon getBlockTexture(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) - { - return this.machine_icon; - } - - @Override - @SideOnly(Side.CLIENT) - public Icon getIcon(int par1, int par2) - { - return this.machine_icon; - } - -} \ No newline at end of file diff --git a/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java b/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java index 8d07fcea..7bfef576 100644 --- a/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java +++ b/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java @@ -15,21 +15,19 @@ import net.minecraft.world.World; import assemblyline.common.AssemblyLine; import assemblyline.common.CommonProxy; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockImprinter extends BlockALMachine +public class BlockImprinter extends BlockAssembly { Icon imprinter_side; Icon imprinter_top; Icon imprinter_bottom; - public BlockImprinter(int id, int texture) + public BlockImprinter(int id) { - super(id, Material.wood); - this.setUnlocalizedName("imprinter"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(id, Material.wood,"imprinter"); } @SideOnly(Side.CLIENT) diff --git a/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java b/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java index 8c972cb3..cc44505a 100644 --- a/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java +++ b/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java @@ -11,20 +11,19 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import universalelectricity.prefab.implement.IRedstoneReceptor; import assemblyline.api.IFilterable; -import assemblyline.common.block.BlockALMachine; import assemblyline.common.imprinter.ItemImprinter; +import assemblyline.common.machine.BlockAssembly; /** * Extend this block class if a filter is allowed to be placed inside of this block. * * @author Calclavia */ -public abstract class BlockImprintable extends BlockALMachine +public abstract class BlockImprintable extends BlockAssembly { public BlockImprintable(String name, int id, Material material, CreativeTabs creativeTab) { - super(id, material); - this.setUnlocalizedName(name); + super(id, material,name); this.setCreativeTab(creativeTab); } diff --git a/src/minecraft/assemblyline/common/imprinter/prefab/TileEntityFilterable.java b/src/minecraft/assemblyline/common/imprinter/prefab/TileEntityFilterable.java index 211002fb..2ab99b03 100644 --- a/src/minecraft/assemblyline/common/imprinter/prefab/TileEntityFilterable.java +++ b/src/minecraft/assemblyline/common/imprinter/prefab/TileEntityFilterable.java @@ -20,23 +20,21 @@ import universalelectricity.prefab.network.PacketManager; import assemblyline.api.IFilterable; import assemblyline.common.AssemblyLine; import assemblyline.common.imprinter.ItemImprinter; -import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.TileEntityAssembly; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; -public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork implements IRotatable, IFilterable, IPacketReceiver +public abstract class TileEntityFilterable extends TileEntityAssembly implements IRotatable, IFilterable, IPacketReceiver { private ItemStack filterItem; private boolean inverted; - /** - * Looks through the things in the filter and finds out which item is being filtered. + /** Looks through the things in the filter and finds out which item is being filtered. * - * @return Is this filterable block filtering this specific ItemStack? - */ + * @return Is this filterable block filtering this specific ItemStack? */ public boolean isFiltering(ItemStack itemStack) { if (this.getFilter() != null && itemStack != null) @@ -65,11 +63,7 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp public void setFilter(ItemStack filter) { this.filterItem = filter; - - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) - { - PacketManager.sendPacketToClients(this.getDescriptionPacket()); - } + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @Override @@ -81,10 +75,7 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp public void setInverted(boolean inverted) { this.inverted = inverted; - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) - { - PacketManager.sendPacketToClients(this.getDescriptionPacket()); - } + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } public boolean isInverted() @@ -119,13 +110,11 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp return this.getDirection(worldObj, xCoord, yCoord, zCoord); } - /** - * Don't override this! Override getPackData() instead! - */ + /** Don't override this! Override getPackData() instead! */ @Override public Packet getDescriptionPacket() { - return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.getPacketData().toArray()); + return PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.NBT.ordinal(), this.getPacketData().toArray()); } public ArrayList getPacketData() @@ -137,31 +126,6 @@ public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork imp return array; } - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - if (worldObj.isRemote) - { - ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); - DataInputStream dis = new DataInputStream(bis); - int id, x, y, z; - try - { - id = dis.readInt(); - x = dis.readInt(); - y = dis.readInt(); - z = dis.readInt(); - this.worldObj.markBlockForRenderUpdate(x, y, z); - NBTTagCompound tag = Packet.readNBTTagCompound(dis); - readFromNBT(tag); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - @Override public void writeToNBT(NBTTagCompound nbt) { diff --git a/src/minecraft/assemblyline/common/machine/BlockAssembly.java b/src/minecraft/assemblyline/common/machine/BlockAssembly.java new file mode 100644 index 00000000..d11e2be7 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/BlockAssembly.java @@ -0,0 +1,101 @@ +package assemblyline.common.machine; + +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.prefab.block.BlockAdvanced; +import assemblyline.common.AssemblyLine; +import assemblyline.common.TabAssemblyLine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import dark.core.api.INetworkPart; + +public class BlockAssembly extends BlockAdvanced +{ + public Icon machine_icon; + + public BlockAssembly(int id, Material material, String name) + { + super(AssemblyLine.CONFIGURATION.getBlock(name, id).getInt(), material); + this.setUnlocalizedName(name); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + ItemStack stack = entityPlayer.getHeldItem(); + TileEntity ent = world.getBlockTileEntity(x, y, z); + if (!world.isRemote && stack != null && stack.itemID == Item.stick.itemID && ent instanceof TileEntityAssembly && entityPlayer != null) + { + TileEntityAssembly asm = (TileEntityAssembly) ent; + String output = "Debug>>>"; + output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|"; + entityPlayer.sendChatToPlayer(output); + output = "Debug>>>"; + output += "Powered:" + asm.running + " "; + if (asm.getTileNetwork() instanceof NetworkAssembly) + { + output += ElectricityDisplay.getDisplaySimple(((NetworkAssembly) asm.getTileNetwork()).getCurrentBattery(), ElectricUnit.WATT, 2); + output += "/"; + output += ElectricityDisplay.getDisplaySimple(((NetworkAssembly) asm.getTileNetwork()).getMaxBattery(), ElectricUnit.WATT, 2); + } + entityPlayer.sendChatToPlayer(output); + } + return super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IconRegister iconReg) + { + this.machine_icon = iconReg.registerIcon(AssemblyLine.TEXTURE_NAME_PREFIX + "machine"); + } + + @Override + @SideOnly(Side.CLIENT) + public Icon getBlockTexture(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) + { + return this.machine_icon; + } + + @Override + @SideOnly(Side.CLIENT) + public Icon getIcon(int par1, int par2) + { + return this.machine_icon; + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + super.onBlockAdded(world, x, y, z); + + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof INetworkPart) + { + ((INetworkPart) tileEntity).updateNetworkConnections(); + } + } + + @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).updateNetworkConnections(); + } + } + +} \ No newline at end of file diff --git a/src/minecraft/assemblyline/common/machine/BlockBeltSorter.java b/src/minecraft/assemblyline/common/machine/BlockBeltSorter.java deleted file mode 100644 index 4058a816..00000000 --- a/src/minecraft/assemblyline/common/machine/BlockBeltSorter.java +++ /dev/null @@ -1,17 +0,0 @@ -package assemblyline.common.machine; - -import net.minecraft.block.material.Material; -import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; - -public class BlockBeltSorter extends BlockALMachine -{ - - public BlockBeltSorter(int id) - { - super(id, Material.iron); - this.setCreativeTab(TabAssemblyLine.INSTANCE); - this.setUnlocalizedName("BeltSorter"); - } - -} diff --git a/src/minecraft/assemblyline/common/block/BlockCrate.java b/src/minecraft/assemblyline/common/machine/BlockCrate.java similarity index 97% rename from src/minecraft/assemblyline/common/block/BlockCrate.java rename to src/minecraft/assemblyline/common/machine/BlockCrate.java index c5a37d5c..e6f9ec2d 100644 --- a/src/minecraft/assemblyline/common/block/BlockCrate.java +++ b/src/minecraft/assemblyline/common/machine/BlockCrate.java @@ -1,4 +1,4 @@ -package assemblyline.common.block; +package assemblyline.common.machine; import java.util.List; @@ -14,7 +14,6 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import universalelectricity.core.UniversalElectricity; import assemblyline.common.AssemblyLine; -import assemblyline.common.PathfinderCrate; import assemblyline.common.TabAssemblyLine; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -26,15 +25,13 @@ import cpw.mods.fml.relauncher.SideOnly; * @author Calclavia * */ -public class BlockCrate extends BlockALMachine +public class BlockCrate extends BlockAssembly { Icon crate_icon; - public BlockCrate(int id, int texture) + public BlockCrate(int id) { - super(id, UniversalElectricity.machine); - this.setUnlocalizedName("crate"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(id, UniversalElectricity.machine,"crate"); } @SideOnly(Side.CLIENT) diff --git a/src/minecraft/assemblyline/common/block/BlockTurntable.java b/src/minecraft/assemblyline/common/machine/BlockTurntable.java similarity index 95% rename from src/minecraft/assemblyline/common/block/BlockTurntable.java rename to src/minecraft/assemblyline/common/machine/BlockTurntable.java index 1f032d01..b6d6553f 100644 --- a/src/minecraft/assemblyline/common/block/BlockTurntable.java +++ b/src/minecraft/assemblyline/common/machine/BlockTurntable.java @@ -1,4 +1,4 @@ -package assemblyline.common.block; +package assemblyline.common.machine; import java.util.Random; @@ -21,15 +21,13 @@ import assemblyline.common.TabAssemblyLine; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockTurntable extends BlockALMachine +public class BlockTurntable extends BlockAssembly { private Icon top; public BlockTurntable(int par1) { - super(par1, Material.piston); - this.setUnlocalizedName("turntable"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(par1, Material.piston,"turntable"); } @Override diff --git a/src/minecraft/assemblyline/common/machine/InvExtractionHelper.java b/src/minecraft/assemblyline/common/machine/InvInteractionHelper.java similarity index 97% rename from src/minecraft/assemblyline/common/machine/InvExtractionHelper.java rename to src/minecraft/assemblyline/common/machine/InvInteractionHelper.java index 2aea01e1..0b4812a7 100644 --- a/src/minecraft/assemblyline/common/machine/InvExtractionHelper.java +++ b/src/minecraft/assemblyline/common/machine/InvInteractionHelper.java @@ -13,18 +13,16 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.multiblock.TileEntityMulti; -import assemblyline.common.block.BlockCrate; -import assemblyline.common.block.TileEntityCrate; import assemblyline.common.imprinter.ItemImprinter; -public class InvExtractionHelper +public class InvInteractionHelper { World world; Vector3 location; List filterItems; boolean inverted; - public InvExtractionHelper(World world, Vector3 location, List filters, boolean inverted) + public InvInteractionHelper(World world, Vector3 location, List filters, boolean inverted) { this.world = world; this.location = location; diff --git a/src/minecraft/assemblyline/common/block/ItemBlockCrate.java b/src/minecraft/assemblyline/common/machine/ItemBlockCrate.java similarity index 99% rename from src/minecraft/assemblyline/common/block/ItemBlockCrate.java rename to src/minecraft/assemblyline/common/machine/ItemBlockCrate.java index 236f8283..070e43ec 100644 --- a/src/minecraft/assemblyline/common/block/ItemBlockCrate.java +++ b/src/minecraft/assemblyline/common/machine/ItemBlockCrate.java @@ -1,4 +1,4 @@ -package assemblyline.common.block; +package assemblyline.common.machine; import java.util.List; diff --git a/src/minecraft/assemblyline/common/machine/NetworkAssembly.java b/src/minecraft/assemblyline/common/machine/NetworkAssembly.java new file mode 100644 index 00000000..d983f876 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/NetworkAssembly.java @@ -0,0 +1,86 @@ +package assemblyline.common.machine; + +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.core.electricity.ElectricityPack; +import net.minecraft.tileentity.TileEntity; +import dark.core.api.INetworkPart; +import dark.core.tile.network.NetworkPowerTiles; +import dark.core.tile.network.NetworkTileEntities; + +public class NetworkAssembly extends NetworkPowerTiles +{ + public NetworkAssembly(INetworkPart... parts) + { + super(parts); + } + + public NetworkTileEntities newInstance() + { + return new NetworkAssembly(); + } + + /** Consumes power for the tile to run on + * + * @param tile - tileEntity + * @return true if the power was consumed */ + public boolean consumePower(TileEntityAssembly tile) + { + if (tile != null && this.wattStored >= tile.getWattLoad()) + { + this.wattStored -= tile.getWattLoad(); + //System.out.println("Power| ---" + ElectricityDisplay.getDisplaySimple(tile.getWattLoad(), ElectricUnit.WATT, 2) + " A: " + ElectricityDisplay.getDisplaySimple(this.wattStored, ElectricUnit.WATT, 2)); + return true; + } + return false; + } + + /** Adds power to the network. Does not save power on area unload */ + public void addPower(double d) + { + double before = this.wattStored; + this.wattStored = Math.min(this.wattStored + d, this.getMaxBattery()); + System.out.println("Power| +++" + ElectricityDisplay.getDisplaySimple(d, ElectricUnit.WATT, 2) + " A: " + ElectricityDisplay.getDisplaySimple(this.wattStored, ElectricUnit.WATT, 2)); + + } + + @Override + public ElectricityPack getRequest(TileEntity... ents) + { + ElectricityPack pack = super.getRequest(ents); + if (pack == null || pack.voltage == 0 || pack.amperes == 0) + { + pack = new ElectricityPack(0, 120); + } + + return ElectricityPack.getFromWatts(pack.getWatts() + this.getMemberRequest(), pack.voltage); + } + + @Override + public double getMemberRequest() + { + double watt = 0; + for (INetworkPart part : this.getNetworkMemebers()) + { + //TODO do check for ignored tiles/ents + if (part instanceof TileEntityAssembly) + { + watt += ((TileEntityAssembly) part).getWattLoad(); + } + } + return watt; + } + + @Override + public boolean isValidMember(INetworkPart part) + { + return super.isValidMember(part) && part instanceof TileEntityAssembly; + } + + @Override + public String toString() + { + return "AssemblyNetwork[" + this.hashCode() + "][parts:" + this.networkMember.size() + "][Power:" + ElectricityDisplay.getDisplaySimple(this.wattStored, ElectricUnit.WATT, 2) + "]"; + } + +} diff --git a/src/minecraft/assemblyline/common/PathfinderCrate.java b/src/minecraft/assemblyline/common/machine/PathfinderCrate.java similarity index 97% rename from src/minecraft/assemblyline/common/PathfinderCrate.java rename to src/minecraft/assemblyline/common/machine/PathfinderCrate.java index b40b274d..f16c1f5e 100644 --- a/src/minecraft/assemblyline/common/PathfinderCrate.java +++ b/src/minecraft/assemblyline/common/machine/PathfinderCrate.java @@ -1,4 +1,4 @@ -package assemblyline.common; +package assemblyline.common.machine; import java.util.ArrayList; import java.util.List; @@ -7,7 +7,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.VectorHelper; -import assemblyline.common.block.TileEntityCrate; /** * A class that allows flexible path finding in Minecraft Blocks. Back Ported from UE 1.3.0. diff --git a/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java b/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java new file mode 100644 index 00000000..0ef7ecde --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java @@ -0,0 +1,321 @@ +package assemblyline.common.machine; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.network.IPacketReceiver; +import universalelectricity.prefab.network.PacketManager; +import assemblyline.common.AssemblyLine; +import buildcraft.api.power.PowerProvider; + +import com.google.common.io.ByteArrayDataInput; + +import dark.core.api.INetworkPart; +import dark.core.tile.network.NetworkPowerTiles; +import dark.core.tile.network.NetworkTileEntities; +import dark.library.machine.TileEntityRunnableMachine; + +/** A class to be inherited by all machines on the assembly line. This class acts as a single peace + * in a network of similar tiles allowing all to share power from one or more sources + * + * @author DarkGuardsman */ +public abstract class TileEntityAssembly extends TileEntityRunnableMachine implements INetworkPart, IPacketReceiver, IConductor +{ + /** Is the tile currently powered allowing it to run */ + public boolean running = false; + private boolean prevRun = false; + /** Network used to link assembly machines together */ + private NetworkAssembly assemblyNetwork; + /** Tiles that are connected to this */ + public List connectedTiles = new ArrayList(); + /** Random instance */ + public Random random = new Random(); + /** Random rate by which this tile updates its connections */ + private int updateTick = 1; + + public static enum AssemblyTilePacket + { + POWER(), + NBT(); + } + + @Override + public void invalidate() + { + NetworkAssembly.invalidate(this); + if (this.getTileNetwork() != null) + { + this.getTileNetwork().splitNetwork(this.worldObj, this); + } + super.invalidate(); + } + + @Override + public void updateEntity() + { + if (!this.worldObj.isRemote) + { + this.prevRun = this.running; + super.updateEntity(); + if (ticks % updateTick == 0) + { + this.updateTick = ((int) random.nextInt(10) + 20); + this.updateNetworkConnections(); + } + this.running = ((NetworkAssembly) this.getTileNetwork()).consumePower(this); + if (running != prevRun) + { + Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.POWER.ordinal(), this.running); + PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 64); + } + } + + this.onUpdate(); + } + + @Override + public void onReceive(ForgeDirection side, double voltage, double amperes) + { + if (voltage <= 0 || amperes <= 0) + { + return; + } + if (voltage > this.getVoltage()) + { + this.onDisable(2); + return; + } + if (this.getTileNetwork() instanceof NetworkAssembly) + { + ((NetworkAssembly) this.getTileNetwork()).addPower(voltage * amperes); + //System.out.println("Tile got power Side:" + side.toString() + " " + ElectricityDisplay.getDisplaySimple(voltage, ElectricUnit.VOLTAGE, 2) + " " + ElectricityDisplay.getDisplaySimple(amperes, ElectricUnit.AMPERE, 2)); + } + } + + /** Same as updateEntity */ + public abstract void onUpdate(); + + /** Checks to see if this assembly tile can run using several methods */ + public boolean isRunning() + { + if (!this.worldObj.isRemote) + { + return this.running || AssemblyLine.REQUIRE_NO_POWER; + } + else + { + return this.running; + } + + } + + /** Amount of energy this tile runs on per tick */ + public double getWattLoad() + { + return 1; + } + + @Override + public double getBattery(ForgeDirection side) + { + if (this.getTileNetwork() instanceof NetworkAssembly) + { + return ((NetworkAssembly) this.getTileNetwork()).getMaxBattery(); + } + return super.getBattery(side); + } + + @Override + public double getCurrentBattery(ForgeDirection side) + { + if (this.getTileNetwork() instanceof NetworkAssembly) + { + return ((NetworkAssembly) this.getTileNetwork()).getCurrentBattery(); + } + return super.getCurrentBattery(side); + } + + /** Amount of energy the network needs at any given time */ + @Override + public double getRequest(ForgeDirection side) + { + if (this.getTileNetwork() instanceof NetworkAssembly) + { + NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork()); + return Math.min(100 + net.getMemberRequest(), Math.max(0, net.getRequest(new Vector3(this).modifyPositionFromSide(side).getTileEntity(this.worldObj), this).getWatts())); + } + return 0; + } + + @Override + public boolean canTileConnect(TileEntity entity, ForgeDirection dir) + { + return entity != null && entity instanceof TileEntityAssembly; + } + + @Override + public void updateNetworkConnections() + { + if (this.worldObj != null && !this.worldObj.isRemote) + { + this.connectedTiles.clear(); + + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj); + if (tileEntity instanceof TileEntityAssembly && ((TileEntityAssembly) tileEntity).canTileConnect(this, dir.getOpposite())) + { + this.getTileNetwork().merge(((TileEntityAssembly) tileEntity).getTileNetwork(), this); + connectedTiles.add(tileEntity); + } + } + } + } + + @Override + public List getNetworkConnections() + { + return this.connectedTiles; + } + + @Override + public NetworkTileEntities getTileNetwork() + { + if (this.assemblyNetwork == null) + { + this.assemblyNetwork = new NetworkAssembly(this); + } + return this.assemblyNetwork; + } + + @Override + public void setTileNetwork(NetworkTileEntities network) + { + if (network instanceof NetworkAssembly) + { + this.assemblyNetwork = (NetworkAssembly) network; + } + + } + + public String toString() + { + return "[AssemblyTile]@" + (new Vector3(this).toString()); + } + + @Override + public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) + { + boolean packetSize = false; + try + { + ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); + DataInputStream dis = new DataInputStream(bis); + + int id = dis.readInt(); + int x = dis.readInt(); + int y = dis.readInt(); + int z = dis.readInt(); + int pId = dis.readInt(); + + this.simplePacket(pId, dis, player); + + /** DEBUG PACKET SIZE AND INFO */ + if (packetSize) + { + System.out.println("TileEntityAssembly>" + new Vector3(this) + ">>>Debug>>Packet" + pId + ">>Size>>bytes>>" + packet.data.length); + } + } + catch (Exception e) + { + System.out.println("Error Reading Packet for a TileEntityAssembly"); + e.printStackTrace(); + } + + } + + /** Handles reduced data from the main packet method + * + * @param id - packet ID + * @param dis - data + * @param player - player + * @return true if the packet was used */ + public boolean simplePacket(int id, DataInputStream dis, EntityPlayer player) + { + try + { + if (this.worldObj.isRemote) + { + if (id == AssemblyTilePacket.POWER.ordinal()) + { + this.running = dis.readBoolean(); + return true; + } + if (id == AssemblyTilePacket.NBT.ordinal()) + { + this.readFromNBT(Packet.readNBTTagCompound(dis)); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + return false; + } + + @Override + public IElectricityNetwork getNetwork() + { + return (this.getTileNetwork() instanceof IElectricityNetwork ? (IElectricityNetwork) this.getTileNetwork() : null); + } + + @Override + public void setNetwork(IElectricityNetwork network) + { + // TODO Auto-generated method stub + + } + + @Override + public TileEntity[] getAdjacentConnections() + { + return new TileEntity[6]; + } + + @Override + public void updateAdjacentConnections() + { + this.updateNetworkConnections(); + + } + + @Override + public double getResistance() + { + return 0.01; + } + + @Override + public double getCurrentCapcity() + { + return 1000; + } + +} diff --git a/src/minecraft/assemblyline/common/machine/TileEntityAssemblyNetwork.java b/src/minecraft/assemblyline/common/machine/TileEntityAssemblyNetwork.java deleted file mode 100644 index a2f00072..00000000 --- a/src/minecraft/assemblyline/common/machine/TileEntityAssemblyNetwork.java +++ /dev/null @@ -1,100 +0,0 @@ -package assemblyline.common.machine; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.electricity.ElectricityPack; -import universalelectricity.prefab.network.PacketManager; -import assemblyline.common.AssemblyLine; -import dark.library.machine.TileEntityRunnableMachine; - -/** - * A class to be inherited by all machines on the assembly line. This will allow all machines to be - * able to be powered through the powering of only one machine. - * - * @author Calclavia - * - */ -public abstract class TileEntityAssemblyNetwork extends TileEntityRunnableMachine -{ - /** - * The range in which power can be transfered. - */ - public int powerTransferRange = 0; - - public boolean isRunning() - { - return AssemblyLine.REQUIRE_NO_POWER || this.powerTransferRange > 0 || this.wattsReceived > this.getRequest().getWatts(); - } - - public void updatePowerTransferRange() - { - int maximumTransferRange = 0; - - for (int i = 0; i < 6; i++) - { - ForgeDirection direction = ForgeDirection.getOrientation(i); - TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); - - if (tileEntity != null) - { - if (tileEntity instanceof TileEntityAssemblyNetwork) - { - TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity; - - if (assemblyNetwork.powerTransferRange > maximumTransferRange) - { - maximumTransferRange = assemblyNetwork.powerTransferRange; - } - } - } - } - - this.powerTransferRange = Math.max(maximumTransferRange - 1, 0); - } - - @Override - public void updateEntity() - { - super.updateEntity(); - - this.onUpdate(); - - if (this.ticks % 10 == 0) - { - if (this.wattsReceived >= this.getRequest().getWatts()) - { - this.wattsReceived -= getRequest().getWatts(); - this.powerTransferRange = this.getMaxTransferRange(); - } - else - { - this.powerTransferRange = 0; - this.updatePowerTransferRange(); - } - - if (!this.worldObj.isRemote) - { - if (this.getDescriptionPacket() != null) - { - PacketManager.sendPacketToClients(this.getDescriptionPacket()); - } - } - } - } - - protected void onUpdate() - { - - } - - @Override - public ElectricityPack getRequest() - { - return new ElectricityPack(1, this.getVoltage()); - } - - protected int getMaxTransferRange() - { - return 30; - } -} diff --git a/src/minecraft/assemblyline/common/block/TileEntityCrate.java b/src/minecraft/assemblyline/common/machine/TileEntityCrate.java similarity index 99% rename from src/minecraft/assemblyline/common/block/TileEntityCrate.java rename to src/minecraft/assemblyline/common/machine/TileEntityCrate.java index 66b466c7..3f6ab5b6 100644 --- a/src/minecraft/assemblyline/common/block/TileEntityCrate.java +++ b/src/minecraft/assemblyline/common/machine/TileEntityCrate.java @@ -1,4 +1,4 @@ -package assemblyline.common.block; +package assemblyline.common.machine; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; diff --git a/src/minecraft/assemblyline/common/machine/TileEntityManipulator.java b/src/minecraft/assemblyline/common/machine/TileEntityManipulator.java index e22e3423..3eb1f29f 100644 --- a/src/minecraft/assemblyline/common/machine/TileEntityManipulator.java +++ b/src/minecraft/assemblyline/common/machine/TileEntityManipulator.java @@ -25,10 +25,10 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota /** True if is currently powered by redstone */ private boolean isRedstonePowered = false; /** The class that interacts with inventories for this machine */ - private InvExtractionHelper invExtractionHelper; + private InvInteractionHelper invExtractionHelper; @Override - protected void onUpdate() + public void onUpdate() { if (!this.worldObj.isRemote) { @@ -201,11 +201,11 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota } /** Gets the class that managed extracting and placing items into inventories */ - public InvExtractionHelper invHelper() + public InvInteractionHelper invHelper() { if (invExtractionHelper == null || invExtractionHelper.world != this.worldObj) { - this.invExtractionHelper = new InvExtractionHelper(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprinter.getFilters(getFilter()) : null, this.isInverted()); + this.invExtractionHelper = new InvInteractionHelper(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprinter.getFilters(getFilter()) : null, this.isInverted()); } return invExtractionHelper; } diff --git a/src/minecraft/assemblyline/common/machine/TileEntityRejector.java b/src/minecraft/assemblyline/common/machine/TileEntityRejector.java index f74298a7..fcd22328 100644 --- a/src/minecraft/assemblyline/common/machine/TileEntityRejector.java +++ b/src/minecraft/assemblyline/common/machine/TileEntityRejector.java @@ -10,59 +10,33 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; -import universalelectricity.prefab.network.PacketManager; +import assemblyline.api.IBelt; import assemblyline.common.imprinter.prefab.TileEntityFilterable; -/** - * - * @author Darkguardsman - * - */ +/** @author Darkguardsman */ public class TileEntityRejector extends TileEntityFilterable { - /** - * should the piston fire, or be extended - */ + /** should the piston fire, or be extended */ public boolean firePiston = false; - public TileEntityRejector() - { - super(); - } - - @Override - protected int getMaxTransferRange() - { - return 20; - } - @Override public void onUpdate() { - super.onUpdate(); - /** - * Has to update a bit faster than a conveyer belt - */ + /** Has to update a bit faster than a conveyer belt */ if (this.ticks % 5 == 0 && !this.isDisabled()) { - int metadata = this.getBlockMetadata(); - this.firePiston = false; - - // area to search for items + this.firePiston = false; + Vector3 searchPosition = new Vector3(this); searchPosition.modifyPositionFromSide(this.getDirection()); TileEntity tileEntity = searchPosition.getTileEntity(this.worldObj); try { - boolean flag = false; - if (this.isRunning()) { - /** - * Find all entities in the position in which this block is facing and attempt - * to push it out of the way. - */ + /** Find all entities in the position in which this block is facing and attempt + * to push it out of the way. */ AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(searchPosition.x, searchPosition.y, searchPosition.z, searchPosition.x + 1, searchPosition.y + 1, searchPosition.z + 1); List entitiesInFront = this.worldObj.getEntitiesWithinAABB(Entity.class, bounds); @@ -70,8 +44,7 @@ public class TileEntityRejector extends TileEntityFilterable { if (this.canEntityBeThrow(entity)) { - this.throwItem(this.getDirection(), entity); - flag = true; + this.throwItem(tileEntity, this.getDirection(), entity); } } } @@ -83,23 +56,22 @@ public class TileEntityRejector extends TileEntityFilterable } } - /** - * Used to move after it has been rejected - * - * @param side - used to do the offset - * @param entity - Entity being thrown - */ - public void throwItem(ForgeDirection side, Entity entity) + /** Pushs an entity in the direction in which the rejector is facing */ + public void throwItem(TileEntity tileEntity, ForgeDirection side, Entity entity) { this.firePiston = true; - + //TODO add config to adjust the motion magnitude per rejector entity.motionX = (double) side.offsetX * 0.1; entity.motionY += 0.10000000298023224D; entity.motionZ = (double) side.offsetZ * 0.1; - PacketManager.sendPacketToClients(getDescriptionPacket()); + if (!this.worldObj.isRemote && tileEntity instanceof IBelt) + { + ((IBelt) tileEntity).ignoreEntity(entity); + } } + /** Checks to see if the rejector can push the entity in the facing direction */ public boolean canEntityBeThrow(Entity entity) { // TODO Add other things than items @@ -114,26 +86,6 @@ public class TileEntityRejector extends TileEntityFilterable return false; } - /** - * NBT Data - */ - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - this.firePiston = nbt.getBoolean("piston"); - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setBoolean("piston", this.firePiston); - } - @Override public boolean canConnect(ForgeDirection dir) { diff --git a/src/minecraft/assemblyline/common/machine/TileEntityRoboticSorter.java b/src/minecraft/assemblyline/common/machine/TileEntityRoboticSorter.java deleted file mode 100644 index 885a2317..00000000 --- a/src/minecraft/assemblyline/common/machine/TileEntityRoboticSorter.java +++ /dev/null @@ -1,233 +0,0 @@ -package assemblyline.common.machine; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.prefab.network.IPacketReceiver; -import universalelectricity.prefab.tile.TileEntityElectricityRunnable; -import assemblyline.common.machine.belt.TileEntityConveyorBelt; - -import com.google.common.io.ByteArrayDataInput; - -public class TileEntityRoboticSorter extends TileEntityElectricityRunnable implements IPacketReceiver, IInventory -{ - /** - * The items this container contains. - */ - protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()]; - - /** - * Used to id the packet types - */ - private enum PacketTypes - { - ANIMATION, GUI, SETTINGON - } - - /** - * Joules required per tick. - */ - public static final int WATT_REQUEST = 10; - - /** - * Stored energy - */ - public double wattsReceived = 0; - /** - * on/off value for the GUI buttons - */ - public boolean[] guiButtons = new boolean[] { true, true, true, true, true }; - /** - * the belt found in the search area - */ - public TileEntityConveyorBelt[] beltSide = new TileEntityConveyorBelt[6]; - - private int playerUsing = 0; - - @Override - public String getInvName() - { - return "Sorter"; - } - - @Override - public int getSizeInventory() - { - return 4; - } - - /** - * Inventory functions. - */ - @Override - public ItemStack getStackInSlot(int par1) - { - return this.containingItems[par1]; - } - - @Override - public ItemStack decrStackSize(int par1, int par2) - { - if (this.containingItems[par1] != null) - { - ItemStack var3; - - if (this.containingItems[par1].stackSize <= par2) - { - var3 = this.containingItems[par1]; - this.containingItems[par1] = null; - return var3; - } - else - { - var3 = this.containingItems[par1].splitStack(par2); - - if (this.containingItems[par1].stackSize == 0) - { - this.containingItems[par1] = null; - } - - return var3; - } - } - else - { - return null; - } - } - - @Override - public ItemStack getStackInSlotOnClosing(int par1) - { - if (this.containingItems[par1] != null) - { - ItemStack var2 = this.containingItems[par1]; - this.containingItems[par1] = null; - return var2; - } - else - { - return null; - } - } - - @Override - public void setInventorySlotContents(int par1, ItemStack par2ItemStack) - { - this.containingItems[par1] = par2ItemStack; - - if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) - { - par2ItemStack.stackSize = this.getInventoryStackLimit(); - } - } - - @Override - public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) - { - return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; - } - - @Override - public void openChest() - { - this.playerUsing++; - } - - @Override - public void closeChest() - { - this.playerUsing--; - } - - /** - * NBT Data - */ - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - - for (int i = 0; i < this.guiButtons.length; i++) - { - this.guiButtons[i] = nbt.getBoolean("guiButton" + i); - } - - NBTTagList var2 = nbt.getTagList("Items"); - this.containingItems = new ItemStack[this.getSizeInventory()]; - - for (int var3 = 0; var3 < var2.tagCount(); ++var3) - { - NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3); - byte var5 = var4.getByte("Slot"); - - if (var5 >= 0 && var5 < this.containingItems.length) - { - this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4); - } - } - } - - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - // TODO Auto-generated method stub - - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - - for (int i = 0; i < this.guiButtons.length; i++) - { - nbt.setBoolean("guiButton" + i, this.guiButtons[i]); - } - - NBTTagList var2 = new NBTTagList(); - for (int var3 = 0; var3 < this.containingItems.length; ++var3) - { - if (this.containingItems[var3] != null) - { - NBTTagCompound var4 = new NBTTagCompound(); - var4.setByte("Slot", (byte) var3); - this.containingItems[var3].writeToNBT(var4); - var2.appendTag(var4); - } - } - nbt.setTag("Items", var2); - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public boolean canConnect(ForgeDirection dir) - { - return dir == ForgeDirection.DOWN; - } - - @Override - public boolean isInvNameLocalized() - { - return false; - } - - @Override - public boolean isStackValidForSlot(int i, ItemStack itemstack) - { - return false; - } -} diff --git a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java index 50350b91..56b4af10 100644 --- a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java @@ -16,7 +16,7 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.UniversalElectricity; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import assemblyline.common.machine.belt.TileEntityConveyorBelt.SlantType; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -26,14 +26,12 @@ import cpw.mods.fml.relauncher.SideOnly; * * @author Calclavia, DarkGuardsman */ -public class BlockConveyorBelt extends BlockALMachine +public class BlockConveyorBelt extends BlockAssembly { public BlockConveyorBelt(int id) { - super(id, UniversalElectricity.machine); - this.setUnlocalizedName("conveyorBelt"); + super(id, UniversalElectricity.machine,"conveyorBelt"); this.setBlockBounds(0, 0, 0, 1, 0.3f, 1); - this.setCreativeTab(TabAssemblyLine.INSTANCE); } @Override @@ -172,6 +170,7 @@ public class BlockConveyorBelt extends BlockALMachine @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving, ItemStack stack) { + super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, stack); int angle = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; int change = 2; @@ -246,7 +245,6 @@ public class BlockConveyorBelt extends BlockALMachine public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) world.getBlockTileEntity(x, y, z); - tileEntity.updatePowerTransferRange(); if (tileEntity.IgnoreList.contains(entity)) { return; diff --git a/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java index 484d0911..a78b1dfe 100644 --- a/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java @@ -1,6 +1,8 @@ package assemblyline.common.machine.belt; +import java.io.DataInputStream; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import net.minecraft.entity.Entity; @@ -14,129 +16,62 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.implement.IRotatable; import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.PacketManager; import assemblyline.api.IBelt; import assemblyline.common.AssemblyLine; -import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.TileEntityAssembly; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; -public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements IPacketReceiver, IBelt, IRotatable +public class TileEntityConveyorBelt extends TileEntityAssembly implements IPacketReceiver, IBelt, IRotatable { public enum SlantType { - NONE, UP, DOWN, TOP + NONE, + UP, + DOWN, + TOP } public static final int MAX_FRAME = 13; public static final int MAX_SLANT_FRAME = 23; - /** - * Joules required to run this thing. - */ public final float acceleration = 0.01f; public final float maxSpeed = 0.1f; - + /** Current rotation of the model wheels */ public float wheelRotation = 0; private int animFrame = 0; // this is from 0 to 15 private SlantType slantType = SlantType.NONE; - - public List IgnoreList = new ArrayList();// Entities that need to be ignored to - // prevent movement - - /** - * This function is overriden to allow conveyor belts to power belts that are diagonally going - * up. - */ - @Override - public void updatePowerTransferRange() - { - int maximumTransferRange = 0; - - for (int i = 0; i < 6; i++) - { - ForgeDirection direction = ForgeDirection.getOrientation(i); - TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); - - if (tileEntity != null) - { - if (tileEntity instanceof TileEntityAssemblyNetwork) - { - TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity; - - if (assemblyNetwork.powerTransferRange > maximumTransferRange) - { - maximumTransferRange = assemblyNetwork.powerTransferRange; - } - } - } - } - - for (int d = 0; d <= 1; d++) - { - ForgeDirection direction = this.getDirection(); - - if (d == 1) - { - direction = direction.getOpposite(); - } - - for (int i = -1; i <= 1; i++) - { - TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + i, this.zCoord + direction.offsetZ); - if (tileEntity != null) - { - if (tileEntity instanceof TileEntityAssemblyNetwork) - { - TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity; - - if (assemblyNetwork.powerTransferRange > maximumTransferRange) - { - maximumTransferRange = assemblyNetwork.powerTransferRange; - } - } - } - } - } - - this.powerTransferRange = Math.max(maximumTransferRange - 1, 0); - } + /** Entities that are ignored allowing for other tiles to interact with them */ + public List IgnoreList = new ArrayList(); @Override public void onUpdate() { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 10 == 0) - { - PacketManager.sendPacketToClients(this.getDescriptionPacket()); - } - /* PROCESSES IGNORE LIST AND REMOVES UNNEED ENTRIES */ - List newList = new ArrayList(); - for (Entity ent : IgnoreList) + Iterator it = this.IgnoreList.iterator(); + while (it.hasNext()) { - if (this.getAffectedEntities().contains(ent)) + if (!this.getAffectedEntities().contains(it.next())) { - newList.add(ent); + it.remove(); } } - this.IgnoreList = newList; - if (this.isRunning() && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) + if (this.worldObj.isRemote && this.isRunning() && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) { if (this.ticks % 10 == 0 && this.worldObj.isRemote && this.worldObj.getBlockId(this.xCoord - 1, this.yCoord, this.zCoord) != AssemblyLine.blockConveyorBelt.blockID && this.worldObj.getBlockId(xCoord, yCoord, zCoord - 1) != AssemblyLine.blockConveyorBelt.blockID) { this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "mods.assemblyline.conveyor", 0.5f, 0.7f, true); } - this.wheelRotation += 40; - - if (this.wheelRotation > 360) - this.wheelRotation = 0; + this.wheelRotation = (40 + this.wheelRotation) % 360; float wheelRotPct = wheelRotation / 360f; @@ -161,16 +96,10 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements } - @Override - protected int getMaxTransferRange() - { - return 20; - } - @Override public Packet getDescriptionPacket() { - return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.wattsReceived, this.slantType.ordinal()); + return PacketManager.getPacket(AssemblyLine.CHANNEL, this, 3, this.slantType.ordinal()); } public SlantType getSlant() @@ -184,86 +113,69 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements { slantType = SlantType.NONE; } - this.slantType = slantType; - - PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj); + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } - /** - * Is this belt in the front of a conveyor line? Used for rendering. - */ + /** Is this belt in the front of a conveyor line? Used for rendering. */ public boolean getIsFirstBelt() { - - ForgeDirection front = this.getDirection(); - ForgeDirection back = this.getDirection().getOpposite(); - TileEntity fBelt = worldObj.getBlockTileEntity(xCoord + front.offsetX, yCoord + front.offsetY, zCoord + front.offsetZ); - TileEntity BBelt = worldObj.getBlockTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ); - if (fBelt instanceof TileEntityConveyorBelt) + Vector3 vec = new Vector3(this); + TileEntity fBelt = vec.clone().modifyPositionFromSide(this.getDirection()).getTileEntity(this.worldObj); + TileEntity bBelt = vec.clone().modifyPositionFromSide(this.getDirection().getOpposite()).getTileEntity(this.worldObj); + if (fBelt instanceof TileEntityConveyorBelt && !(bBelt instanceof TileEntityConveyorBelt)) { - ForgeDirection fD = ((TileEntityConveyorBelt) fBelt).getDirection(); - ForgeDirection TD = this.getDirection(); - return fD == TD; + return ((TileEntityConveyorBelt) fBelt).getDirection() == this.getDirection(); } return false; } - /** - * Is this belt in the middile of two belts? Used for rendering. - */ + /** Is this belt in the middile of two belts? Used for rendering. */ public boolean getIsMiddleBelt() { - ForgeDirection front = this.getDirection(); - ForgeDirection back = this.getDirection().getOpposite(); - TileEntity fBelt = worldObj.getBlockTileEntity(xCoord + front.offsetX, yCoord + front.offsetY, zCoord + front.offsetZ); - TileEntity BBelt = worldObj.getBlockTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ); - if (fBelt instanceof TileEntityConveyorBelt && BBelt instanceof TileEntityConveyorBelt) + Vector3 vec = new Vector3(this); + TileEntity fBelt = vec.clone().modifyPositionFromSide(this.getDirection()).getTileEntity(this.worldObj); + TileEntity bBelt = vec.clone().modifyPositionFromSide(this.getDirection().getOpposite()).getTileEntity(this.worldObj); + if (fBelt instanceof TileEntityConveyorBelt && bBelt instanceof TileEntityConveyorBelt) { - ForgeDirection fD = ((TileEntityConveyorBelt) fBelt).getDirection(); - ForgeDirection BD = ((TileEntityConveyorBelt) BBelt).getDirection(); - ForgeDirection TD = this.getDirection(); - return fD == TD && BD == TD; + return ((TileEntityConveyorBelt) fBelt).getDirection() == this.getDirection() && ((TileEntityConveyorBelt) bBelt).getDirection() == this.getDirection(); } return false; } - /** - * Is this belt in the back of a conveyor line? Used for rendering. - */ + /** Is this belt in the back of a conveyor line? Used for rendering. */ public boolean getIsLastBelt() { - - ForgeDirection front = this.getDirection(); - ForgeDirection back = this.getDirection().getOpposite(); - TileEntity fBelt = worldObj.getBlockTileEntity(xCoord + front.offsetX, yCoord + front.offsetY, zCoord + front.offsetZ); - TileEntity BBelt = worldObj.getBlockTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ); - - if (BBelt instanceof TileEntityConveyorBelt) + Vector3 vec = new Vector3(this); + TileEntity fBelt = vec.clone().modifyPositionFromSide(this.getDirection()).getTileEntity(this.worldObj); + TileEntity bBelt = vec.clone().modifyPositionFromSide(this.getDirection().getOpposite()).getTileEntity(this.worldObj); + if (bBelt instanceof TileEntityConveyorBelt && !(fBelt instanceof TileEntityConveyorBelt)) { - ForgeDirection BD = ((TileEntityConveyorBelt) BBelt).getDirection(); - ForgeDirection TD = this.getDirection(); - return BD == TD; + return ((TileEntityConveyorBelt) bBelt).getDirection() == this.getDirection().getOpposite(); } return false; } @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) + public boolean simplePacket(int id, DataInputStream dis, EntityPlayer player) { - if (this.worldObj.isRemote) + if (!super.simplePacket(id, dis, player) && this.worldObj.isRemote) { try { - this.wattsReceived = dataStream.readDouble(); - this.slantType = SlantType.values()[dataStream.readInt()]; + if (id == 3) + { + this.slantType = SlantType.values()[dis.readInt()]; + return true; + } } catch (Exception e) { e.printStackTrace(); } } + return false; } @Override @@ -272,6 +184,11 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 3); } + public void setDirection(ForgeDirection facingDirection) + { + this.setDirection(worldObj, xCoord, yCoord, zCoord, facingDirection); + } + @Override public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) { @@ -283,83 +200,35 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements return this.getDirection(worldObj, xCoord, yCoord, zCoord); } - public void setDirection(ForgeDirection facingDirection) - { - this.setDirection(worldObj, xCoord, yCoord, zCoord, facingDirection); - } - @Override public List getAffectedEntities() { - AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1); - return worldObj.getEntitiesWithinAABB(Entity.class, bounds); + return worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1)); } public int getAnimationFrame() { - if (!this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) - { - TileEntity te = null; - te = this.worldObj.getBlockTileEntity(this.xCoord - 1, this.yCoord, this.zCoord); - - if (te != null) - { - if (te instanceof TileEntityConveyorBelt) - { - if (((TileEntityConveyorBelt) te).getSlant() == this.slantType) - return ((TileEntityConveyorBelt) te).getAnimationFrame(); - } - - } - - te = this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord - 1); - - if (te != null) - { - if (te instanceof TileEntityConveyorBelt) - { - if (((TileEntityConveyorBelt) te).getSlant() == this.slantType) - return ((TileEntityConveyorBelt) te).getAnimationFrame(); - } - - } - } - return this.animFrame; } - /** - * NBT Data - */ + /** NBT Data */ @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); this.slantType = SlantType.values()[nbt.getByte("slant")]; - - if (worldObj != null) - { - worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, nbt.getInteger("rotation"), 3); - } } - /** - * Writes a tile entity to NBT. - */ + /** Writes a tile entity to NBT. */ @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setByte("slant", (byte) this.slantType.ordinal()); - - if (worldObj != null) - { - nbt.setInteger("rotation", worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); - } } @Override - public void IgnoreEntity(Entity entity) + public void ignoreEntity(Entity entity) { if (!this.IgnoreList.contains(entity)) { @@ -373,4 +242,50 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements { return direction == ForgeDirection.DOWN; } + + @Override + public void updateNetworkConnections() + { + super.updateNetworkConnections(); + if (this.worldObj != null && !this.worldObj.isRemote) + { + Vector3 face = new Vector3(this).modifyPositionFromSide(this.getDirection()); + Vector3 back = new Vector3(this).modifyPositionFromSide(this.getDirection().getOpposite()); + TileEntity front, rear; + if (this.slantType == SlantType.DOWN) + { + face.add(new Vector3(0, -1, 0)); + back.add(new Vector3(0, 1, 0)); + } + else if (this.slantType == SlantType.UP) + { + face.add(new Vector3(0, 1, 0)); + back.add(new Vector3(0, -1, 0)); + } + else + { + return; + } + front = face.getTileEntity(this.worldObj); + rear = back.getTileEntity(this.worldObj); + if (front instanceof TileEntityAssembly) + { + this.getTileNetwork().merge(((TileEntityAssembly) front).getTileNetwork(), this); + this.connectedTiles.add(front); + } + if (rear instanceof TileEntityAssembly) + { + this.getTileNetwork().merge(((TileEntityAssembly) rear).getTileNetwork(), this); + this.connectedTiles.add(rear); + } + + } + } + + @Override + public double getWattLoad() + { + return 0.1 + (0.1 * this.getAffectedEntities().size()); + } + } diff --git a/src/minecraft/assemblyline/common/machine/belt/TileEntityCoveredBelt.java b/src/minecraft/assemblyline/common/machine/belt/TileEntityCoveredBelt.java deleted file mode 100644 index b105d577..00000000 --- a/src/minecraft/assemblyline/common/machine/belt/TileEntityCoveredBelt.java +++ /dev/null @@ -1,13 +0,0 @@ -package assemblyline.common.machine.belt; - -/** - * For the moment this is just a render place holder, but will be convered to prevent item pickups - * from the belts. - * - * @author Rseifert - * - */ -public class TileEntityCoveredBelt extends TileEntityConveyorBelt -{ - -} diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java index 8c538e86..dbc73ae2 100644 --- a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java @@ -8,17 +8,15 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.UniversalElectricity; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockCraneController extends BlockALMachine +public class BlockCraneController extends BlockAssembly { public BlockCraneController(int id) { - super(id, UniversalElectricity.machine); - this.setUnlocalizedName("craneController"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(id, UniversalElectricity.machine,"craneController"); } @Override diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java index 833860c1..c72c45c4 100644 --- a/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java @@ -8,17 +8,15 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.UniversalElectricity; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockCraneFrame extends BlockALMachine +public class BlockCraneFrame extends BlockAssembly { public BlockCraneFrame(int id) { - super(id, UniversalElectricity.machine); - this.setUnlocalizedName("craneFrame"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(id, UniversalElectricity.machine,"craneFrame"); this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); } diff --git a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java index ea9de66e..e5f9e15b 100644 --- a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java +++ b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java @@ -7,9 +7,9 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; import assemblyline.api.ICraneStructure; import assemblyline.common.AssemblyLine; -import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.TileEntityAssembly; -public class TileEntityCraneController extends TileEntityAssemblyNetwork implements ICraneStructure +public class TileEntityCraneController extends TileEntityAssembly implements ICraneStructure { int width, depth; boolean isCraneValid; @@ -213,4 +213,10 @@ public class TileEntityCraneController extends TileEntityAssemblyNetwork impleme { return true; } + @Override + public void onUpdate() + { + // TODO Auto-generated method stub + + } } diff --git a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java index 8eca5e7c..8d13f215 100644 --- a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java +++ b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java @@ -2,9 +2,9 @@ package assemblyline.common.machine.crane; import net.minecraftforge.common.ForgeDirection; import assemblyline.api.ICraneStructure; -import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.TileEntityAssembly; -public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements ICraneStructure +public class TileEntityCraneRail extends TileEntityAssembly implements ICraneStructure { @Override @@ -19,4 +19,11 @@ public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements IC return false; } + @Override + public void onUpdate() + { + // TODO Auto-generated method stub + + } + } diff --git a/src/minecraft/assemblyline/common/machine/detector/BlockDetector.java b/src/minecraft/assemblyline/common/machine/detector/BlockDetector.java index 94040b57..29a0e63f 100644 --- a/src/minecraft/assemblyline/common/machine/detector/BlockDetector.java +++ b/src/minecraft/assemblyline/common/machine/detector/BlockDetector.java @@ -25,7 +25,7 @@ public class BlockDetector extends BlockImprintable Icon eye_red; Icon eye_green; - public BlockDetector(int blockID, int texture) + public BlockDetector(int blockID) { super("detector", blockID, UniversalElectricity.machine, TabAssemblyLine.INSTANCE); } diff --git a/src/minecraft/assemblyline/common/machine/detector/TileEntityDetector.java b/src/minecraft/assemblyline/common/machine/detector/TileEntityDetector.java index 94882d8f..75c0186c 100644 --- a/src/minecraft/assemblyline/common/machine/detector/TileEntityDetector.java +++ b/src/minecraft/assemblyline/common/machine/detector/TileEntityDetector.java @@ -110,4 +110,11 @@ public class TileEntityDetector extends TileEntityFilterable { return direction != this.getDirection(); } + + @Override + public void onUpdate() + { + // TODO Auto-generated method stub + + } } diff --git a/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java b/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java index c2183bde..059c9d04 100644 --- a/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java +++ b/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java @@ -10,20 +10,18 @@ import net.minecraft.world.World; import assemblyline.common.AssemblyLine; import assemblyline.common.CommonProxy; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.block.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockEncoder extends BlockALMachine +public class BlockEncoder extends BlockAssembly { Icon encoder_side; Icon encoder_top; Icon encoder_bottom; - public BlockEncoder(int id, int texture) + public BlockEncoder(int id) { - super(id, Material.wood); - this.setUnlocalizedName("encoder"); - this.setCreativeTab(TabAssemblyLine.INSTANCE); + super(id, Material.wood,"encoder"); } @SideOnly(Side.CLIENT)