From 8c60099e0edd23c928350ac52ea08d28d2cd86b5 Mon Sep 17 00:00:00 2001 From: Rseifert Date: Thu, 7 Feb 2013 23:43:59 -0500 Subject: [PATCH] Worked on use cmd and added a logger --- .../assemblyline/common/AssemblyLine.java | 16 +++--- .../assemblyline/common/DebugToPlayer.java | 52 +++++++++++++++++++ .../common/machine/command/CommandUse.java | 24 ++++++--- 3 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 src/minecraft/assemblyline/common/DebugToPlayer.java diff --git a/src/minecraft/assemblyline/common/AssemblyLine.java b/src/minecraft/assemblyline/common/AssemblyLine.java index 5e230427..f6d8db7d 100644 --- a/src/minecraft/assemblyline/common/AssemblyLine.java +++ b/src/minecraft/assemblyline/common/AssemblyLine.java @@ -1,6 +1,7 @@ package assemblyline.common; import java.io.File; +import java.util.logging.Logger; import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -29,6 +30,7 @@ import assemblyline.common.machine.encoder.ItemDisk; import assemblyline.common.machine.imprinter.BlockImprinter; import assemblyline.common.machine.imprinter.ItemImprinter; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; @@ -91,9 +93,13 @@ public class AssemblyLine public static Item itemImprint; public static Item itemDisk; + public static Logger FMLog = Logger.getLogger(AssemblyLine.NAME); + @PreInit public void preInit(FMLPreInitializationEvent event) { + FMLog.setParent(FMLLog.getLogger()); + FMLog.info("Initializing..."); UniversalElectricity.register(this, 1, 2, 5, false); instance = this; @@ -137,6 +143,7 @@ public class AssemblyLine @Init public void load(FMLInitializationEvent evt) { + FMLog.info("Loading..."); proxy.init(); System.out.println(NAME + " Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " languages."); @@ -173,13 +180,8 @@ public class AssemblyLine // Manipulator GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockManipulator, 2), new Object[] { Block.dispenser, "basicCircuit" })); - } - - @ServerStarted - public void serverStarted(FMLServerStartedEvent evt) - { - // LOLOLOL i wish - // MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().remove("briman0094"); + + FMLog.info("Ready to Use"); } public static void printSidedData(String data) diff --git a/src/minecraft/assemblyline/common/DebugToPlayer.java b/src/minecraft/assemblyline/common/DebugToPlayer.java new file mode 100644 index 00000000..74c8f0f4 --- /dev/null +++ b/src/minecraft/assemblyline/common/DebugToPlayer.java @@ -0,0 +1,52 @@ +package assemblyline.common; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class DebugToPlayer +{ + /** + * Send a debug message to the player using world xyz + * + * @param r - range + * @param msg - display message under 200 chars + */ + public static void SendToClosest(World world, int x, int y, int z, int r, String msg) + { + EntityPlayer player = world.getClosestPlayer(x, y, z, r); + if (player != null) + { + msg = trimForDisplay(msg); + player.sendChatToPlayer("Debug: " + msg); + } + } + + /** + * Sends a debug message to the player using the tileEntity as the center + * + * @param r - range + * @param msg - display message under 200 chars + */ + public static void SendToClosest(TileEntity ent, int r, String msg) + { + if (ent != null) + { + DebugToPlayer.SendToClosest(ent.worldObj, ent.xCoord, ent.yCoord, ent.zCoord, r, msg); + } + } + + /** + * cleans up the display text and adds the [Debug] prefix too the text + * + * @param msg - display string under 200 chars + * @return + */ + public static String trimForDisplay(String msg) + { + // TODO trim the length to under 255 to prevent crashing + msg = msg.trim(); + msg = "[Debug] " + msg; + return msg; + } +} diff --git a/src/minecraft/assemblyline/common/machine/command/CommandUse.java b/src/minecraft/assemblyline/common/machine/command/CommandUse.java index 08506d7f..d8794d21 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandUse.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandUse.java @@ -9,6 +9,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ISidedInventory; import assemblyline.api.IArmbotUseable; +import assemblyline.common.DebugToPlayer; public class CommandUse extends Command { @@ -45,19 +46,26 @@ public class CommandUse extends Command else if (targetTile instanceof ISidedInventory) { // TODO add IInventory side behavior for placing and taking items. - if(tileEntity.getGrabbedEntities().size() > 0) + if (tileEntity.getGrabbedEntities().size() > 0) { - //add items to inv - }else + // add items to inv + } + else { - //remove items from inv + // remove items from inv } } - else if (block == Block.lever) - { - block.onBlockActivated(this.world, tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ(), null, 0, 0, 0, 0); - } + } + else + { + try{ + boolean f = block.onBlockActivated(this.world, tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ(), null, 0, 0, 0, 0); + }catch(Exception e) + { + + e.printStackTrace(); + } }