From 866c254aa73b21b622179c1229e25f58d82716f2 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Mon, 26 Aug 2013 12:43:36 -0400 Subject: [PATCH] Created debug blocks Not tested nor really done yet. The idea in creating these is to provide a sure way to test basic functions of machines. Since these debug block are very simple no real issue should arise of the block failing. --- src/dark/common/debug/BlockDebug.java | 58 ++++++++++++++++++ src/dark/common/debug/TileEntityInfFluid.java | 8 +++ src/dark/common/debug/TileEntityInfLoad.java | 50 ++++++++++++++++ .../common/debug/TileEntityInfSupply.java | 60 +++++++++++++++++++ src/dark/common/debug/TileEntityVoid.java | 59 ++++++++++++++++++ .../transmit}/BlockLaserEmitter.java | 2 +- .../transmit}/ItemBlockLaserEmitter.java | 2 +- .../transmit}/TileEntityLaserEmitter.java | 2 +- src/dark/core/CoreRecipeLoader.java | 2 +- src/dark/core/DarkMain.java | 16 ++++- src/dark/core/blocks/BlockMachine.java | 4 +- .../tile/network/NetworkTileEntities.java | 8 ++- 12 files changed, 261 insertions(+), 10 deletions(-) create mode 100644 src/dark/common/debug/BlockDebug.java create mode 100644 src/dark/common/debug/TileEntityInfFluid.java create mode 100644 src/dark/common/debug/TileEntityInfLoad.java create mode 100644 src/dark/common/debug/TileEntityInfSupply.java create mode 100644 src/dark/common/debug/TileEntityVoid.java rename src/dark/{transmit/laser => common/transmit}/BlockLaserEmitter.java (89%) rename src/dark/{transmit/laser => common/transmit}/ItemBlockLaserEmitter.java (85%) rename src/dark/{transmit/laser => common/transmit}/TileEntityLaserEmitter.java (97%) diff --git a/src/dark/common/debug/BlockDebug.java b/src/dark/common/debug/BlockDebug.java new file mode 100644 index 000000000..bb4b9441a --- /dev/null +++ b/src/dark/common/debug/BlockDebug.java @@ -0,0 +1,58 @@ +package dark.common.debug; + +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.Configuration; +import dark.core.DarkMain; +import dark.core.blocks.BlockMachine; + +public class BlockDebug extends BlockMachine +{ + enum debugBlocks + { + INF_POWER("infPower", TileEntityInfSupply.class), + INF_FLUID("infFluid", TileEntityInfFluid.class), + VOID("void", TileEntityVoid.class), + INF_LOAD("infLoad", TileEntityInfLoad.class); + + String name; + Class clazz; + + private debugBlocks(String name, Class clazz) + { + this.name = name; + this.clazz = clazz; + } + } + + public BlockDebug(int blockID, Configuration config) + { + super("DebugBlock", config, blockID, Material.clay); + } + + @Override + public TileEntity createTileEntity(World world, int metadata) + { + if (metadata < debugBlocks.values().length) + { + try + { + return debugBlocks.values()[metadata].clazz.newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + return super.createTileEntity(world, metadata); + } + + @Override + public TileEntity createNewTileEntity(World world) + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/dark/common/debug/TileEntityInfFluid.java b/src/dark/common/debug/TileEntityInfFluid.java new file mode 100644 index 000000000..db2397ef8 --- /dev/null +++ b/src/dark/common/debug/TileEntityInfFluid.java @@ -0,0 +1,8 @@ +package dark.common.debug; + +import net.minecraft.tileentity.TileEntity; + +public class TileEntityInfFluid extends TileEntity +{ + +} diff --git a/src/dark/common/debug/TileEntityInfLoad.java b/src/dark/common/debug/TileEntityInfLoad.java new file mode 100644 index 000000000..bc5f3fa2e --- /dev/null +++ b/src/dark/common/debug/TileEntityInfLoad.java @@ -0,0 +1,50 @@ +package dark.common.debug; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.block.IElectrical; +import universalelectricity.core.electricity.ElectricityPack; + +public class TileEntityInfLoad extends TileEntity implements IElectrical +{ + + @Override + public boolean canConnect(ForgeDirection direction) + { + //TODO add wrench settings to close sides for testing + return true; + } + + @Override + public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive) + { + return this.canConnect(from) && receive != null ? receive.getWatts() : 0; + } + + @Override + public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public float getRequest(ForgeDirection direction) + { + //TODO add config options to change this for testing + return Integer.MAX_VALUE; + } + + @Override + public float getProvide(ForgeDirection direction) + { + return 0; + } + + @Override + public float getVoltage() + { + return 10000; + } + +} diff --git a/src/dark/common/debug/TileEntityInfSupply.java b/src/dark/common/debug/TileEntityInfSupply.java new file mode 100644 index 000000000..25aa3fcbd --- /dev/null +++ b/src/dark/common/debug/TileEntityInfSupply.java @@ -0,0 +1,60 @@ +package dark.common.debug; + +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.compatibility.TileEntityUniversalElectrical; +import universalelectricity.core.block.IElectrical; +import universalelectricity.core.electricity.ElectricityPack; + +public class TileEntityInfSupply extends TileEntityUniversalElectrical implements IElectrical +{ + + @Override + public void updateEntity() + { + super.updateEntity(); + + if (!this.worldObj.isRemote) + { + this.produce(); + } + } + + @Override + public boolean canConnect(ForgeDirection direction) + { + return true; + } + + @Override + public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide) + { + return this.canConnect(from) ? request : null; + } + + @Override + public float getProvide(ForgeDirection direction) + { + // TODO Auto-generated method stub + return Integer.MAX_VALUE; + } + + @Override + public float getVoltage() + { + return 120; + } + + @Override + public float getMaxEnergyStored() + { + return Integer.MAX_VALUE; + } + + @Override + public float getRequest(ForgeDirection direction) + { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/dark/common/debug/TileEntityVoid.java b/src/dark/common/debug/TileEntityVoid.java new file mode 100644 index 000000000..958f40df0 --- /dev/null +++ b/src/dark/common/debug/TileEntityVoid.java @@ -0,0 +1,59 @@ +package dark.common.debug; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +/** Designed to debug fluid devices by draining everything that comes in at one time + * + * @author DarkGuardsman */ +public class TileEntityVoid extends TileEntity implements IFluidHandler +{ + FluidTank tank = new FluidTank(1000000); + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { + //TODO add wrench toggle options to change amount actually drained + return resource != null && this.canDrain(from, resource.getFluid()) ? resource.amount : 0; + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) + { + //TODO add wrench settings to close off sides for testing + return true; + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { + return new FluidTankInfo[] { this.tank.getInfo() }; + } + +} diff --git a/src/dark/transmit/laser/BlockLaserEmitter.java b/src/dark/common/transmit/BlockLaserEmitter.java similarity index 89% rename from src/dark/transmit/laser/BlockLaserEmitter.java rename to src/dark/common/transmit/BlockLaserEmitter.java index 6e2bac4e6..30ead5e4f 100644 --- a/src/dark/transmit/laser/BlockLaserEmitter.java +++ b/src/dark/common/transmit/BlockLaserEmitter.java @@ -1,4 +1,4 @@ -package dark.transmit.laser; +package dark.common.transmit; import net.minecraft.block.material.Material; import universalelectricity.prefab.block.BlockAdvanced; diff --git a/src/dark/transmit/laser/ItemBlockLaserEmitter.java b/src/dark/common/transmit/ItemBlockLaserEmitter.java similarity index 85% rename from src/dark/transmit/laser/ItemBlockLaserEmitter.java rename to src/dark/common/transmit/ItemBlockLaserEmitter.java index 494dd833b..4634590f2 100644 --- a/src/dark/transmit/laser/ItemBlockLaserEmitter.java +++ b/src/dark/common/transmit/ItemBlockLaserEmitter.java @@ -1,4 +1,4 @@ -package dark.transmit.laser; +package dark.common.transmit; import net.minecraft.item.ItemBlock; diff --git a/src/dark/transmit/laser/TileEntityLaserEmitter.java b/src/dark/common/transmit/TileEntityLaserEmitter.java similarity index 97% rename from src/dark/transmit/laser/TileEntityLaserEmitter.java rename to src/dark/common/transmit/TileEntityLaserEmitter.java index 0a9f5002b..525f2fb38 100644 --- a/src/dark/transmit/laser/TileEntityLaserEmitter.java +++ b/src/dark/common/transmit/TileEntityLaserEmitter.java @@ -1,4 +1,4 @@ -package dark.transmit.laser; +package dark.common.transmit; import net.minecraftforge.common.ForgeDirection; import dark.core.DarkMain; diff --git a/src/dark/core/CoreRecipeLoader.java b/src/dark/core/CoreRecipeLoader.java index 7e7bc875b..20eb63e11 100644 --- a/src/dark/core/CoreRecipeLoader.java +++ b/src/dark/core/CoreRecipeLoader.java @@ -12,7 +12,7 @@ public class CoreRecipeLoader extends RecipeLoader { /* BLOCKS */ - public static Block blockOre; + public static Block blockOre, blockDebug; /* ITEMS */ public static Item itemMetals; diff --git a/src/dark/core/DarkMain.java b/src/dark/core/DarkMain.java index 820403cb1..daf928de4 100644 --- a/src/dark/core/DarkMain.java +++ b/src/dark/core/DarkMain.java @@ -23,12 +23,14 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStoppingEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; +import dark.common.debug.BlockDebug; import dark.core.blocks.BlockMulti; import dark.core.blocks.BlockOre; import dark.core.blocks.TileEntityMulti; import dark.core.helpers.FluidRestrictionHandler; import dark.core.items.EnumMeterials; import dark.core.items.ItemBattery; +import dark.core.items.ItemBlockHolder; import dark.core.items.ItemOre; import dark.core.items.ItemOreDirv; import dark.core.items.ItemWrench; @@ -98,7 +100,14 @@ public class DarkMain extends ModPrefab { super.init(event); - GameRegistry.registerBlock(CoreRecipeLoader.blockOre, ItemOre.class, "DMOre"); + if (CoreRecipeLoader.blockOre != null) + { + GameRegistry.registerBlock(CoreRecipeLoader.blockOre, ItemOre.class, "DMOre"); + } + if (CoreRecipeLoader.blockDebug != null) + { + GameRegistry.registerBlock(CoreRecipeLoader.blockDebug, ItemBlockHolder.class, "DMOre"); + } GameRegistry.registerBlock(blockMulti, "multiBlock"); GameRegistry.registerTileEntity(TileEntityMulti.class, "ALMulti"); @@ -154,11 +163,16 @@ public class DarkMain extends ModPrefab { CoreRecipeLoader.blockOre = new BlockOre(getNextID(), CONFIGURATION); } + if (CONFIGURATION.get("general", "enableDebugBlocks", false).getBoolean(false)) + { + CoreRecipeLoader.blockDebug = new BlockDebug(getNextID(), CONFIGURATION); + } /* ITEMS */ if (CONFIGURATION.get("general", "LoadOreItems", true).getBoolean(true)) { CoreRecipeLoader.itemMetals = new ItemOreDirv(ITEM_ID_PREFIX++, CONFIGURATION); } + CONFIGURATION.save(); /* CONFIG END */ diff --git a/src/dark/core/blocks/BlockMachine.java b/src/dark/core/blocks/BlockMachine.java index 6855e2d7c..70428da42 100644 --- a/src/dark/core/blocks/BlockMachine.java +++ b/src/dark/core/blocks/BlockMachine.java @@ -22,13 +22,13 @@ import dark.core.DarkMain; * each mod using this create there own basic block extending this to reduce need to input config * file each time * - * @author Rseifert */ + * @author Darkguardsman */ public abstract class BlockMachine extends BlockAdvanced implements ITileEntityProvider { /** @param name - The name the block will use for both the config and translation file * @param config - configuration reference used to pull blockID from * @param blockID - Default block id to be used for the config - * @param material - Block material used for tool refrence? */ + * @param material - Block material used for tool reference? */ public BlockMachine(String name, Configuration config, int blockID, Material material) { super(config.getBlock(name, blockID).getInt(), material); diff --git a/src/dark/core/tile/network/NetworkTileEntities.java b/src/dark/core/tile/network/NetworkTileEntities.java index c608bad54..35f653a6e 100644 --- a/src/dark/core/tile/network/NetworkTileEntities.java +++ b/src/dark/core/tile/network/NetworkTileEntities.java @@ -74,6 +74,7 @@ public abstract class NetworkTileEntities return this.networkMember.contains(ent); } + /** removes a tile from all parts of the network */ public boolean removeTile(TileEntity ent) { return this.networkMember.remove(ent); @@ -133,13 +134,14 @@ public abstract class NetworkTileEntities return this.networkMember; } - /** Override this to write any data to the time. Called before a merge, split, or major edit of the - * network */ + /** Override this to write any data to the tile. Called before a merge, split, or major edit of + * the network */ public void writeDataToTiles() { } - /** Override this to write any data to the time. Called after a merge, split, or major edit of the + + /** Override this to read any data to the tile. Called after a merge, split, or major edit of the * network */ public void readDataFromTiles() {