Starting the update to 1.5
Thought you guys had this handled but guess since i'm doing the same thing for 5 other mods i'll do this as well.
This commit is contained in:
parent
e94ea438bc
commit
8ceb2dba22
108 changed files with 6642 additions and 1848 deletions
|
@ -14,7 +14,6 @@ import assemblyline.client.render.RenderConveyorBelt;
|
|||
import assemblyline.client.render.RenderCraneController;
|
||||
import assemblyline.client.render.RenderCraneFrame;
|
||||
import assemblyline.client.render.RenderCrate;
|
||||
import assemblyline.client.render.RenderDetector;
|
||||
import assemblyline.client.render.RenderManipulator;
|
||||
import assemblyline.client.render.RenderRejector;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
|
@ -26,7 +25,6 @@ import assemblyline.common.machine.armbot.TileEntityArmbot;
|
|||
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
|
||||
import assemblyline.common.machine.crane.TileEntityCraneController;
|
||||
import assemblyline.common.machine.crane.TileEntityCraneRail;
|
||||
import assemblyline.common.machine.detector.TileEntityDetector;
|
||||
import assemblyline.common.machine.encoder.TileEntityEncoder;
|
||||
import assemblyline.common.machine.imprinter.TileEntityImprinter;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
|
@ -50,7 +48,6 @@ public class ClientProxy extends CommonProxy
|
|||
super.init();
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityConveyorBelt.class, new RenderConveyorBelt());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRejector.class, new RenderRejector());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDetector.class, new RenderDetector());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityManipulator.class, new RenderManipulator());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCrate.class, new RenderCrate());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityArmbot.class, new RenderArmbot());
|
||||
|
|
|
@ -6,7 +6,6 @@ import net.minecraft.world.IBlockAccess;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import assemblyline.client.model.ModelConveyorBelt;
|
||||
import assemblyline.client.model.ModelManipulator;
|
||||
import assemblyline.client.model.ModelRejectorPiston;
|
||||
|
@ -38,10 +37,6 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
|
|||
modelConveyorBelt.render(0.0625F, 0, false, false, false, false);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
else if (block.blockID == AssemblyLine.blockDetector.blockID)
|
||||
{
|
||||
RenderDetector.render(false, new Vector3());
|
||||
}
|
||||
else if (block.blockID == AssemblyLine.blockRejector.blockID)
|
||||
{
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "rejector.png"));
|
||||
|
|
|
@ -119,7 +119,7 @@ public class AssemblyLine
|
|||
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(), 10);
|
||||
blockTurntable = new BlockTurntable(CONFIGURATION.getBlock("Turntable", BLOCK_ID_PREFIX + 12).getInt());
|
||||
|
||||
itemImprint = new ItemImprinter(CONFIGURATION.getItem("Imprint", ITEM_ID_PREFIX).getInt());
|
||||
itemDisk = new ItemDisk(CONFIGURATION.getItem("Disk", ITEM_ID_PREFIX + 1).getInt());
|
||||
|
@ -141,7 +141,8 @@ public class AssemblyLine
|
|||
GameRegistry.registerBlock(blockCraneFrame, "Crane Frame");
|
||||
|
||||
TabAssemblyLine.itemStack = new ItemStack(AssemblyLine.blockConveyorBelt);
|
||||
UpdateNotifier.INSTANCE.checkUpdate(NAME, VERSION, "http://calclavia.com/downloads/al/recommendedversion.txt");
|
||||
// TODO // UpdateNotifier.INSTANCE.checkUpdate(NAME, VERSION,
|
||||
// "http://calclavia.com/downloads/al/recommendedversion.txt");
|
||||
|
||||
proxy.preInit();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -84,7 +85,7 @@ public class PathfinderCrate
|
|||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
TileEntity connectedTile = Vector3.getTileEntityFromSide(provider.worldObj, new Vector3(provider), ForgeDirection.getOrientation(i));
|
||||
TileEntity connectedTile = VectorHelper.getTileEntityFromSide(provider.worldObj, new Vector3(provider), ForgeDirection.getOrientation(i));
|
||||
|
||||
if (!iteratedNodes.contains(connectedTile))
|
||||
{
|
||||
|
|
|
@ -5,34 +5,16 @@ import net.minecraft.block.material.Material;
|
|||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.prefab.BlockMachine;
|
||||
import universalelectricity.prefab.block.BlockAdvanced;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
public class BlockALMachine extends BlockMachine
|
||||
public class BlockALMachine extends BlockAdvanced
|
||||
{
|
||||
|
||||
public BlockALMachine(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
}
|
||||
|
||||
public BlockALMachine(int id, int textureIndex, Material material)
|
||||
{
|
||||
super(id, textureIndex, material);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockALMachine(String string, int id, Material material)
|
||||
{
|
||||
this(id, material);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockALMachine(String string, int id, Material material, CreativeTabs creativeTab)
|
||||
{
|
||||
this(string, id, material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
|
|
|
@ -26,10 +26,8 @@ public class BlockCrate extends BlockALMachine
|
|||
public BlockCrate(int id, int texture)
|
||||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
this.setBlockName("crate");
|
||||
this.blockIndexInTexture = texture;
|
||||
this.setUnlocalizedName("crate");
|
||||
this.setCreativeTab(TabAssemblyLine.INSTANCE);
|
||||
this.setTextureFile(AssemblyLine.BLOCK_TEXTURE_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -363,7 +361,7 @@ public class BlockCrate extends BlockALMachine
|
|||
var13.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(var13);
|
||||
tileEntity.setInventorySlotContents(0, null);
|
||||
world.setBlockWithNotify(x, y, z, 0);
|
||||
world.setBlockAndMetadataWithNotify(x, y, z, 0, 0, 3);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,23 +6,22 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.implement.IRotatable;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.TabAssemblyLine;
|
||||
|
||||
public class BlockTurntable extends BlockALMachine
|
||||
{
|
||||
public BlockTurntable(int par1, int par2)
|
||||
public BlockTurntable(int par1)
|
||||
{
|
||||
super(par1, par2, Material.piston);
|
||||
this.setBlockName("turntable");
|
||||
super(par1, Material.piston);
|
||||
this.setUnlocalizedName("turntable");
|
||||
this.setCreativeTab(TabAssemblyLine.INSTANCE);
|
||||
this.setTextureFile(AssemblyLine.BLOCK_TEXTURE_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,21 +30,6 @@ public class BlockTurntable extends BlockALMachine
|
|||
this.updateTurntableState(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTextureFromSideAndMetadata(int side, int metadata)
|
||||
{
|
||||
if (side == ForgeDirection.getOrientation(metadata).getOpposite().ordinal())
|
||||
{
|
||||
return this.blockIndexInTexture;
|
||||
}
|
||||
else if (side == metadata)
|
||||
{
|
||||
return this.blockIndexInTexture + 1;
|
||||
}
|
||||
|
||||
return this.blockIndexInTexture + 2;
|
||||
}
|
||||
|
||||
public static int determineOrientation(World world, int x, int y, int z, EntityPlayer entityPlayer)
|
||||
{
|
||||
if (MathHelper.abs((float) entityPlayer.posX - (float) x) < 2.0F && MathHelper.abs((float) entityPlayer.posZ - (float) z) < 2.0F)
|
||||
|
@ -68,10 +52,10 @@ public class BlockTurntable extends BlockALMachine
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving)
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving, ItemStack stack)
|
||||
{
|
||||
int metadata = determineOrientation(world, x, y, z, (EntityPlayer) par5EntityLiving);
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata);
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
|
||||
world.scheduleBlockUpdate(x, y, z, this.blockID, 20);
|
||||
}
|
||||
|
@ -107,7 +91,7 @@ public class BlockTurntable extends BlockALMachine
|
|||
|
||||
if (rotatable != null)
|
||||
{
|
||||
int newDir = ((IRotatable) tileEntity).getDirection().ordinal();
|
||||
int newDir = ((IRotatable) tileEntity).getDirection(world, x, y, z).ordinal();
|
||||
newDir++;
|
||||
|
||||
while (newDir >= 6)
|
||||
|
@ -120,7 +104,7 @@ public class BlockTurntable extends BlockALMachine
|
|||
newDir += 6;
|
||||
}
|
||||
|
||||
rotatable.setDirection(ForgeDirection.getOrientation(newDir));
|
||||
rotatable.setDirection(world, x, y, z, ForgeDirection.getOrientation(newDir));
|
||||
|
||||
world.markBlockForUpdate(position.intX(), position.intY(), position.intZ());
|
||||
world.playSoundEffect((double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, "tile.piston.in", 0.5F, world.rand.nextFloat() * 0.15F + 0.6F);
|
||||
|
|
|
@ -20,9 +20,9 @@ public class ItemBlockCrate extends ItemBlock
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getItemNameIS(ItemStack itemStack)
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return this.getItemName() + "." + itemStack.getItemDamage();
|
||||
return this.getUnlocalizedName() + "." + itemStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -276,6 +276,20 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven
|
|||
@Override
|
||||
public void setTier(int tier)
|
||||
{
|
||||
this.worldObj.setBlockMetadata(this.xCoord, this.yCoord, this.zCoord, tier);
|
||||
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, tier, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94042_c()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94041_b(int i, ItemStack itemstack)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package universalelectricity.components.client;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.components.client.gui.GuiBatteryBox;
|
||||
import universalelectricity.components.client.gui.GuiCoalGenerator;
|
||||
import universalelectricity.components.client.gui.GuiElectricFurnace;
|
||||
import universalelectricity.components.common.CommonProxy;
|
||||
import universalelectricity.components.common.tileentity.TileEntityBatteryBox;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCoalGenerator;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCopperWire;
|
||||
import universalelectricity.components.common.tileentity.TileEntityElectricFurnace;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
@Override
|
||||
public void preInit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCopperWire.class, new RenderCopperWire());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
switch (ID)
|
||||
{
|
||||
case 0:
|
||||
return new GuiBatteryBox(player.inventory, ((TileEntityBatteryBox) tileEntity));
|
||||
case 1:
|
||||
return new GuiCoalGenerator(player.inventory, ((TileEntityCoalGenerator) tileEntity));
|
||||
case 2:
|
||||
return new GuiElectricFurnace(player.inventory, ((TileEntityElectricFurnace) tileEntity));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package universalelectricity.components.client;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ModelCopperWire extends ModelBase
|
||||
{
|
||||
// fields
|
||||
ModelRenderer Middle;
|
||||
ModelRenderer Right;
|
||||
ModelRenderer Left;
|
||||
ModelRenderer Back;
|
||||
ModelRenderer Front;
|
||||
ModelRenderer Top;
|
||||
ModelRenderer Bottom;
|
||||
|
||||
public ModelCopperWire()
|
||||
{
|
||||
textureWidth = 64;
|
||||
textureHeight = 32;
|
||||
Middle = new ModelRenderer(this, 0, 0);
|
||||
Middle.addBox(-1F, -1F, -1F, 4, 4, 4);
|
||||
Middle.setRotationPoint(-1F, 15F, -1F);
|
||||
Middle.setTextureSize(64, 32);
|
||||
Middle.mirror = true;
|
||||
setRotation(Middle, 0F, 0F, 0F);
|
||||
Right = new ModelRenderer(this, 21, 0);
|
||||
Right.addBox(0F, 0F, 0F, 6, 4, 4);
|
||||
Right.setRotationPoint(2F, 14F, -2F);
|
||||
Right.setTextureSize(64, 32);
|
||||
Right.mirror = true;
|
||||
setRotation(Right, 0F, 0F, 0F);
|
||||
Left = new ModelRenderer(this, 21, 0);
|
||||
Left.addBox(0F, 0F, 0F, 6, 4, 4);
|
||||
Left.setRotationPoint(-8F, 14F, -2F);
|
||||
Left.setTextureSize(64, 32);
|
||||
Left.mirror = true;
|
||||
setRotation(Left, 0F, 0F, 0F);
|
||||
Back = new ModelRenderer(this, 0, 11);
|
||||
Back.addBox(0F, 0F, 0F, 4, 4, 6);
|
||||
Back.setRotationPoint(-2F, 14F, 2F);
|
||||
Back.setTextureSize(64, 32);
|
||||
Back.mirror = true;
|
||||
setRotation(Back, 0F, 0F, 0F);
|
||||
Front = new ModelRenderer(this, 0, 11);
|
||||
Front.addBox(0F, 0F, 0F, 4, 4, 6);
|
||||
Front.setRotationPoint(-2F, 14F, -8F);
|
||||
Front.setTextureSize(64, 32);
|
||||
Front.mirror = true;
|
||||
setRotation(Front, 0F, 0F, 0F);
|
||||
Top = new ModelRenderer(this, 21, 11);
|
||||
Top.addBox(0F, 0F, 0F, 4, 6, 4);
|
||||
Top.setRotationPoint(-2F, 8F, -2F);
|
||||
Top.setTextureSize(64, 32);
|
||||
Top.mirror = true;
|
||||
setRotation(Top, 0F, 0F, 0F);
|
||||
Bottom = new ModelRenderer(this, 21, 11);
|
||||
Bottom.addBox(0F, 0F, 0F, 4, 6, 4);
|
||||
Bottom.setRotationPoint(-2F, 18F, -2F);
|
||||
Bottom.setTextureSize(64, 32);
|
||||
Bottom.mirror = true;
|
||||
setRotation(Bottom, 0F, 0F, 0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
|
||||
{
|
||||
super.render(entity, f, f1, f2, f3, f4, f5);
|
||||
this.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
|
||||
this.renderMiddle();
|
||||
this.renderBottom();
|
||||
this.renderTop();
|
||||
this.renderLeft();
|
||||
this.renderRight();
|
||||
this.renderBack();
|
||||
this.renderFront();
|
||||
}
|
||||
|
||||
public void renderMiddle()
|
||||
{
|
||||
Middle.render(0.0625F);
|
||||
}
|
||||
|
||||
public void renderBottom()
|
||||
{
|
||||
Bottom.render(0.0625F);
|
||||
}
|
||||
|
||||
public void renderTop()
|
||||
{
|
||||
Top.render(0.0625F);
|
||||
}
|
||||
|
||||
public void renderLeft()
|
||||
{
|
||||
Left.render(0.0625F);
|
||||
}
|
||||
|
||||
public void renderRight()
|
||||
{
|
||||
Right.render(0.0625F);
|
||||
}
|
||||
|
||||
public void renderBack()
|
||||
{
|
||||
Back.render(0.0625F);
|
||||
}
|
||||
|
||||
public void renderFront()
|
||||
{
|
||||
Front.render(0.0625F);
|
||||
}
|
||||
|
||||
private void setRotation(ModelRenderer model, float x, float y, float z)
|
||||
{
|
||||
model.rotateAngleX = x;
|
||||
model.rotateAngleY = y;
|
||||
model.rotateAngleZ = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotationAngles(float x, float y, float z, float f3, float f4, float f5, Entity entity)
|
||||
{
|
||||
super.setRotationAngles(x, y, z, f3, f4, f5, entity);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package universalelectricity.components.client;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCopperWire;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderCopperWire extends TileEntitySpecialRenderer
|
||||
{
|
||||
private ModelCopperWire model;
|
||||
|
||||
public RenderCopperWire()
|
||||
{
|
||||
model = new ModelCopperWire();
|
||||
}
|
||||
|
||||
public void renderAModelAt(TileEntityCopperWire tileEntity, double d, double d1, double d2, float f)
|
||||
{
|
||||
// Texture file
|
||||
this.bindTextureByName(BasicComponents.MODEL_TEXTURE_DIRECTORY + "copperWire.png");
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
|
||||
GL11.glScalef(1.0F, -1F, -1F);
|
||||
|
||||
if (tileEntity.visuallyConnected[0])
|
||||
{
|
||||
model.renderBottom();
|
||||
}
|
||||
|
||||
if (tileEntity.visuallyConnected[1])
|
||||
{
|
||||
model.renderTop();
|
||||
}
|
||||
|
||||
if (tileEntity.visuallyConnected[2])
|
||||
{
|
||||
model.renderBack();
|
||||
}
|
||||
|
||||
if (tileEntity.visuallyConnected[3])
|
||||
{
|
||||
model.renderFront();
|
||||
}
|
||||
|
||||
if (tileEntity.visuallyConnected[4])
|
||||
{
|
||||
model.renderLeft();
|
||||
}
|
||||
|
||||
if (tileEntity.visuallyConnected[5])
|
||||
{
|
||||
model.renderRight();
|
||||
}
|
||||
|
||||
model.renderMiddle();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
|
||||
{
|
||||
this.renderAModelAt((TileEntityCopperWire) tileEntity, var2, var4, var6, var8);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package universalelectricity.components.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.container.ContainerBatteryBox;
|
||||
import universalelectricity.components.common.tileentity.TileEntityBatteryBox;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBatteryBox extends GuiContainer
|
||||
{
|
||||
private TileEntityBatteryBox tileEntity;
|
||||
|
||||
private int containerWidth;
|
||||
private int containerHeight;
|
||||
|
||||
public GuiBatteryBox(InventoryPlayer par1InventoryPlayer, TileEntityBatteryBox batteryBox)
|
||||
{
|
||||
super(new ContainerBatteryBox(par1InventoryPlayer, batteryBox));
|
||||
this.tileEntity = batteryBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the foreground layer for the GuiContainer (everything in front of the items)
|
||||
*/
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
{
|
||||
this.fontRenderer.drawString(this.tileEntity.getInvName(), 65, 6, 4210752);
|
||||
String displayJoules = ElectricityDisplay.getDisplayShort(tileEntity.getJoules(), ElectricUnit.JOULES);
|
||||
String displayMaxJoules = ElectricityDisplay.getDisplay(tileEntity.getMaxJoules(), ElectricUnit.JOULES);
|
||||
|
||||
if (this.tileEntity.isDisabled())
|
||||
{
|
||||
displayMaxJoules = "Disabled";
|
||||
}
|
||||
|
||||
this.fontRenderer.drawString(displayJoules + " of", 98 - displayJoules.length(), 30, 4210752);
|
||||
this.fontRenderer.drawString(displayMaxJoules, 78, 40, 4210752);
|
||||
this.fontRenderer.drawString("Voltage: " + (int) this.tileEntity.getVoltage(), 90, 60, 4210752);
|
||||
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the background layer for the GuiContainer (everything behind the items)
|
||||
*/
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
|
||||
{
|
||||
this.mc.renderEngine.func_98187_b(BasicComponents.GUI_DIRECTORY + "battery_box.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.containerWidth = (this.width - this.xSize) / 2;
|
||||
this.containerHeight = (this.height - this.ySize) / 2;
|
||||
// Background energy bar
|
||||
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
|
||||
// Foreground energy bar
|
||||
int scale = (int) (((double) this.tileEntity.getJoules() / this.tileEntity.getMaxJoules()) * 72);
|
||||
this.drawTexturedModalRect(containerWidth + 87, containerHeight + 52, 176, 0, scale, 20);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package universalelectricity.components.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.container.ContainerCoalGenerator;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCoalGenerator;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiCoalGenerator extends GuiContainer
|
||||
{
|
||||
private TileEntityCoalGenerator tileEntity;
|
||||
|
||||
private int containerWidth;
|
||||
private int containerHeight;
|
||||
|
||||
public GuiCoalGenerator(InventoryPlayer par1InventoryPlayer, TileEntityCoalGenerator tileEntity)
|
||||
{
|
||||
super(new ContainerCoalGenerator(par1InventoryPlayer, tileEntity));
|
||||
this.tileEntity = tileEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the foreground layer for the GuiContainer (everything in front of the items)
|
||||
*/
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
{
|
||||
this.fontRenderer.drawString(this.tileEntity.getInvName(), 55, 6, 4210752);
|
||||
this.fontRenderer.drawString("Generating", 90, 33, 4210752);
|
||||
String displayText = "";
|
||||
|
||||
if (this.tileEntity.isDisabled())
|
||||
{
|
||||
displayText = "Disabled";
|
||||
}
|
||||
else if (this.tileEntity.generateWatts <= 0)
|
||||
{
|
||||
displayText = "Not Generating";
|
||||
}
|
||||
else if (this.tileEntity.generateWatts < this.tileEntity.MIN_GENERATE_WATTS)
|
||||
{
|
||||
displayText = "Hull Heat: " + (int) (this.tileEntity.generateWatts / this.tileEntity.MIN_GENERATE_WATTS * 100) + "%";
|
||||
}
|
||||
else
|
||||
{
|
||||
displayText = ElectricityDisplay.getDisplay(tileEntity.generateWatts, ElectricUnit.WATT);
|
||||
}
|
||||
|
||||
this.fontRenderer.drawString(displayText, (int) (100 - displayText.length() * 1.25), 45, 4210752);
|
||||
this.fontRenderer.drawString("Voltage: " + (int) this.tileEntity.getVoltage(), 85, 60, 4210752);
|
||||
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the background layer for the GuiContainer (everything behind the items)
|
||||
*/
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
|
||||
{
|
||||
this.mc.renderEngine.func_98187_b(BasicComponents.GUI_DIRECTORY + "coal_generator.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
containerWidth = (this.width - this.xSize) / 2;
|
||||
containerHeight = (this.height - this.ySize) / 2;
|
||||
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package universalelectricity.components.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.container.ContainerElectricFurnace;
|
||||
import universalelectricity.components.common.tileentity.TileEntityElectricFurnace;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiElectricFurnace extends GuiContainer
|
||||
{
|
||||
private TileEntityElectricFurnace tileEntity;
|
||||
|
||||
private int containerWidth;
|
||||
private int containerHeight;
|
||||
|
||||
public GuiElectricFurnace(InventoryPlayer par1InventoryPlayer, TileEntityElectricFurnace tileEntity)
|
||||
{
|
||||
super(new ContainerElectricFurnace(par1InventoryPlayer, tileEntity));
|
||||
this.tileEntity = tileEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the foreground layer for the GuiContainer (everything in front of the items)
|
||||
*/
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
{
|
||||
this.fontRenderer.drawString(this.tileEntity.getInvName(), 60, 6, 4210752);
|
||||
this.fontRenderer.drawString("Smelting:", 10, 28, 4210752);
|
||||
this.fontRenderer.drawString("Battery:", 10, 53, 4210752);
|
||||
String displayText = "";
|
||||
|
||||
if (this.tileEntity.isDisabled())
|
||||
{
|
||||
displayText = "Disabled!";
|
||||
}
|
||||
else if (this.tileEntity.processTicks > 0)
|
||||
{
|
||||
displayText = "Smelting";
|
||||
}
|
||||
else
|
||||
{
|
||||
displayText = "Idle";
|
||||
}
|
||||
|
||||
this.fontRenderer.drawString("Status: " + displayText, 82, 45, 4210752);
|
||||
this.fontRenderer.drawString(ElectricityDisplay.getDisplay(this.tileEntity.WATTS_PER_TICK * 20, ElectricUnit.WATT), 82, 56, 4210752);
|
||||
this.fontRenderer.drawString(ElectricityDisplay.getDisplay(this.tileEntity.getVoltage(), ElectricUnit.VOLTAGE), 82, 68, 4210752);
|
||||
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the background layer for the GuiContainer (everything behind the items)
|
||||
*/
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
|
||||
{
|
||||
this.mc.renderEngine.func_98187_b(BasicComponents.GUI_DIRECTORY + "electric_furnace.png");
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
containerWidth = (this.width - this.xSize) / 2;
|
||||
containerHeight = (this.height - this.ySize) / 2;
|
||||
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
if (this.tileEntity.processTicks > 0)
|
||||
{
|
||||
int scale = (int) (((double) this.tileEntity.processTicks / (double) this.tileEntity.PROCESS_TIME_REQUIRED) * 23);
|
||||
this.drawTexturedModalRect(containerWidth + 77, containerHeight + 24, 176, 0, 23 - scale, 20);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package universalelectricity.components.common;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import universalelectricity.components.common.block.BlockBCOre;
|
||||
import universalelectricity.components.common.block.BlockBasicMachine;
|
||||
import universalelectricity.components.common.block.BlockCopperWire;
|
||||
import universalelectricity.components.common.item.ItemBasic;
|
||||
import universalelectricity.components.common.item.ItemBattery;
|
||||
import universalelectricity.components.common.item.ItemBlockBCOre;
|
||||
import universalelectricity.components.common.item.ItemBlockBasicMachine;
|
||||
import universalelectricity.components.common.item.ItemBlockCopperWire;
|
||||
import universalelectricity.components.common.item.ItemCircuit;
|
||||
import universalelectricity.components.common.item.ItemInfiniteBattery;
|
||||
import universalelectricity.components.common.item.ItemWrench;
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.prefab.RecipeHelper;
|
||||
import universalelectricity.prefab.TranslationHelper;
|
||||
import universalelectricity.prefab.network.ConnectionHandler;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import universalelectricity.prefab.ore.OreGenReplaceStone;
|
||||
import universalelectricity.prefab.ore.OreGenerator;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.Init;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.Mod.PreInit;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = BasicComponents.CHANNEL, name = BasicComponents.NAME, version = UniversalElectricity.VERSION)
|
||||
@NetworkMod(channels = BasicComponents.CHANNEL, clientSideRequired = true, serverSideRequired = false, connectionHandler = ConnectionHandler.class, packetHandler = PacketManager.class)
|
||||
public class BCLoader
|
||||
{
|
||||
private static final String[] LANGUAGES_SUPPORTED = new String[] { "en_US", "zh_CN", "es_ES", "it_IT", "nl_NL", "de_DE" };
|
||||
|
||||
@Instance("BasicComponents")
|
||||
public static BCLoader instance;
|
||||
|
||||
@SidedProxy(clientSide = "universalelectricity.components.client.ClientProxy", serverSide = "universalelectricity.components.common.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@PreInit
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
|
||||
|
||||
/**
|
||||
* Define the items and blocks.
|
||||
*/
|
||||
UniversalElectricity.CONFIGURATION.load();
|
||||
BasicComponents.blockBasicOre = new BlockBCOre(UniversalElectricity.CONFIGURATION.getBlock("Copper and Tin Ores", BasicComponents.BLOCK_ID_PREFIX + 0).getInt());
|
||||
BasicComponents.blockCopperWire = new BlockCopperWire(UniversalElectricity.CONFIGURATION.getBlock("Copper_Wire", BasicComponents.BLOCK_ID_PREFIX + 1).getInt());
|
||||
BasicComponents.blockMachine = new BlockBasicMachine(UniversalElectricity.CONFIGURATION.getBlock("Basic Machine", BasicComponents.BLOCK_ID_PREFIX + 4).getInt(), 0);
|
||||
|
||||
BasicComponents.itemInfiniteBattery = new ItemInfiniteBattery(UniversalElectricity.CONFIGURATION.getItem("Infinite Battery", BasicComponents.ITEM_ID_PREFIX + 0).getInt());
|
||||
BasicComponents.itemBattery = new ItemBattery(UniversalElectricity.CONFIGURATION.getItem("Battery", BasicComponents.ITEM_ID_PREFIX + 1).getInt());
|
||||
BasicComponents.itemWrench = new ItemWrench(UniversalElectricity.CONFIGURATION.getItem("Universal Wrench", BasicComponents.ITEM_ID_PREFIX + 2).getInt(), 20);
|
||||
BasicComponents.itemCircuit = new ItemCircuit(UniversalElectricity.CONFIGURATION.getItem("Circuit", BasicComponents.ITEM_ID_PREFIX + 3).getInt(), 16);
|
||||
|
||||
BasicComponents.itemBronzeDust = new ItemBasic("dustBronze", UniversalElectricity.CONFIGURATION.getItem("Bronze Dust", BasicComponents.ITEM_ID_PREFIX + 8).getInt());
|
||||
BasicComponents.itemSteelDust = new ItemBasic("dustSteel", UniversalElectricity.CONFIGURATION.getItem("Steel Dust", BasicComponents.ITEM_ID_PREFIX + 9).getInt());
|
||||
|
||||
BasicComponents.itemMotor = new ItemBasic("motor", UniversalElectricity.CONFIGURATION.getItem("Motor", BasicComponents.ITEM_ID_PREFIX + 14).getInt());
|
||||
|
||||
// Register Blocks
|
||||
GameRegistry.registerBlock(BasicComponents.blockBasicOre, ItemBlockBCOre.class, "Ore");
|
||||
GameRegistry.registerBlock(BasicComponents.blockMachine, ItemBlockBasicMachine.class, "Basic Machine");
|
||||
GameRegistry.registerBlock(BasicComponents.blockCopperWire, ItemBlockCopperWire.class, "Copper Wire");
|
||||
|
||||
BasicComponents.copperOreGeneration = new OreGenReplaceStone("Copper Ore", "oreCopper", new ItemStack(BasicComponents.blockBasicOre, 1, 0), 60, 26, 4).enable(UniversalElectricity.CONFIGURATION);
|
||||
BasicComponents.tinOreGeneration = new OreGenReplaceStone("Tin Ore", "oreTin", new ItemStack(BasicComponents.blockBasicOre, 1, 1), 60, 23, 4).enable(UniversalElectricity.CONFIGURATION);
|
||||
|
||||
UniversalElectricity.CONFIGURATION.save();
|
||||
|
||||
/**
|
||||
* Registering all Basic Component items into the Forge Ore Dictionary.
|
||||
*/
|
||||
OreDictionary.registerOre("copperWire", BasicComponents.blockCopperWire);
|
||||
|
||||
OreDictionary.registerOre("coalGenerator", ((BlockBasicMachine) BasicComponents.blockMachine).getCoalGenerator());
|
||||
OreDictionary.registerOre("batteryBox", ((BlockBasicMachine) BasicComponents.blockMachine).getBatteryBox());
|
||||
OreDictionary.registerOre("electricFurnace", ((BlockBasicMachine) BasicComponents.blockMachine).getElectricFurnace());
|
||||
|
||||
OreDictionary.registerOre("battery", BasicComponents.itemBattery);
|
||||
OreDictionary.registerOre("wrench", BasicComponents.itemWrench);
|
||||
OreDictionary.registerOre("motor", BasicComponents.itemMotor);
|
||||
|
||||
OreDictionary.registerOre("basicCircuit", new ItemStack(BasicComponents.itemCircuit, 1, 0));
|
||||
OreDictionary.registerOre("advancedCircuit", new ItemStack(BasicComponents.itemCircuit, 1, 1));
|
||||
OreDictionary.registerOre("eliteCircuit", new ItemStack(BasicComponents.itemCircuit, 1, 2));
|
||||
|
||||
OreDictionary.registerOre("dustBronze", BasicComponents.itemBronzeDust);
|
||||
OreDictionary.registerOre("dustSteel", BasicComponents.itemSteelDust);
|
||||
|
||||
BasicComponents.requestIngots(0);
|
||||
BasicComponents.requestPlates(0);
|
||||
|
||||
proxy.preInit();
|
||||
}
|
||||
|
||||
@Init
|
||||
public void load(FMLInitializationEvent evt)
|
||||
{
|
||||
proxy.init();
|
||||
|
||||
System.out.println("Basic Components Loaded: " + TranslationHelper.loadLanguages(BasicComponents.LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " Languages.");
|
||||
|
||||
OreGenerator.addOre(BasicComponents.copperOreGeneration);
|
||||
OreGenerator.addOre(BasicComponents.tinOreGeneration);
|
||||
|
||||
// Recipe Registry
|
||||
// Motor
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemMotor), new Object[] { "@!@", "!#!", "@!@", '!', "ingotSteel", '#', Item.ingotIron, '@', "copperWire" }));
|
||||
// Wrench
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemWrench), new Object[] { " S ", " DS", "S ", 'S', "ingotSteel", 'D', Item.diamond }));
|
||||
// Battery Box
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(OreDictionary.getOres("batteryBox").get(0), new Object[] { "SSS", "BBB", "SSS", 'B', ElectricItemHelper.getUncharged(BasicComponents.itemBattery), 'S', "ingotSteel" }));
|
||||
// Coal Generator
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(OreDictionary.getOres("coalGenerator").get(0), new Object[] { "MMM", "MOM", "MCM", 'M', "ingotSteel", 'C', BasicComponents.itemMotor, 'O', Block.furnaceIdle }));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(OreDictionary.getOres("coalGenerator").get(0), new Object[] { "MMM", "MOM", "MCM", 'M', "ingotBronze", 'C', BasicComponents.itemMotor, 'O', Block.furnaceIdle }));
|
||||
// Electric Furnace
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(OreDictionary.getOres("electricFurnace").get(0), new Object[] { "SSS", "SCS", "SMS", 'S', "ingotSteel", 'C', BasicComponents.itemCircuit, 'M', BasicComponents.itemMotor }));
|
||||
// Copper
|
||||
FurnaceRecipes.smelting().addSmelting(BasicComponents.blockBasicOre.blockID, 0, OreDictionary.getOres("ingotCopper").get(0), 0.7f);
|
||||
// Copper Wire
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.blockCopperWire, 6), new Object[] { "!!!", "@@@", "!!!", '!', Block.cloth, '@', "ingotCopper" }));
|
||||
// Tin
|
||||
FurnaceRecipes.smelting().addSmelting(BasicComponents.blockBasicOre.blockID, 1, OreDictionary.getOres("ingotTin").get(0), 0.7f);
|
||||
// Battery
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemBattery), new Object[] { " T ", "TRT", "TCT", 'T', "ingotTin", 'R', Item.redstone, 'C', Item.coal }));
|
||||
// Steel
|
||||
RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemSteelDust), new Object[] { " C ", "CIC", " C ", 'C', new ItemStack(Item.coal, 1, 1), 'I', Item.ingotIron }), "Steel Dust", UniversalElectricity.CONFIGURATION, true);
|
||||
RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemSteelDust), new Object[] { " C ", "CIC", " C ", 'C', new ItemStack(Item.coal, 1, 0), 'I', Item.ingotIron }), "Steel Dust", UniversalElectricity.CONFIGURATION, true);
|
||||
GameRegistry.addSmelting(BasicComponents.itemSteelDust.itemID, OreDictionary.getOres("ingotSteel").get(0), 0.8f);
|
||||
// Bronze
|
||||
RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemBronzeDust), new Object[] { "!#!", '!', "ingotCopper", '#', "ingotTin" }), "Bronze Dust", UniversalElectricity.CONFIGURATION, true);
|
||||
GameRegistry.addSmelting(BasicComponents.itemBronzeDust.itemID, OreDictionary.getOres("ingotBronze").get(0), 0.6f);
|
||||
|
||||
// Circuit
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemCircuit, 1, 0), new Object[] { "!#!", "#@#", "!#!", '@', "plateBronze", '#', Item.redstone, '!', "copperWire" }));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemCircuit, 1, 0), new Object[] { "!#!", "#@#", "!#!", '@', "plateSteel", '#', Item.redstone, '!', "copperWire" }));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemCircuit, 1, 1), new Object[] { "@@@", "#?#", "@@@", '@', Item.redstone, '?', Item.diamond, '#', BasicComponents.itemCircuit }));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BasicComponents.itemCircuit, 1, 2), new Object[] { "@@@", "?#?", "@@@", '@', Item.ingotGold, '?', new ItemStack(BasicComponents.itemCircuit, 1, 1), '#', Block.blockLapis }));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package universalelectricity.components.common;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
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 universalelectricity.components.common.item.ItemIngot;
|
||||
import universalelectricity.components.common.item.ItemPlate;
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.core.item.ItemElectric;
|
||||
import universalelectricity.prefab.ore.OreGenBase;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* The main class for managing Basic Component items and blocks. Reference objects from this class
|
||||
* to add them to your recipes and such.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
||||
public class BasicComponents
|
||||
{
|
||||
public static final String NAME = "Basic Components";
|
||||
public static final String CHANNEL = "BasicComponents";
|
||||
|
||||
public static final String RESOURCE_PATH = "/mods/basiccomponents/";
|
||||
|
||||
public static final CreativeTabs TAB = new TabBC(CreativeTabs.getNextID(), CHANNEL);
|
||||
|
||||
public static final String TEXTURE_DIRECTORY = RESOURCE_PATH + "textures/";
|
||||
public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/";
|
||||
public static final String BLOCK_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
|
||||
public static final String ITEM_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "items/";
|
||||
public static final String MODEL_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "models/";
|
||||
|
||||
public static final String TEXTURE_NAME_PREFIX = "basiccomponents:";
|
||||
|
||||
public static final String LANGUAGE_PATH = RESOURCE_PATH + "languages/";
|
||||
|
||||
public static int BLOCK_ID_PREFIX = 3970;
|
||||
|
||||
public static Block blockBasicOre;
|
||||
public static Block blockCopperWire;
|
||||
public static Block blockMachine;
|
||||
|
||||
public static final int ITEM_ID_PREFIX = 13970;
|
||||
public static ItemElectric itemBattery;
|
||||
public static Item itemInfiniteBattery;
|
||||
public static Item itemWrench;
|
||||
public static Item itemCircuit;
|
||||
public static Item itemBronzeDust;
|
||||
public static Item itemMotor;
|
||||
public static Item itemPlate;
|
||||
public static Item itemIngot;
|
||||
public static Item itemSteelDust;
|
||||
|
||||
public static OreGenBase copperOreGeneration;
|
||||
public static OreGenBase tinOreGeneration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param itemName: Steel, Bronze Copper, Tin
|
||||
* @return
|
||||
*/
|
||||
public static void requestPlates(int id)
|
||||
{
|
||||
if (BasicComponents.itemPlate == null)
|
||||
{
|
||||
UniversalElectricity.CONFIGURATION.load();
|
||||
itemPlate = new ItemPlate(UniversalElectricity.CONFIGURATION.getItem("Plates", BasicComponents.ITEM_ID_PREFIX + 13).getInt());
|
||||
OreDictionary.registerOre("ingotIron", Item.ingotIron);
|
||||
OreDictionary.registerOre("ingotGold", Item.ingotGold);
|
||||
|
||||
for (int i = 0; i < ItemPlate.TYPES.length; i++)
|
||||
{
|
||||
String plateName = ItemPlate.TYPES[i];
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlate, 1, i), new Object[] { "!!", "!!", '!', plateName.replaceAll("plate", "ingot") }));
|
||||
|
||||
if (plateName.equals("ingotIron"))
|
||||
{
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(Item.ingotIron, new Object[] { new ItemStack(itemPlate, 1, i) }));
|
||||
}
|
||||
else if (plateName.equals("ingotGold"))
|
||||
{
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(Item.ingotGold, new Object[] { new ItemStack(itemPlate, 1, i) }));
|
||||
}
|
||||
|
||||
OreDictionary.registerOre(plateName, new ItemStack(itemPlate, 1, i));
|
||||
}
|
||||
|
||||
UniversalElectricity.CONFIGURATION.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void requestIngots(int id)
|
||||
{
|
||||
if (BasicComponents.itemIngot == null)
|
||||
{
|
||||
UniversalElectricity.CONFIGURATION.load();
|
||||
BasicComponents.itemIngot = new ItemIngot(UniversalElectricity.CONFIGURATION.getItem("Ingots", BasicComponents.ITEM_ID_PREFIX + 4).getInt());
|
||||
|
||||
for (int i = 0; i < ItemIngot.TYPES.length; i++)
|
||||
{
|
||||
String itemName = ItemIngot.TYPES[i];
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(itemIngot, 1, i), new Object[] { itemName.replaceAll("ingot", "plate") }));
|
||||
OreDictionary.registerOre(itemName, new ItemStack(itemIngot, 1, i));
|
||||
}
|
||||
|
||||
UniversalElectricity.CONFIGURATION.save();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package universalelectricity.components.common;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.components.common.container.ContainerBatteryBox;
|
||||
import universalelectricity.components.common.container.ContainerCoalGenerator;
|
||||
import universalelectricity.components.common.container.ContainerElectricFurnace;
|
||||
import universalelectricity.components.common.tileentity.TileEntityBatteryBox;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCoalGenerator;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCopperWire;
|
||||
import universalelectricity.components.common.tileentity.TileEntityElectricFurnace;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class CommonProxy implements IGuiHandler
|
||||
{
|
||||
public void preInit()
|
||||
{
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
/**
|
||||
* Registering Tile Entities
|
||||
*/
|
||||
GameRegistry.registerTileEntity(TileEntityBatteryBox.class, "UEBatteryBox");
|
||||
GameRegistry.registerTileEntity(TileEntityCoalGenerator.class, "UECoalGenerator");
|
||||
GameRegistry.registerTileEntity(TileEntityElectricFurnace.class, "UEElectricFurnace");
|
||||
GameRegistry.registerTileEntity(TileEntityCopperWire.class, "UECopperWire");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
switch (ID)
|
||||
{
|
||||
case 0:
|
||||
return new ContainerBatteryBox(player.inventory, ((TileEntityBatteryBox) tileEntity));
|
||||
case 1:
|
||||
return new ContainerCoalGenerator(player.inventory, ((TileEntityCoalGenerator) tileEntity));
|
||||
case 2:
|
||||
return new ContainerElectricFurnace(player.inventory, ((TileEntityElectricFurnace) tileEntity));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package universalelectricity.components.common;
|
||||
|
||||
import universalelectricity.components.common.block.BlockBasicMachine;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class TabBC extends CreativeTabs
|
||||
{
|
||||
public TabBC(int par1, String par2Str)
|
||||
{
|
||||
super(par1, par2Str);
|
||||
}
|
||||
|
||||
public ItemStack getIconItemStack()
|
||||
{
|
||||
return new ItemStack(BasicComponents.blockMachine, 1, BlockBasicMachine.BATTERY_BOX_METADATA);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package universalelectricity.components.common.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Icon;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
|
||||
public class BlockBCOre extends Block
|
||||
{
|
||||
private Icon iconCopper;
|
||||
private Icon iconTin;
|
||||
|
||||
public BlockBCOre(int id)
|
||||
{
|
||||
super(id, Material.rock);
|
||||
this.setCreativeTab(BasicComponents.TAB);
|
||||
this.setUnlocalizedName("bcOre");
|
||||
this.setHardness(2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getBlockTextureFromSideAndMetadata(int side, int metadata)
|
||||
{
|
||||
if (metadata == 1)
|
||||
{
|
||||
return this.iconTin;
|
||||
}
|
||||
|
||||
return this.iconCopper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_94332_a(IconRegister par1IconRegister)
|
||||
{
|
||||
this.iconCopper = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "oreCopper");
|
||||
this.iconTin = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "oreTin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int metadata)
|
||||
{
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(new ItemStack(par1, 1, 0));
|
||||
par3List.add(new ItemStack(par1, 1, 1));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,385 @@
|
|||
package universalelectricity.components.common.block;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
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.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.components.common.BCLoader;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.tileentity.TileEntityBatteryBox;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCoalGenerator;
|
||||
import universalelectricity.components.common.tileentity.TileEntityElectricFurnace;
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.prefab.block.BlockAdvanced;
|
||||
|
||||
public class BlockBasicMachine extends BlockAdvanced
|
||||
{
|
||||
public static final int COAL_GENERATOR_METADATA = 0;
|
||||
public static final int BATTERY_BOX_METADATA = 4;
|
||||
public static final int ELECTRIC_FURNACE_METADATA = 8;
|
||||
|
||||
private Icon iconMachineSide;
|
||||
private Icon iconInput;
|
||||
private Icon iconOutput;
|
||||
|
||||
private Icon iconCoalGenerator;
|
||||
private Icon iconBatteryBox;
|
||||
private Icon iconElectricFurnace;
|
||||
|
||||
public BlockBasicMachine(int id, int textureIndex)
|
||||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
this.setUnlocalizedName("bcMachine");
|
||||
this.setCreativeTab(BasicComponents.TAB);
|
||||
this.setStepSound(soundMetalFootstep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_94332_a(IconRegister par1IconRegister)
|
||||
{
|
||||
this.field_94336_cN = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "machine");
|
||||
this.iconInput = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "machine_input");
|
||||
this.iconOutput = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "machine_output");
|
||||
|
||||
this.iconMachineSide = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "machine_side");
|
||||
this.iconCoalGenerator = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "coalGenerator");
|
||||
this.iconBatteryBox = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "batteryBox");
|
||||
this.iconElectricFurnace = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + "electricFurnace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(World par1World, int x, int y, int z, Random par5Random)
|
||||
{
|
||||
TileEntity tile = par1World.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TileEntityCoalGenerator)
|
||||
{
|
||||
TileEntityCoalGenerator tileEntity = (TileEntityCoalGenerator) tile;
|
||||
if (tileEntity.generateWatts > 0)
|
||||
{
|
||||
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||
float var7 = (float) x + 0.5F;
|
||||
float var8 = (float) y + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
|
||||
float var9 = (float) z + 0.5F;
|
||||
float var10 = 0.52F;
|
||||
float var11 = par5Random.nextFloat() * 0.6F - 0.3F;
|
||||
|
||||
if (metadata == 3)
|
||||
{
|
||||
par1World.spawnParticle("smoke", (double) (var7 - var10), (double) var8, (double) (var9 + var11), 0.0D, 0.0D, 0.0D);
|
||||
par1World.spawnParticle("flame", (double) (var7 - var10), (double) var8, (double) (var9 + var11), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
else if (metadata == 2)
|
||||
{
|
||||
par1World.spawnParticle("smoke", (double) (var7 + var10), (double) var8, (double) (var9 + var11), 0.0D, 0.0D, 0.0D);
|
||||
par1World.spawnParticle("flame", (double) (var7 + var10), (double) var8, (double) (var9 + var11), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
else if (metadata == 1)
|
||||
{
|
||||
par1World.spawnParticle("smoke", (double) (var7 + var11), (double) var8, (double) (var9 - var10), 0.0D, 0.0D, 0.0D);
|
||||
par1World.spawnParticle("flame", (double) (var7 + var11), (double) var8, (double) (var9 - var10), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
else if (metadata == 0)
|
||||
{
|
||||
par1World.spawnParticle("smoke", (double) (var7 + var11), (double) var8, (double) (var9 + var10), 0.0D, 0.0D, 0.0D);
|
||||
par1World.spawnParticle("flame", (double) (var7 + var11), (double) var8, (double) (var9 + var10), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getBlockTextureFromSideAndMetadata(int side, int metadata)
|
||||
{
|
||||
|
||||
if (side == 0 || side == 1)
|
||||
{
|
||||
return this.field_94336_cN;
|
||||
}
|
||||
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
metadata -= ELECTRIC_FURNACE_METADATA;
|
||||
|
||||
// If it is the front side
|
||||
if (side == metadata + 2)
|
||||
{
|
||||
return this.iconInput;
|
||||
}
|
||||
// If it is the back side
|
||||
else if (side == ForgeDirection.getOrientation(metadata + 2).getOpposite().ordinal())
|
||||
{
|
||||
return this.iconElectricFurnace;
|
||||
}
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
metadata -= BATTERY_BOX_METADATA;
|
||||
|
||||
// If it is the front side
|
||||
if (side == metadata + 2)
|
||||
{
|
||||
return this.iconOutput;
|
||||
}
|
||||
// If it is the back side
|
||||
else if (side == ForgeDirection.getOrientation(metadata + 2).getOpposite().ordinal())
|
||||
{
|
||||
return this.iconInput;
|
||||
}
|
||||
|
||||
return this.iconBatteryBox;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If it is the front side
|
||||
if (side == metadata + 2)
|
||||
{
|
||||
return this.iconOutput;
|
||||
}
|
||||
// If it is the back side
|
||||
else if (side == ForgeDirection.getOrientation(metadata + 2).getOpposite().ordinal())
|
||||
{
|
||||
return this.iconCoalGenerator;
|
||||
}
|
||||
}
|
||||
|
||||
return this.iconMachineSide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the block is placed in the world.
|
||||
*/
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack)
|
||||
{
|
||||
int metadata = world.getBlockMetadata(x, y, z);
|
||||
|
||||
int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
int change = 0;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 0:
|
||||
change = 1;
|
||||
break;
|
||||
case 1:
|
||||
change = 2;
|
||||
break;
|
||||
case 2:
|
||||
change = 0;
|
||||
break;
|
||||
case 3:
|
||||
change = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, ELECTRIC_FURNACE_METADATA + change, 3);
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
switch (angle)
|
||||
{
|
||||
case 0:
|
||||
change = 3;
|
||||
break;
|
||||
case 1:
|
||||
change = 1;
|
||||
break;
|
||||
case 2:
|
||||
change = 2;
|
||||
break;
|
||||
case 3:
|
||||
change = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, BATTERY_BOX_METADATA + change, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, COAL_GENERATOR_METADATA + change, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||
int original = metadata;
|
||||
|
||||
int change = 0;
|
||||
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
original -= ELECTRIC_FURNACE_METADATA;
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
original -= BATTERY_BOX_METADATA;
|
||||
}
|
||||
|
||||
// Re-orient the block
|
||||
switch (original)
|
||||
{
|
||||
case 0:
|
||||
change = 3;
|
||||
break;
|
||||
case 3:
|
||||
change = 1;
|
||||
break;
|
||||
case 1:
|
||||
change = 2;
|
||||
break;
|
||||
case 2:
|
||||
change = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
change += ELECTRIC_FURNACE_METADATA;
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
change += BATTERY_BOX_METADATA;
|
||||
}
|
||||
|
||||
par1World.setBlockMetadataWithNotify(x, y, z, change, 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the block is right clicked by the player
|
||||
*/
|
||||
@Override
|
||||
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||
|
||||
if (!par1World.isRemote)
|
||||
{
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
par5EntityPlayer.openGui(BCLoader.instance, 2, par1World, x, y, z);
|
||||
return true;
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
par5EntityPlayer.openGui(BCLoader.instance, 0, par1World, x, y, z);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
par5EntityPlayer.openGui(BCLoader.instance, 1, par1World, x, y, z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata)
|
||||
{
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
return new TileEntityElectricFurnace();
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
return new TileEntityBatteryBox();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TileEntityCoalGenerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ItemStack getCoalGenerator()
|
||||
{
|
||||
return new ItemStack(this.blockID, 1, COAL_GENERATOR_METADATA);
|
||||
}
|
||||
|
||||
public ItemStack getBatteryBox()
|
||||
{
|
||||
return new ItemStack(this.blockID, 1, BATTERY_BOX_METADATA);
|
||||
}
|
||||
|
||||
public ItemStack getElectricFurnace()
|
||||
{
|
||||
return new ItemStack(this.blockID, 1, ELECTRIC_FURNACE_METADATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(this.getCoalGenerator());
|
||||
par3List.add(this.getBatteryBox());
|
||||
par3List.add(this.getElectricFurnace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int metadata)
|
||||
{
|
||||
if (metadata >= ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
return ELECTRIC_FURNACE_METADATA;
|
||||
}
|
||||
else if (metadata >= BATTERY_BOX_METADATA)
|
||||
{
|
||||
return BATTERY_BOX_METADATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
return COAL_GENERATOR_METADATA;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
|
||||
{
|
||||
int id = idPicked(world, x, y, z);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Item item = Item.itemsList[id];
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int metadata = getDamageValue(world, x, y, z);
|
||||
|
||||
return new ItemStack(id, 1, metadata);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package universalelectricity.components.common.block;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCopperWire;
|
||||
import universalelectricity.prefab.block.BlockConductor;
|
||||
|
||||
public class BlockCopperWire extends BlockConductor
|
||||
{
|
||||
public BlockCopperWire(int id)
|
||||
{
|
||||
super(id, Material.cloth);
|
||||
this.setUnlocalizedName("copperWire");
|
||||
this.setStepSound(soundClothFootstep);
|
||||
this.setResistance(0.2F);
|
||||
this.setHardness(0.1f);
|
||||
this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
|
||||
this.setCreativeTab(BasicComponents.TAB);
|
||||
this.setBurnProperties(this.blockID, 30, 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_94332_a(IconRegister par1IconRegister)
|
||||
{
|
||||
this.field_94336_cN = par1IconRegister.func_94245_a(BasicComponents.TEXTURE_NAME_PREFIX + this.func_94330_A());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the
|
||||
* shared face of two adjacent blocks and also whether the player can attach torches, redstone
|
||||
* wire, etc to this block.
|
||||
*/
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this block doesn't render as an ordinary block it will return False (examples: signs,
|
||||
* buttons, stairs, etc)
|
||||
*/
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of render function that is called for this block
|
||||
*/
|
||||
@Override
|
||||
public int getRenderType()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return new TileEntityCopperWire();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package universalelectricity.components.common.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.components.common.tileentity.TileEntityBatteryBox;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.prefab.SlotSpecific;
|
||||
|
||||
public class ContainerBatteryBox extends Container
|
||||
{
|
||||
private TileEntityBatteryBox tileEntity;
|
||||
|
||||
public ContainerBatteryBox(InventoryPlayer par1InventoryPlayer, TileEntityBatteryBox batteryBox)
|
||||
{
|
||||
this.tileEntity = batteryBox;
|
||||
// Top slot for battery output
|
||||
this.addSlotToContainer(new SlotSpecific(batteryBox, 0, 33, 24, IItemElectric.class));
|
||||
// Bottom slot for batter input
|
||||
this.addSlotToContainer(new SlotSpecific(batteryBox, 1, 33, 48, IItemElectric.class));
|
||||
int var3;
|
||||
|
||||
for (var3 = 0; var3 < 3; ++var3)
|
||||
{
|
||||
for (int var4 = 0; var4 < 9; ++var4)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (var3 = 0; var3 < 9; ++var3)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
|
||||
}
|
||||
|
||||
tileEntity.openChest();
|
||||
}
|
||||
|
||||
public void onCraftGuiClosed(EntityPlayer entityplayer)
|
||||
{
|
||||
super.onCraftGuiClosed(entityplayer);
|
||||
tileEntity.closeChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotID)
|
||||
{
|
||||
ItemStack returnStack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotID);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemStack = slot.getStack();
|
||||
returnStack = itemStack.copy();
|
||||
|
||||
if (slotID != 0 && slotID != 1)
|
||||
{
|
||||
if (this.getSlot(0).isItemValid(itemStack))
|
||||
{
|
||||
if (((IItemElectric) itemStack.getItem()).getProvideRequest(itemStack).getWatts() > 0)
|
||||
{
|
||||
if (!this.mergeItemStack(itemStack, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.mergeItemStack(itemStack, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (slotID >= 30 && slotID < 38 && !this.mergeItemStack(itemStack, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemStack, 3, 38, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemStack.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemStack.stackSize == returnStack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(par1EntityPlayer, itemStack);
|
||||
}
|
||||
|
||||
return returnStack;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package universalelectricity.components.common.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCoalGenerator;
|
||||
|
||||
public class ContainerCoalGenerator extends Container
|
||||
{
|
||||
private TileEntityCoalGenerator tileEntity;
|
||||
|
||||
public ContainerCoalGenerator(InventoryPlayer par1InventoryPlayer, TileEntityCoalGenerator tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
this.addSlotToContainer(new Slot(tileEntity, 0, 33, 34));
|
||||
int var3;
|
||||
|
||||
for (var3 = 0; var3 < 3; ++var3)
|
||||
{
|
||||
for (int var4 = 0; var4 < 9; ++var4)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (var3 = 0; var3 < 9; ++var3)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
|
||||
}
|
||||
|
||||
tileEntity.openChest();
|
||||
}
|
||||
|
||||
public void onCraftGuiClosed(EntityPlayer entityplayer)
|
||||
{
|
||||
super.onCraftGuiClosed(entityplayer);
|
||||
tileEntity.closeChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1)
|
||||
{
|
||||
ItemStack var2 = null;
|
||||
Slot var3 = (Slot) this.inventorySlots.get(par1);
|
||||
|
||||
if (var3 != null && var3.getHasStack())
|
||||
{
|
||||
ItemStack var4 = var3.getStack();
|
||||
var2 = var4.copy();
|
||||
|
||||
if (par1 != 0)
|
||||
{
|
||||
if (var4.itemID == Item.coal.itemID)
|
||||
{
|
||||
if (!this.mergeItemStack(var4, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(var4, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(var4, 3, 37, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (var4.stackSize == 0)
|
||||
{
|
||||
var3.putStack((ItemStack) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
var3.onSlotChanged();
|
||||
}
|
||||
|
||||
if (var4.stackSize == var2.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var3.onPickupFromSlot(par1EntityPlayer, var4);
|
||||
}
|
||||
|
||||
return var2;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package universalelectricity.components.common.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotFurnace;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import universalelectricity.components.common.tileentity.TileEntityElectricFurnace;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.prefab.SlotSpecific;
|
||||
|
||||
public class ContainerElectricFurnace extends Container
|
||||
{
|
||||
private TileEntityElectricFurnace tileEntity;
|
||||
|
||||
public ContainerElectricFurnace(InventoryPlayer par1InventoryPlayer, TileEntityElectricFurnace tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
|
||||
// Electric Input Slot
|
||||
this.addSlotToContainer(new SlotSpecific(tileEntity, 0, 55, 49, IItemElectric.class));
|
||||
|
||||
// To be smelted
|
||||
this.addSlotToContainer(new Slot(tileEntity, 1, 55, 25));
|
||||
|
||||
// Smelting result
|
||||
this.addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, tileEntity, 2, 108, 25));
|
||||
int var3;
|
||||
|
||||
for (var3 = 0; var3 < 3; ++var3)
|
||||
{
|
||||
for (int var4 = 0; var4 < 9; ++var4)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (var3 = 0; var3 < 9; ++var3)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
|
||||
}
|
||||
|
||||
tileEntity.openChest();
|
||||
}
|
||||
|
||||
public void onCraftGuiClosed(EntityPlayer entityplayer)
|
||||
{
|
||||
super.onCraftGuiClosed(entityplayer);
|
||||
tileEntity.closeChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1)
|
||||
{
|
||||
ItemStack var2 = null;
|
||||
Slot var3 = (Slot) this.inventorySlots.get(par1);
|
||||
|
||||
if (var3 != null && var3.getHasStack())
|
||||
{
|
||||
ItemStack var4 = var3.getStack();
|
||||
var2 = var4.copy();
|
||||
|
||||
if (par1 == 2)
|
||||
{
|
||||
if (!this.mergeItemStack(var4, 3, 39, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var3.onSlotChange(var4, var2);
|
||||
}
|
||||
else if (par1 != 1 && par1 != 0)
|
||||
{
|
||||
if (var4.getItem() instanceof IItemElectric)
|
||||
{
|
||||
if (!this.mergeItemStack(var4, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (FurnaceRecipes.smelting().getSmeltingResult(var4) != null)
|
||||
{
|
||||
if (!this.mergeItemStack(var4, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (par1 >= 3 && par1 < 30)
|
||||
{
|
||||
if (!this.mergeItemStack(var4, 30, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (par1 >= 30 && par1 < 39 && !this.mergeItemStack(var4, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(var4, 3, 39, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (var4.stackSize == 0)
|
||||
{
|
||||
var3.putStack((ItemStack) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
var3.onSlotChanged();
|
||||
}
|
||||
|
||||
if (var4.stackSize == var2.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var3.onPickupFromSlot(par1EntityPlayer, var4);
|
||||
}
|
||||
|
||||
return var2;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Icon;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBasic extends Item
|
||||
{
|
||||
protected List<Icon> icons = new ArrayList<Icon>();
|
||||
|
||||
public ItemBasic(String name, int id)
|
||||
{
|
||||
super(id);
|
||||
this.setUnlocalizedName(name);
|
||||
this.setCreativeTab(BasicComponents.TAB);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void func_94581_a(IconRegister iconRegister)
|
||||
{
|
||||
List<ItemStack> list = new ArrayList<ItemStack>();
|
||||
this.getSubItems(this.itemID, this.getCreativeTab(), list);
|
||||
|
||||
if (list.size() > 0)
|
||||
{
|
||||
for (ItemStack itemStack : list)
|
||||
{
|
||||
this.icons.add(iconRegister.func_94245_a(this.getUnlocalizedName(itemStack).replace("item.", BasicComponents.TEXTURE_NAME_PREFIX)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.iconIndex = iconRegister.func_94245_a(this.getUnlocalizedName().replace("item.", BasicComponents.TEXTURE_NAME_PREFIX));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIconFromDamage(int damage)
|
||||
{
|
||||
if (this.icons.size() > damage)
|
||||
{
|
||||
return icons.get(damage);
|
||||
}
|
||||
|
||||
return super.getIconFromDamage(damage);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.core.item.ItemElectric;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBattery extends ItemElectric
|
||||
{
|
||||
public ItemBattery(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setUnlocalizedName("battery");
|
||||
this.setCreativeTab(BasicComponents.TAB);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void func_94581_a(IconRegister iconRegister)
|
||||
{
|
||||
this.iconIndex = iconRegister.func_94245_a(this.getUnlocalizedName().replace("item.", BasicComponents.TEXTURE_NAME_PREFIX));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules(ItemStack itemStack)
|
||||
{
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getVoltage(ItemStack itemStack)
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemBlockBCOre extends ItemBlock
|
||||
{
|
||||
private String[] ores = { "Copper Ore", "Tin Ore" };
|
||||
|
||||
public ItemBlockBCOre(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack par1ItemStack)
|
||||
{
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + (par1ItemStack.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + ".0";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.components.common.block.BlockBasicMachine;
|
||||
|
||||
public class ItemBlockBasicMachine extends ItemBlock
|
||||
{
|
||||
public ItemBlockBasicMachine(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemstack)
|
||||
{
|
||||
int metadata = 0;
|
||||
|
||||
if (itemstack.getItemDamage() >= BlockBasicMachine.ELECTRIC_FURNACE_METADATA)
|
||||
{
|
||||
metadata = 2;
|
||||
}
|
||||
else if (itemstack.getItemDamage() >= BlockBasicMachine.BATTERY_BOX_METADATA)
|
||||
{
|
||||
metadata = 1;
|
||||
}
|
||||
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + ".0";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.components.common.tileentity.TileEntityCopperWire;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
|
||||
public class ItemBlockCopperWire extends ItemBlock
|
||||
{
|
||||
public ItemBlockCopperWire(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||
{
|
||||
par3List.add("Resistance: " + ElectricityDisplay.getDisplay(TileEntityCopperWire.RESISTANCE, ElectricUnit.RESISTANCE));
|
||||
par3List.add("Max Amps: " + ElectricityDisplay.getDisplay(TileEntityCopperWire.MAX_AMPS, ElectricUnit.AMPERE));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemCircuit extends ItemBasic
|
||||
{
|
||||
public static final String[] TYPES = { "circuitBasic", "circuitAdvanced", "circuitElite" };
|
||||
|
||||
public ItemCircuit(int id, int texture)
|
||||
{
|
||||
super("circuit", id);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return "item." + TYPES[itemStack.getItemDamage()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List list)
|
||||
{
|
||||
for (int i = 0; i < TYPES.length; i++)
|
||||
{
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
|
||||
/**
|
||||
* An infinite battery used for players and modders to test things.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ItemInfiniteBattery extends ItemBasic implements IItemElectric
|
||||
{
|
||||
public ItemInfiniteBattery(int id)
|
||||
{
|
||||
super("infiniteBattery", id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setNoRepair();
|
||||
this.setCreativeTab(BasicComponents.TAB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||
{
|
||||
par3List.add("\u00a72 Infinite");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getJoules(ItemStack itemStack)
|
||||
{
|
||||
return this.getMaxJoules(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoules(double joules, ItemStack itemStack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules(ItemStack itemStack)
|
||||
{
|
||||
return Double.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getVoltage(ItemStack itemStack)
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack)
|
||||
{
|
||||
return electricityPack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack)
|
||||
{
|
||||
return electricityPack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getReceiveRequest(ItemStack itemStack)
|
||||
{
|
||||
return new ElectricityPack(Double.POSITIVE_INFINITY, this.getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getProvideRequest(ItemStack itemStack)
|
||||
{
|
||||
return new ElectricityPack(Double.POSITIVE_INFINITY, this.getVoltage(itemStack));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemIngot extends ItemBasic
|
||||
{
|
||||
public static final String[] TYPES = { "ingotCopper", "ingotTin", "ingotBronze", "ingotSteel" };
|
||||
|
||||
public ItemIngot(int id)
|
||||
{
|
||||
super("ingot", id);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return "item." + TYPES[itemStack.getItemDamage()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs creativeTabs, List list)
|
||||
{
|
||||
for (int i = 0; i < TYPES.length; i++)
|
||||
{
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemPlate extends ItemBasic
|
||||
{
|
||||
public static final String[] TYPES = { "plateCopper", "plateTin", "plateBronze", "plateSteel", "plateIron", "plateGold" };
|
||||
|
||||
public ItemPlate(int id)
|
||||
{
|
||||
super("plate", id);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return "item." + TYPES[itemStack.getItemDamage()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List list)
|
||||
{
|
||||
for (int i = 0; i < TYPES.length; i++)
|
||||
{
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package universalelectricity.components.common.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.prefab.implement.IToolConfigurator;
|
||||
|
||||
public class ItemWrench extends ItemBasic implements IToolConfigurator
|
||||
{
|
||||
public ItemWrench(int id, int texture)
|
||||
{
|
||||
super("wrench", id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrench(EntityPlayer entityPlayer, int x, int y, int z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wrenchUsed(EntityPlayer entityPlayer, int x, int y, int z)
|
||||
{
|
||||
if (entityPlayer.getCurrentEquippedItem() != null)
|
||||
{
|
||||
if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemWrench)
|
||||
{
|
||||
entityPlayer.getCurrentEquippedItem().damageItem(1, entityPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
int blockID = world.getBlockId(x, y, z);
|
||||
|
||||
if (blockID == Block.furnaceIdle.blockID || blockID == Block.furnaceBurning.blockID || blockID == Block.field_94340_cs.blockID || blockID == Block.field_96469_cy.blockID || blockID == Block.dispenser.blockID || blockID == Block.pistonBase.blockID || blockID == Block.pistonStickyBase.blockID)
|
||||
{
|
||||
int metadata = world.getBlockMetadata(x, y, z);
|
||||
|
||||
int[] rotationMatrix = { 1, 2, 3, 4, 5, 0 };
|
||||
|
||||
if (blockID == Block.furnaceIdle.blockID || blockID == Block.furnaceBurning.blockID)
|
||||
{
|
||||
rotationMatrix = ForgeDirection.ROTATION_MATRIX[0];
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(rotationMatrix[metadata]).ordinal(), 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldPassSneakingClickToBlock(World world, int x, int y, int z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,310 @@
|
|||
package universalelectricity.components.common.tileentity;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.ISidedInventory;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.block.BlockBasicMachine;
|
||||
import universalelectricity.core.block.IElectricityStorage;
|
||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import universalelectricity.prefab.tile.TileEntityElectricityStorage;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class TileEntityBatteryBox extends TileEntityElectricityStorage implements IElectricityStorage, IPacketReceiver, ISidedInventory
|
||||
{
|
||||
private ItemStack[] containingItems = new ItemStack[2];
|
||||
|
||||
private int playersUsing = 0;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!this.isDisabled())
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
/**
|
||||
* Recharges electric item.
|
||||
*/
|
||||
this.setJoules(this.getJoules() - ElectricItemHelper.chargeItem(this.containingItems[0], this.getJoules(), this.getVoltage()));
|
||||
|
||||
/**
|
||||
* Decharge electric item.
|
||||
*/
|
||||
this.setJoules(this.getJoules() + ElectricItemHelper.dechargeItem(this.containingItems[1], this.getMaxJoules() - this.getJoules(), this.getVoltage()));
|
||||
|
||||
ForgeDirection outputDirection = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.BATTERY_BOX_METADATA + 2);
|
||||
TileEntity inputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection.getOpposite());
|
||||
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
|
||||
|
||||
IElectricityNetwork inputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(inputTile, outputDirection.getOpposite());
|
||||
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
|
||||
|
||||
if (outputNetwork != null && inputNetwork != outputNetwork)
|
||||
{
|
||||
double outputWatts = Math.min(outputNetwork.getRequest(this).getWatts(), Math.min(this.getJoules(), 10000));
|
||||
|
||||
if (this.getJoules() > 0 && outputWatts > 0)
|
||||
{
|
||||
outputNetwork.startProducing(this, outputWatts / this.getVoltage(), this.getVoltage());
|
||||
this.setJoules(this.getJoules() - outputWatts);
|
||||
}
|
||||
else
|
||||
{
|
||||
outputNetwork.stopProducing(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gradually lose energy.
|
||||
*/
|
||||
this.setJoules(this.getJoules() - 0.00005);
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (this.ticks % 3 == 0 && this.playersUsing > 0)
|
||||
{
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket(), this.worldObj, new Vector3(this), 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return direction == ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.BATTERY_BOX_METADATA + 2) || direction == ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.BATTERY_BOX_METADATA + 2).getOpposite();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EnumSet<ForgeDirection> getConsumingSides()
|
||||
{
|
||||
return EnumSet.of(ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.BATTERY_BOX_METADATA + 2).getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
return PacketManager.getPacket(BasicComponents.CHANNEL, this, this.getJoules(), this.disabledTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.setJoules(dataStream.readDouble());
|
||||
this.disabledTicks = dataStream.readInt();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
this.playersUsing++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
this.playersUsing--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile entity from NBT.
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.readFromNBT(par1NBTTagCompound);
|
||||
|
||||
NBTTagList var2 = par1NBTTagCompound.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tile entity to NBT.
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.writeToNBT(par1NBTTagCompound);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
par1NBTTagCompound.setTag("Items", var2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartInventorySide(ForgeDirection side)
|
||||
{
|
||||
if (side == side.DOWN)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (side == side.UP)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventorySide(ForgeDirection side)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.containingItems.length;
|
||||
}
|
||||
|
||||
@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 String getInvName()
|
||||
{
|
||||
return LanguageRegistry.instance().getStringLocalization("tile.bcMachine.1.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@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 double getMaxJoules()
|
||||
{
|
||||
return 5000000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94042_c()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94041_b(int i, ItemStack itemstack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,355 @@
|
|||
package universalelectricity.components.common.tileentity;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
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.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.ISidedInventory;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.block.BlockBasicMachine;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class TileEntityCoalGenerator extends TileEntityElectrical implements IInventory, ISidedInventory, IPacketReceiver
|
||||
{
|
||||
/**
|
||||
* Maximum amount of energy needed to generate electricity
|
||||
*/
|
||||
public static final int MAX_GENERATE_WATTS = 10000;
|
||||
|
||||
/**
|
||||
* Amount of heat the coal generator needs before generating electricity.
|
||||
*/
|
||||
public static final int MIN_GENERATE_WATTS = 100;
|
||||
|
||||
private static final float BASE_ACCELERATION = 0.3f;
|
||||
|
||||
/**
|
||||
* Per second
|
||||
*/
|
||||
public double prevGenerateWatts, generateWatts = 0;
|
||||
|
||||
public IConductor connectedElectricUnit = null;
|
||||
/**
|
||||
* The number of ticks that a fresh copy of the currently-burning item would keep the furnace
|
||||
* burning for
|
||||
*/
|
||||
public int itemCookTime = 0;
|
||||
/**
|
||||
* The ItemStacks that hold the items currently being used in the battery box
|
||||
*/
|
||||
private ItemStack[] containingItems = new ItemStack[1];
|
||||
|
||||
private int playersUsing = 0;
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return direction == ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.COAL_GENERATOR_METADATA + 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
this.prevGenerateWatts = this.generateWatts;
|
||||
|
||||
// Check nearby blocks and see if the conductor is full. If so, then it is connected
|
||||
ForgeDirection outputDirection = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.COAL_GENERATOR_METADATA + 2);
|
||||
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this.xCoord, this.yCoord, this.zCoord), outputDirection);
|
||||
|
||||
IElectricityNetwork network = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
|
||||
|
||||
if (network != null)
|
||||
{
|
||||
if (network.getRequest().getWatts() > 0)
|
||||
{
|
||||
this.connectedElectricUnit = (IConductor) outputTile;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connectedElectricUnit = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connectedElectricUnit = null;
|
||||
}
|
||||
|
||||
if (!this.isDisabled())
|
||||
{
|
||||
if (this.itemCookTime > 0)
|
||||
{
|
||||
this.itemCookTime--;
|
||||
|
||||
if (this.connectedElectricUnit != null)
|
||||
{
|
||||
this.generateWatts = (double) Math.min(this.generateWatts + Math.min((this.generateWatts * 0.005 + BASE_ACCELERATION), 5), this.MAX_GENERATE_WATTS);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.containingItems[0] != null && this.connectedElectricUnit != null)
|
||||
{
|
||||
if (this.containingItems[0].getItem().itemID == Item.coal.itemID)
|
||||
{
|
||||
if (this.itemCookTime <= 0)
|
||||
{
|
||||
this.itemCookTime = 320;
|
||||
this.decrStackSize(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.connectedElectricUnit == null || this.itemCookTime <= 0)
|
||||
{
|
||||
this.generateWatts = (double) Math.max(this.generateWatts - 8, 0);
|
||||
}
|
||||
|
||||
if (this.connectedElectricUnit != null)
|
||||
{
|
||||
if (this.generateWatts > MIN_GENERATE_WATTS)
|
||||
{
|
||||
this.connectedElectricUnit.getNetwork().startProducing(this, (this.generateWatts / this.getVoltage()) / 20, this.getVoltage());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connectedElectricUnit.getNetwork().stopProducing(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.ticks % 3 == 0 && this.playersUsing > 0)
|
||||
{
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket(), this.worldObj, new Vector3(this), 12);
|
||||
}
|
||||
|
||||
if (this.prevGenerateWatts <= 0 && this.generateWatts > 0 || this.prevGenerateWatts > 0 && this.generateWatts <= 0)
|
||||
{
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket(), this.worldObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
return PacketManager.getPacket(BasicComponents.CHANNEL, this, this.generateWatts, this.itemCookTime, this.disabledTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
this.generateWatts = dataStream.readDouble();
|
||||
this.itemCookTime = dataStream.readInt();
|
||||
this.disabledTicks = dataStream.readInt();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket(), this.worldObj, new Vector3(this), 15);
|
||||
}
|
||||
|
||||
this.playersUsing++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
this.playersUsing--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile entity from NBT.
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.readFromNBT(par1NBTTagCompound);
|
||||
this.itemCookTime = par1NBTTagCompound.getInteger("itemCookTime");
|
||||
this.generateWatts = par1NBTTagCompound.getDouble("generateRate");
|
||||
NBTTagList var2 = par1NBTTagCompound.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tile entity to NBT.
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.writeToNBT(par1NBTTagCompound);
|
||||
par1NBTTagCompound.setInteger("itemCookTime", this.itemCookTime);
|
||||
par1NBTTagCompound.setDouble("generateRate", this.generateWatts);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
par1NBTTagCompound.setTag("Items", var2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartInventorySide(ForgeDirection side)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventorySide(ForgeDirection side)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.containingItems.length;
|
||||
}
|
||||
|
||||
@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 String getInvName()
|
||||
{
|
||||
return LanguageRegistry.instance().getStringLocalization("tile.bcMachine.0.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@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 boolean func_94042_c()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94041_b(int i, ItemStack itemstack)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package universalelectricity.components.common.tileentity;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.prefab.tile.TileEntityConductor;
|
||||
|
||||
public class TileEntityCopperWire extends TileEntityConductor
|
||||
{
|
||||
/**
|
||||
* Changed this if your mod wants to nerf Basic Component's copper wire.
|
||||
*/
|
||||
public static double RESISTANCE = 0.05;
|
||||
public static double MAX_AMPS = 200;
|
||||
|
||||
public TileEntityCopperWire()
|
||||
{
|
||||
this.channel = BasicComponents.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getResistance()
|
||||
{
|
||||
return RESISTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCurrentCapcity()
|
||||
{
|
||||
return MAX_AMPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (this.getNetwork() != null && this.ticks % 20 == 0)
|
||||
{
|
||||
if (this.getNetwork().getProduced().amperes > this.getCurrentCapcity())
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
this.worldObj.setBlockAndMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, Block.fire.blockID, 0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,392 @@
|
|||
package universalelectricity.components.common.tileentity;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
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.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.ISidedInventory;
|
||||
import universalelectricity.components.common.BasicComponents;
|
||||
import universalelectricity.components.common.block.BlockBasicMachine;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class TileEntityElectricFurnace extends TileEntityElectricityRunnable implements IInventory, ISidedInventory, IPacketReceiver
|
||||
{
|
||||
/**
|
||||
* The amount of watts required every TICK.
|
||||
*/
|
||||
public static final double WATTS_PER_TICK = 500;
|
||||
|
||||
/**
|
||||
* The amount of processing time required.
|
||||
*/
|
||||
public static final int PROCESS_TIME_REQUIRED = 130;
|
||||
|
||||
/**
|
||||
* The amount of ticks this machine has been processing.
|
||||
*/
|
||||
public int processTicks = 0;
|
||||
|
||||
/**
|
||||
* The ItemStacks that hold the items currently being used in the battery box
|
||||
*/
|
||||
private ItemStack[] containingItems = new ItemStack[3];
|
||||
|
||||
/**
|
||||
* The amount of players using the electric furnace.
|
||||
*/
|
||||
private int playersUsing = 0;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
/**
|
||||
* Attempts to charge using batteries.
|
||||
*/
|
||||
this.wattsReceived += ElectricItemHelper.dechargeItem(this.containingItems[0], WATTS_PER_TICK, this.getVoltage());
|
||||
|
||||
/**
|
||||
* Attempts to smelt an item.
|
||||
*/
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (this.canProcess())
|
||||
{
|
||||
if (this.wattsReceived >= this.WATTS_PER_TICK)
|
||||
{
|
||||
if (this.processTicks == 0)
|
||||
{
|
||||
this.processTicks = this.PROCESS_TIME_REQUIRED;
|
||||
}
|
||||
else if (this.processTicks > 0)
|
||||
{
|
||||
this.processTicks--;
|
||||
|
||||
/**
|
||||
* Process the item when the process timer is done.
|
||||
*/
|
||||
if (this.processTicks < 1)
|
||||
{
|
||||
this.smeltItem();
|
||||
this.processTicks = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.processTicks = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.processTicks = 0;
|
||||
}
|
||||
|
||||
this.wattsReceived = Math.max(this.wattsReceived - WATTS_PER_TICK / 4, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.processTicks = 0;
|
||||
}
|
||||
|
||||
if (this.ticks % 3 == 0 && this.playersUsing > 0)
|
||||
{
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket(), this.worldObj, new Vector3(this), 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return direction == ForgeDirection.getOrientation(this.getBlockMetadata() - BlockBasicMachine.ELECTRIC_FURNACE_METADATA + 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getRequest()
|
||||
{
|
||||
if (this.canProcess())
|
||||
{
|
||||
return new ElectricityPack(WATTS_PER_TICK / this.getVoltage(), this.getVoltage());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ElectricityPack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
return PacketManager.getPacket(BasicComponents.CHANNEL, this, this.processTicks, this.disabledTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.processTicks = dataStream.readInt();
|
||||
this.disabledTicks = dataStream.readInt();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
PacketManager.sendPacketToClients(getDescriptionPacket(), this.worldObj, new Vector3(this), 15);
|
||||
}
|
||||
this.playersUsing++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
this.playersUsing--;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Is this machine able to process its specific task?
|
||||
*/
|
||||
public boolean canProcess()
|
||||
{
|
||||
if (FurnaceRecipes.smelting().getSmeltingResult(this.containingItems[1]) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.containingItems[1] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.containingItems[2] != null)
|
||||
{
|
||||
if (!this.containingItems[2].isItemEqual(FurnaceRecipes.smelting().getSmeltingResult(this.containingItems[1])))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.containingItems[2].stackSize + 1 > 64)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace
|
||||
* result stack
|
||||
*/
|
||||
public void smeltItem()
|
||||
{
|
||||
if (this.canProcess())
|
||||
{
|
||||
ItemStack resultItemStack = FurnaceRecipes.smelting().getSmeltingResult(this.containingItems[1]);
|
||||
|
||||
if (this.containingItems[2] == null)
|
||||
{
|
||||
this.containingItems[2] = resultItemStack.copy();
|
||||
}
|
||||
else if (this.containingItems[2].isItemEqual(resultItemStack))
|
||||
{
|
||||
this.containingItems[2].stackSize++;
|
||||
}
|
||||
|
||||
this.containingItems[1].stackSize--;
|
||||
|
||||
if (this.containingItems[1].stackSize <= 0)
|
||||
{
|
||||
this.containingItems[1] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile entity from NBT.
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.readFromNBT(par1NBTTagCompound);
|
||||
this.processTicks = par1NBTTagCompound.getInteger("smeltingTicks");
|
||||
NBTTagList var2 = par1NBTTagCompound.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tile entity to NBT.
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.writeToNBT(par1NBTTagCompound);
|
||||
par1NBTTagCompound.setInteger("smeltingTicks", this.processTicks);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
par1NBTTagCompound.setTag("Items", var2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartInventorySide(ForgeDirection side)
|
||||
{
|
||||
if (side == side.DOWN || side == side.UP)
|
||||
{
|
||||
return side.ordinal();
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventorySide(ForgeDirection side)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.containingItems.length;
|
||||
}
|
||||
|
||||
@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 String getInvName()
|
||||
{
|
||||
return LanguageRegistry.instance().getStringLocalization("tile.bcMachine.2.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@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 boolean func_94042_c()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_94041_b(int i, ItemStack itemstack)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package universalelectricity.core;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import universalelectricity.core.electricity.Electricity;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/**
|
||||
* A class used to load Universal Electricity and make it work.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class UELoader
|
||||
{
|
||||
public static final UELoader INSTANCE = new UELoader();
|
||||
|
||||
public static boolean isInitialized = false;
|
||||
|
||||
public void initiate()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
Electricity.instance = new Electricity();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
UniversalElectricity.isVoltageSensitive = UniversalElectricity.CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", UniversalElectricity.isVoltageSensitive).getBoolean(UniversalElectricity.isVoltageSensitive);
|
||||
|
||||
UniversalElectricity.IC2_RATIO = UniversalElectricity.CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", UniversalElectricity.IC2_RATIO).getDouble(UniversalElectricity.IC2_RATIO);
|
||||
UniversalElectricity.BC3_RATIO = UniversalElectricity.CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", UniversalElectricity.BC3_RATIO).getDouble(UniversalElectricity.BC3_RATIO);
|
||||
UniversalElectricity.TO_IC2_RATIO = 1 / UniversalElectricity.IC2_RATIO;
|
||||
UniversalElectricity.TO_BC_RATIO = 1 / UniversalElectricity.BC3_RATIO;
|
||||
|
||||
FMLLog.finest("Universal Electricity v" + UniversalElectricity.VERSION + " successfully loaded!");
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldUnLoad(WorldEvent.Unload event)
|
||||
{
|
||||
Electricity.instance = new Electricity();
|
||||
Electricity.instance.cleanUpNetworks();
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldLoad(WorldEvent.Load event)
|
||||
{
|
||||
Electricity.instance = new Electricity();
|
||||
Electricity.instance.cleanUpNetworks();
|
||||
}
|
||||
}
|
|
@ -1,25 +1,14 @@
|
|||
package universalelectricity.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
/**
|
||||
* Instructions for using the Universal Electricity API.
|
||||
*
|
||||
* The less you include of the API, the more compatible your mod will be for future releases of
|
||||
* Universal Electricity.
|
||||
*
|
||||
* REQUIRED PACKAGE: "universalelectricity.core" OPTIONAL PACKAGE: "universalelectricity.prefab"
|
||||
*
|
||||
* All classes should be removed if you are not going to use them.
|
||||
* General Universal Electricity class.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
|
@ -30,8 +19,8 @@ public class UniversalElectricity
|
|||
* The version of the Universal Electricity API.
|
||||
*/
|
||||
public static final int MAJOR_VERSION = 1;
|
||||
public static final int MINOR_VERSION = 2;
|
||||
public static final int REVISION_VERSION = 6;
|
||||
public static final int MINOR_VERSION = 3;
|
||||
public static final int REVISION_VERSION = 0;
|
||||
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
|
||||
|
||||
/**
|
||||
|
@ -40,12 +29,14 @@ public class UniversalElectricity
|
|||
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/UniversalElectricity.cfg"));
|
||||
|
||||
/**
|
||||
* Conversion ratios between Buildcraft and Industrialcraft energy.
|
||||
* Multiply this to convert foreign energy into UE Joules.
|
||||
*/
|
||||
// The amount of UE Joules equivalent to IC2 EU
|
||||
public static double IC2_RATIO = 40;
|
||||
// The amount of UE Joules equivalent to BC Minecraft Joules
|
||||
public static double BC3_RATIO = 100;
|
||||
|
||||
/**
|
||||
* Multiply this to convert UE Joules into foreign energy.
|
||||
*/
|
||||
public static double TO_IC2_RATIO = 1 / IC2_RATIO;
|
||||
public static double TO_BC_RATIO = 1 / BC3_RATIO;
|
||||
|
||||
|
@ -56,80 +47,22 @@ public class UniversalElectricity
|
|||
public static boolean isVoltageSensitive = false;
|
||||
|
||||
/**
|
||||
* Use this material for all your machine blocks. It can be breakable by hand.
|
||||
* A general material that can be used by machines. Breakable by hand, suitable for machines.
|
||||
*/
|
||||
public static final Material machine = new Material(MapColor.ironColor);
|
||||
|
||||
/**
|
||||
* A list of all mods Universal Electricity has loaded.
|
||||
*/
|
||||
public static final List<Object> mods = new ArrayList<Object>();
|
||||
|
||||
/**
|
||||
* You must register your mod with Universal Electricity. Call this in your mod's
|
||||
* pre-initialization stage.
|
||||
*/
|
||||
public static void register(Object mod, int major, int minor, int revision, boolean strict)
|
||||
static
|
||||
{
|
||||
if (MAJOR_VERSION != major)
|
||||
{
|
||||
throw new RuntimeException("A Universal Electricity mod " + mod.getClass().getSimpleName() + " is way too old! Make sure it is update to v" + major + "." + minor + "." + revision);
|
||||
}
|
||||
/**
|
||||
* Loads the configuration and sets all the values.
|
||||
*/
|
||||
CONFIGURATION.load();
|
||||
IC2_RATIO = CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO);
|
||||
BC3_RATIO = CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO);
|
||||
TO_IC2_RATIO = 1 / IC2_RATIO;
|
||||
TO_BC_RATIO = 1 / BC3_RATIO;
|
||||
|
||||
if (MINOR_VERSION < minor)
|
||||
{
|
||||
throw new RuntimeException("A Universal Electricity mod " + mod.getClass().getSimpleName() + " is too old! Make sure it is update to v" + major + "." + minor + "." + revision);
|
||||
}
|
||||
|
||||
if (REVISION_VERSION < revision)
|
||||
{
|
||||
if (strict)
|
||||
{
|
||||
throw new RuntimeException("A Universal Electricity mod " + mod.getClass().getSimpleName() + " is too old! Require v" + major + "." + minor + "." + revision);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.warning("The version of Universal Electricity detected is not the recommended version by the mod " + mod.getClass().getSimpleName() + ". Odd things might happen. Recommended to try v" + major + "." + minor + "." + revision);
|
||||
}
|
||||
}
|
||||
|
||||
mods.add(mod);
|
||||
|
||||
FMLLog.fine(mod.getClass().getSimpleName() + " has been registered to Universal Electricity.");
|
||||
|
||||
UELoader.INSTANCE.initiate();
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that allows you to lock your mod to a specific version of Forge.
|
||||
*/
|
||||
public static void forgeLock(int major, int minor, int revision, boolean strict)
|
||||
{
|
||||
if (ForgeVersion.getMajorVersion() != major)
|
||||
{
|
||||
throw new RuntimeException("Universal Electricity: Wrong Minecraft Forge version! Require " + major + "." + minor + "." + revision);
|
||||
}
|
||||
|
||||
if (ForgeVersion.getMinorVersion() < minor)
|
||||
{
|
||||
throw new RuntimeException("Universal Electricity: Minecraft Forge minor version is too old! Require " + major + "." + minor + "." + revision);
|
||||
}
|
||||
|
||||
if (ForgeVersion.getRevisionVersion() < revision)
|
||||
{
|
||||
if (strict)
|
||||
{
|
||||
throw new RuntimeException("Universal Electricity: Minecraft Forge revision version is too old! Require " + major + "." + minor + "." + revision);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Universal Electricity Warning: Minecraft Forge is not the specified version. Odd things might happen. Require " + major + "." + minor + "." + revision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void forgeLock(int major, int minor, int revision)
|
||||
{
|
||||
forgeLock(major, minor, revision, false);
|
||||
isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive);
|
||||
CONFIGURATION.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
/**
|
||||
* Must be applied to all tile entities that are conductors.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IConductor extends INetworkProvider, IConnectionProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the resistance of the conductor. Used to calculate energy loss. A higher resistance
|
||||
* means a higher energy loss.
|
||||
*
|
||||
* @return The amount of resistance in Ohms.
|
||||
*/
|
||||
public double getResistance();
|
||||
|
||||
/**
|
||||
* @return The maximum amount of amps this conductor can handle before melting down.
|
||||
*/
|
||||
public double getCurrentCapcity();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Applied to TileEntities.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IConnectionProvider extends IConnector
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets a list of all the connected TileEntities that this conductor is connected to. The
|
||||
* array's length should be always the 6 adjacent wires.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TileEntity[] getAdjacentConnections();
|
||||
|
||||
/**
|
||||
* Instantly refreshes all connected blocks around the conductor, recalculating the connected
|
||||
* blocks.
|
||||
*/
|
||||
public void updateAdjacentConnections();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Applied to TileEntities that can connect to an electrical network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IConnector
|
||||
{
|
||||
|
||||
/**
|
||||
* @return If the connection is possible.
|
||||
*/
|
||||
public boolean canConnect(ForgeDirection direction);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
/**
|
||||
* This interface is to be applied to all TileEntities which stores electricity within them.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public interface IElectricityStorage
|
||||
{
|
||||
/**
|
||||
* Returns the amount of joules this unit has stored.
|
||||
*/
|
||||
public double getJoules();
|
||||
|
||||
/**
|
||||
* Sets the amount of joules this unit has stored.
|
||||
*/
|
||||
public void setJoules(double joules);
|
||||
|
||||
/**
|
||||
* Gets the maximum amount of joules this unit can store.
|
||||
*/
|
||||
public double getMaxJoules();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package universalelectricity.core.block;
|
||||
|
||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
||||
|
||||
/**
|
||||
* Applied to TileEntities that has an instance of an electricity network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface INetworkProvider
|
||||
{
|
||||
public IElectricityNetwork getNetwork();
|
||||
|
||||
public void setNetwork(IElectricityNetwork network);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package universalelectricity.core.implement;
|
||||
package universalelectricity.core.block;
|
||||
|
||||
/**
|
||||
* Applies to all objects that has a voltage.
|
||||
|
@ -11,8 +11,7 @@ public interface IVoltage
|
|||
/**
|
||||
* Gets the voltage of this object.
|
||||
*
|
||||
* @param data - The data, possibly an ItemStack if this is an electric item.
|
||||
* @return The amount of volts. E.g 120v or 240v
|
||||
*/
|
||||
public double getVoltage(Object... data);
|
||||
public double getVoltage();
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.implement.IConductor;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/**
|
||||
* The Electricity Network Manager.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class Electricity
|
||||
{
|
||||
public static Electricity instance = new Electricity();
|
||||
|
||||
private List<ElectricityNetwork> electricityNetworks = new ArrayList<ElectricityNetwork>();
|
||||
|
||||
/**
|
||||
* Registers a conductor into the UE electricity net.
|
||||
*/
|
||||
public void registerConductor(IConductor newConductor)
|
||||
{
|
||||
this.cleanUpNetworks();
|
||||
ElectricityNetwork newNetwork = new ElectricityNetwork(newConductor);
|
||||
this.electricityNetworks.add(newNetwork);
|
||||
}
|
||||
|
||||
public void unregister(TileEntity tileEntity)
|
||||
{
|
||||
for (ElectricityNetwork network : this.electricityNetworks)
|
||||
{
|
||||
network.stopProducing(tileEntity);
|
||||
network.stopRequesting(tileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two connection lines together into one.
|
||||
*
|
||||
* @param networkA - The network to be merged into. This network will be kept.
|
||||
* @param networkB - The network to be merged. This network will be deleted.
|
||||
*/
|
||||
public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB)
|
||||
{
|
||||
if (networkA != networkB)
|
||||
{
|
||||
if (networkA != null && networkB != null)
|
||||
{
|
||||
networkA.conductors.addAll(networkB.conductors);
|
||||
networkA.setNetwork();
|
||||
this.electricityNetworks.remove(networkB);
|
||||
networkB = null;
|
||||
|
||||
networkA.cleanConductors();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("Failed to merge Universal Electricity wire connections!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate one connection line into two different ones between two conductors. This function
|
||||
* does this by resetting all wires in the connection line and making them each reconnect.
|
||||
*
|
||||
* @param conductorA - existing conductor
|
||||
* @param conductorB - broken/invalid conductor
|
||||
*/
|
||||
public void splitConnection(IConductor conductorA, IConductor conductorB)
|
||||
{
|
||||
try
|
||||
{
|
||||
ElectricityNetwork network = conductorA.getNetwork();
|
||||
|
||||
if (network != null)
|
||||
{
|
||||
network.cleanConductors();
|
||||
network.resetConductors();
|
||||
|
||||
Iterator it = network.conductors.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
IConductor conductor = (IConductor) it.next();
|
||||
|
||||
for (byte i = 0; i < 6; i++)
|
||||
{
|
||||
conductor.updateConnectionWithoutSplit(Vector3.getConnectorFromSide(((TileEntity) conductor).worldObj, new Vector3((TileEntity) conductor), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.severe("Conductor invalid network while splitting connection!");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Failed to split wire connection!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up and remove all useless and invalid connections.
|
||||
*/
|
||||
public void cleanUpNetworks()
|
||||
{
|
||||
try
|
||||
{
|
||||
Iterator it = electricityNetworks.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
ElectricityNetwork network = (ElectricityNetwork) it.next();
|
||||
network.cleanConductors();
|
||||
|
||||
if (network.conductors.size() == 0)
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Failed to clean up wire connections!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void resetConductors()
|
||||
{
|
||||
Iterator it = electricityNetworks.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
ElectricityNetwork network = ((ElectricityNetwork) it.next());
|
||||
network.resetConductors();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Register your block to allow a wire connection with this class. This class manages the visual
|
||||
* aspect of a wire connection and does not effect the actual transmission of electricity.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricityConnections
|
||||
{
|
||||
private static final HashMap<TileEntity, EnumSet<ForgeDirection>> connectors = new HashMap<TileEntity, EnumSet<ForgeDirection>>();
|
||||
|
||||
/**
|
||||
* Registers a block to allow connection from Universal Electricity wires.
|
||||
*
|
||||
* @param tileEntity - The TileEntity
|
||||
* @param connectableDirections - Directions that allow connection
|
||||
*/
|
||||
public static void registerConnector(TileEntity tileEntity, EnumSet<ForgeDirection> connectableDirections)
|
||||
{
|
||||
connectors.put(tileEntity, connectableDirections);
|
||||
}
|
||||
|
||||
public static void unregisterConnector(TileEntity tileEntity)
|
||||
{
|
||||
connectors.remove(tileEntity);
|
||||
}
|
||||
|
||||
public static boolean isConnector(TileEntity tileEntity)
|
||||
{
|
||||
return connectors.containsKey(tileEntity);
|
||||
}
|
||||
|
||||
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if (isConnector(tileEntity))
|
||||
{
|
||||
EnumSet<ForgeDirection> enumSet = connectors.get(tileEntity);
|
||||
|
||||
if (enumSet != null)
|
||||
{
|
||||
return enumSet.contains(side);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directions in which this block may connect or be connected from.
|
||||
*/
|
||||
public static EnumSet<ForgeDirection> getDirections(TileEntity tileEntity)
|
||||
{
|
||||
return connectors.get(tileEntity);
|
||||
}
|
||||
|
||||
public static void clearAll()
|
||||
{
|
||||
connectors.clear();
|
||||
}
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
/**
|
||||
* An easy way to display information on electricity.
|
||||
* An easy way to display information on electricity for the client.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
||||
public class ElectricInfo
|
||||
public class ElectricityDisplay
|
||||
{
|
||||
public static enum ElectricUnit
|
||||
{
|
||||
AMPERE("Amp", "I"), AMP_HOUR("Amp Hour", "Ah"), VOLTAGE("Volt", "V"), WATT("Watt", "W"), WATT_HOUR("Watt Hour", "Wh"), RESISTANCE("Ohm", "R"), CONDUCTANCE("Siemen", "S"), JOULES("Joule", "J");
|
||||
AMPERE("Amp", "I"), AMP_HOUR("Amp Hour", "Ah"), VOLTAGE("Volt", "V"), WATT("Watt", "W"),
|
||||
WATT_HOUR("Watt Hour", "Wh"), RESISTANCE("Ohm", "R"), CONDUCTANCE("Siemen", "S"),
|
||||
JOULES("Joule", "J");
|
||||
|
||||
public String name;
|
||||
public String symbol;
|
||||
|
@ -29,7 +31,8 @@ public class ElectricInfo
|
|||
|
||||
public static enum MeasurementUnit
|
||||
{
|
||||
MICRO("Micro", "mi", 0.000001), MILLI("Milli", "m", 0.001), KILO("Kilo", "k", 1000), MEGA("Mega", "M", 1000000);
|
||||
MICRO("Micro", "mi", 0.000001), MILLI("Milli", "m", 0.001), KILO("Kilo", "k", 1000),
|
||||
MEGA("Mega", "M", 1000000);
|
||||
|
||||
public String name;
|
||||
public String symbol;
|
||||
|
@ -60,76 +63,6 @@ public class ElectricInfo
|
|||
}
|
||||
}
|
||||
|
||||
public static double getJoules(double watts, double seconds)
|
||||
{
|
||||
return watts * seconds;
|
||||
}
|
||||
|
||||
public static double getJoules(double amps, double voltage, double seconds)
|
||||
{
|
||||
return amps * voltage * seconds;
|
||||
}
|
||||
|
||||
public static double getWattsFromJoules(double joules, double seconds)
|
||||
{
|
||||
return joules / seconds;
|
||||
}
|
||||
|
||||
public static double getAmps(double watts, double voltage)
|
||||
{
|
||||
return watts / voltage;
|
||||
}
|
||||
|
||||
public static double getAmps(double ampHours)
|
||||
{
|
||||
return ampHours * 3600;
|
||||
}
|
||||
|
||||
public static double getAmpsFromWattHours(double wattHours, double voltage)
|
||||
{
|
||||
return getWatts(wattHours) / voltage;
|
||||
}
|
||||
|
||||
public static double getWattHoursFromAmpHours(double ampHours, double voltage)
|
||||
{
|
||||
return ampHours * voltage;
|
||||
}
|
||||
|
||||
public static double getAmpHours(double amps)
|
||||
{
|
||||
return amps / 3600;
|
||||
}
|
||||
|
||||
public static double getWatts(double amps, double voltage)
|
||||
{
|
||||
return amps * voltage;
|
||||
}
|
||||
|
||||
public static double getWatts(double wattHours)
|
||||
{
|
||||
return wattHours * 3600;
|
||||
}
|
||||
|
||||
public static double getWattHours(double watts)
|
||||
{
|
||||
return watts / 3600;
|
||||
}
|
||||
|
||||
public static double getWattHours(double amps, double voltage)
|
||||
{
|
||||
return getWattHours(getWatts(amps, voltage));
|
||||
}
|
||||
|
||||
public static double getResistance(double amps, double voltage)
|
||||
{
|
||||
return voltage / amps;
|
||||
}
|
||||
|
||||
public static double getConductance(double amps, double voltage)
|
||||
{
|
||||
return amps / voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the unit as text. Works only for positive numbers.
|
||||
*/
|
|
@ -1,33 +1,48 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.implement.IConductor;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnectionProvider;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.path.Pathfinder;
|
||||
import universalelectricity.core.path.PathfinderChecker;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
public class ElectricityNetwork
|
||||
/**
|
||||
* An Electrical Network specifies a wire connection. Each wire connection line will have its own
|
||||
* electrical network. Do not include this class if you do not intend to have custom wires in your
|
||||
* mod. This will increase future compatibility.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricityNetwork implements IElectricityNetwork
|
||||
{
|
||||
private final HashMap<TileEntity, ElectricityPack> producers = new HashMap<TileEntity, ElectricityPack>();
|
||||
private final HashMap<TileEntity, ElectricityPack> consumers = new HashMap<TileEntity, ElectricityPack>();
|
||||
|
||||
public final List<IConductor> conductors = new ArrayList<IConductor>();
|
||||
private final Set<IConductor> conductors = new HashSet<IConductor>();
|
||||
|
||||
public ElectricityNetwork(IConductor conductor)
|
||||
public ElectricityNetwork()
|
||||
{
|
||||
this.addConductor(conductor);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this tile entity to start producing energy in this network.
|
||||
*/
|
||||
public ElectricityNetwork(IConductor... conductors)
|
||||
{
|
||||
this.conductors.addAll(Arrays.asList(conductors));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
if (tileEntity != null && electricityPack.getWatts() > 0)
|
||||
|
@ -36,11 +51,13 @@ public class ElectricityNetwork
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startProducing(TileEntity tileEntity, double amperes, double voltage)
|
||||
{
|
||||
this.startProducing(tileEntity, new ElectricityPack(amperes, voltage));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProducing(TileEntity tileEntity)
|
||||
{
|
||||
return this.producers.containsKey(tileEntity);
|
||||
|
@ -49,6 +66,7 @@ public class ElectricityNetwork
|
|||
/**
|
||||
* Sets this tile entity to stop producing energy in this network.
|
||||
*/
|
||||
@Override
|
||||
public void stopProducing(TileEntity tileEntity)
|
||||
{
|
||||
this.producers.remove(tileEntity);
|
||||
|
@ -57,6 +75,7 @@ public class ElectricityNetwork
|
|||
/**
|
||||
* Sets this tile entity to start producing energy in this network.
|
||||
*/
|
||||
@Override
|
||||
public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
if (tileEntity != null && electricityPack.getWatts() > 0)
|
||||
|
@ -65,11 +84,13 @@ public class ElectricityNetwork
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startRequesting(TileEntity tileEntity, double amperes, double voltage)
|
||||
{
|
||||
this.startRequesting(tileEntity, new ElectricityPack(amperes, voltage));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequesting(TileEntity tileEntity)
|
||||
{
|
||||
return this.consumers.containsKey(tileEntity);
|
||||
|
@ -78,6 +99,7 @@ public class ElectricityNetwork
|
|||
/**
|
||||
* Sets this tile entity to stop producing energy in this network.
|
||||
*/
|
||||
@Override
|
||||
public void stopRequesting(TileEntity tileEntity)
|
||||
{
|
||||
this.consumers.remove(tileEntity);
|
||||
|
@ -88,6 +110,7 @@ public class ElectricityNetwork
|
|||
* ignore any.
|
||||
* @return The electricity produced in this electricity network
|
||||
*/
|
||||
@Override
|
||||
public ElectricityPack getProduced(TileEntity... ignoreTiles)
|
||||
{
|
||||
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
|
||||
|
@ -151,6 +174,7 @@ public class ElectricityNetwork
|
|||
/**
|
||||
* @return How much electricity this network needs.
|
||||
*/
|
||||
@Override
|
||||
public ElectricityPack getRequest(TileEntity... ignoreTiles)
|
||||
{
|
||||
ElectricityPack totalElectricity = this.getRequestWithoutReduction();
|
||||
|
@ -158,6 +182,7 @@ public class ElectricityNetwork
|
|||
return totalElectricity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getRequestWithoutReduction()
|
||||
{
|
||||
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
|
||||
|
@ -207,6 +232,7 @@ public class ElectricityNetwork
|
|||
* @param tileEntity
|
||||
* @return The electricity being input into this tile entity.
|
||||
*/
|
||||
@Override
|
||||
public ElectricityPack consumeElectricity(TileEntity tileEntity)
|
||||
{
|
||||
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
|
||||
|
@ -217,8 +243,7 @@ public class ElectricityNetwork
|
|||
|
||||
if (this.consumers.containsKey(tileEntity) && tileRequest != null)
|
||||
{
|
||||
// Calculate the electricity this tile entity is receiving in
|
||||
// percentage.
|
||||
// Calculate the electricity this TileEntity is receiving in percentage.
|
||||
totalElectricity = this.getProduced();
|
||||
|
||||
if (totalElectricity.getWatts() > 0)
|
||||
|
@ -249,291 +274,217 @@ public class ElectricityNetwork
|
|||
/**
|
||||
* @return Returns all producers in this electricity network.
|
||||
*/
|
||||
@Override
|
||||
public HashMap<TileEntity, ElectricityPack> getProducers()
|
||||
{
|
||||
return this.producers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the electricity receivers.
|
||||
*/
|
||||
@Override
|
||||
public List<TileEntity> getProviders()
|
||||
{
|
||||
List<TileEntity> providers = new ArrayList<TileEntity>();
|
||||
providers.addAll(this.producers.keySet());
|
||||
return providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns all consumers in this electricity network.
|
||||
*/
|
||||
@Override
|
||||
public HashMap<TileEntity, ElectricityPack> getConsumers()
|
||||
{
|
||||
return this.consumers;
|
||||
}
|
||||
|
||||
public void addConductor(IConductor newConductor)
|
||||
{
|
||||
this.cleanConductors();
|
||||
|
||||
if (!conductors.contains(newConductor))
|
||||
{
|
||||
conductors.add(newConductor);
|
||||
newConductor.setNetwork(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get only the electric units that can receive electricity from the given side.
|
||||
* Gets all the electricity receivers.
|
||||
*/
|
||||
@Override
|
||||
public List<TileEntity> getReceivers()
|
||||
{
|
||||
List<TileEntity> receivers = new ArrayList<TileEntity>();
|
||||
|
||||
Iterator it = this.consumers.entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry pairs = (Map.Entry) it.next();
|
||||
|
||||
if (pairs != null)
|
||||
{
|
||||
receivers.add((TileEntity) pairs.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
receivers.addAll(this.consumers.keySet());
|
||||
return receivers;
|
||||
}
|
||||
|
||||
public void cleanConductors()
|
||||
@Override
|
||||
public void cleanUpConductors()
|
||||
{
|
||||
for (int i = 0; i < conductors.size(); i++)
|
||||
Iterator it = this.conductors.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
if (conductors.get(i) == null)
|
||||
IConductor conductor = (IConductor) it.next();
|
||||
|
||||
if (conductor == null)
|
||||
{
|
||||
conductors.remove(i);
|
||||
it.remove();
|
||||
}
|
||||
else if (((TileEntity) conductors.get(i)).isInvalid())
|
||||
else if (((TileEntity) conductor).isInvalid())
|
||||
{
|
||||
conductors.remove(i);
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
conductor.setNetwork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetConductors()
|
||||
{
|
||||
for (int i = 0; i < conductors.size(); i++)
|
||||
{
|
||||
conductors.get(i).reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void setNetwork()
|
||||
{
|
||||
this.cleanConductors();
|
||||
|
||||
for (IConductor conductor : this.conductors)
|
||||
{
|
||||
conductor.setNetwork(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onOverCharge()
|
||||
{
|
||||
this.cleanConductors();
|
||||
|
||||
for (int i = 0; i < conductors.size(); i++)
|
||||
{
|
||||
conductors.get(i).onOverCharge();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total amount of resistance of this electrical network. In Ohms.
|
||||
* This function is called to refresh all conductors in this network
|
||||
*/
|
||||
@Override
|
||||
public void refreshConductors()
|
||||
{
|
||||
this.cleanUpConductors();
|
||||
|
||||
try
|
||||
{
|
||||
Iterator<IConductor> it = this.conductors.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
IConductor conductor = it.next();
|
||||
conductor.updateAdjacentConnections();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Universal Electricity: Failed to refresh conductor.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTotalResistance()
|
||||
{
|
||||
double resistance = 0;
|
||||
|
||||
for (int i = 0; i < conductors.size(); i++)
|
||||
for (IConductor conductor : this.conductors)
|
||||
{
|
||||
resistance += conductors.get(i).getResistance();
|
||||
resistance += conductor.getResistance();
|
||||
}
|
||||
|
||||
return resistance;
|
||||
}
|
||||
|
||||
public double getLowestAmpTolerance()
|
||||
@Override
|
||||
public double getLowestCurrentCapacity()
|
||||
{
|
||||
double lowestAmp = 0;
|
||||
|
||||
for (IConductor conductor : conductors)
|
||||
for (IConductor conductor : this.conductors)
|
||||
{
|
||||
if (lowestAmp == 0 || conductor.getMaxAmps() < lowestAmp)
|
||||
if (lowestAmp == 0 || conductor.getCurrentCapcity() < lowestAmp)
|
||||
{
|
||||
lowestAmp = conductor.getMaxAmps();
|
||||
lowestAmp = conductor.getCurrentCapcity();
|
||||
}
|
||||
}
|
||||
|
||||
return lowestAmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called to refresh all conductors in this network
|
||||
*/
|
||||
public void refreshConductors()
|
||||
@Override
|
||||
public Set<IConductor> getConductors()
|
||||
{
|
||||
for (int j = 0; j < this.conductors.size(); j++)
|
||||
return this.conductors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeConnection(IElectricityNetwork network)
|
||||
{
|
||||
if (network != null && network != this)
|
||||
{
|
||||
IConductor conductor = this.conductors.get(j);
|
||||
conductor.refreshConnectedBlocks();
|
||||
ElectricityNetwork newNetwork = new ElectricityNetwork();
|
||||
newNetwork.getConductors().addAll(this.getConductors());
|
||||
newNetwork.getConductors().addAll(network.getConductors());
|
||||
newNetwork.cleanUpConductors();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find the electricity network based in a tile entity and checks to see if it is a
|
||||
* conductor. All machines should use this function to search for a connecting conductor around
|
||||
* it.
|
||||
*
|
||||
* @param conductor - The TileEntity conductor
|
||||
* @param approachDirection - The direction you are approaching this wire from.
|
||||
* @return The ElectricityNetwork or null if not found.
|
||||
*/
|
||||
public static ElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection)
|
||||
@Override
|
||||
public void splitNetwork(IConnectionProvider splitPoint)
|
||||
{
|
||||
if (tileEntity != null)
|
||||
if (splitPoint instanceof TileEntity)
|
||||
{
|
||||
if (tileEntity instanceof IConductor)
|
||||
this.getConductors().remove(splitPoint);
|
||||
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere.
|
||||
*/
|
||||
TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
if (ElectricityConnections.isConnector(tileEntity))
|
||||
TileEntity connectedBlockA = connectedBlocks[i];
|
||||
|
||||
if (connectedBlockA instanceof IConnectionProvider)
|
||||
{
|
||||
if (ElectricityConnections.canConnect(tileEntity, approachDirection.getOpposite()))
|
||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||
{
|
||||
return ((IConductor) tileEntity).getNetwork();
|
||||
final TileEntity connectedBlockB = connectedBlocks[ii];
|
||||
|
||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IConnectionProvider)
|
||||
{
|
||||
Pathfinder finder = new PathfinderChecker((IConnectionProvider) connectedBlockB, splitPoint);
|
||||
finder.init((IConnectionProvider) connectedBlockA);
|
||||
|
||||
if (finder.results.size() > 0)
|
||||
{
|
||||
/**
|
||||
* The connections A and B are still intact elsewhere. Set all
|
||||
* references of wire connection into one network.
|
||||
*/
|
||||
|
||||
for (IConnectionProvider node : finder.iteratedNodes)
|
||||
{
|
||||
if (node instanceof INetworkProvider)
|
||||
{
|
||||
if (node != splitPoint)
|
||||
{
|
||||
((INetworkProvider) node).setNetwork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* The connections A and B are not connected anymore. Give both of
|
||||
* them a new network.
|
||||
*/
|
||||
IElectricityNetwork newNetwork = new ElectricityNetwork();
|
||||
|
||||
for (IConnectionProvider node : finder.iteratedNodes)
|
||||
{
|
||||
if (node instanceof IConductor)
|
||||
{
|
||||
if (node != splitPoint)
|
||||
{
|
||||
newNetwork.getConductors().add((IConductor) node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newNetwork.cleanUpConductors();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tileEntity - The TileEntity's sides.
|
||||
* @param approachingDirection - The directions that can be connected.
|
||||
* @return A list of networks from all specified sides. There will be no repeated
|
||||
* ElectricityNetworks and it will never return null.
|
||||
*/
|
||||
public static List<ElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection)
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final List<ElectricityNetwork> connectedNetworks = new ArrayList<ElectricityNetwork>();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
|
||||
if (approachingDirection.contains(direction))
|
||||
{
|
||||
Vector3 position = new Vector3(tileEntity);
|
||||
position.modifyPositionFromSide(direction);
|
||||
TileEntity outputConductor = position.getTileEntity(tileEntity.worldObj);
|
||||
ElectricityNetwork electricityNetwork = getNetworkFromTileEntity(outputConductor, direction);
|
||||
|
||||
if (electricityNetwork != null && !connectedNetworks.contains(connectedNetworks))
|
||||
{
|
||||
connectedNetworks.add(electricityNetwork);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return connectedNetworks;
|
||||
return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests and attempts to consume electricity from all specified sides. Use this as a simple
|
||||
* helper function.
|
||||
*
|
||||
* @param tileEntity- The TileEntity consuming the electricity.
|
||||
* @param approachDirection - The sides in which you can connect.
|
||||
* @param requestPack - The amount of electricity to be requested.
|
||||
* @return The consumed ElectricityPack.
|
||||
*/
|
||||
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack requestPack)
|
||||
{
|
||||
ElectricityPack consumedPack = new ElectricityPack();
|
||||
|
||||
if (tileEntity != null && approachingDirection != null)
|
||||
{
|
||||
final List<ElectricityNetwork> connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
||||
|
||||
if (connectedNetworks.size() > 0)
|
||||
{
|
||||
/**
|
||||
* Requests an even amount of electricity from all sides.
|
||||
*/
|
||||
double wattsPerSide = (requestPack.getWatts() / connectedNetworks.size());
|
||||
double voltage = requestPack.voltage;
|
||||
|
||||
for (ElectricityNetwork network : connectedNetworks)
|
||||
{
|
||||
if (wattsPerSide > 0 && requestPack.getWatts() > 0)
|
||||
{
|
||||
network.startRequesting(tileEntity, wattsPerSide / voltage, voltage);
|
||||
ElectricityPack receivedPack = network.consumeElectricity(tileEntity);
|
||||
consumedPack.amperes += receivedPack.amperes;
|
||||
consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage);
|
||||
}
|
||||
else
|
||||
{
|
||||
network.stopRequesting(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return consumedPack;
|
||||
}
|
||||
|
||||
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
return consumeFromMultipleSides(tileEntity, ElectricityConnections.getDirections(tileEntity), electricityPack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces electricity from all specified sides. Use this as a simple helper function.
|
||||
*
|
||||
* @param tileEntity- The TileEntity consuming the electricity.
|
||||
* @param approachDirection - The sides in which you can connect to.
|
||||
* @param producePack - The amount of electricity to be produced.
|
||||
* @return What remained in the electricity pack.
|
||||
*/
|
||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack producingPack)
|
||||
{
|
||||
ElectricityPack remainingElectricity = producingPack.clone();
|
||||
|
||||
if (tileEntity != null && approachingDirection != null)
|
||||
{
|
||||
final List<ElectricityNetwork> connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
||||
|
||||
if (connectedNetworks.size() > 0)
|
||||
{
|
||||
/**
|
||||
* Requests an even amount of electricity from all sides.
|
||||
*/
|
||||
double wattsPerSide = (producingPack.getWatts() / connectedNetworks.size());
|
||||
double voltage = producingPack.voltage;
|
||||
|
||||
for (ElectricityNetwork network : connectedNetworks)
|
||||
{
|
||||
if (wattsPerSide > 0 && producingPack.getWatts() > 0)
|
||||
{
|
||||
double amperes = wattsPerSide / voltage;
|
||||
network.startProducing(tileEntity, amperes, voltage);
|
||||
remainingElectricity.amperes -= amperes;
|
||||
}
|
||||
else
|
||||
{
|
||||
network.stopProducing(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingElectricity;
|
||||
}
|
||||
|
||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
return produceFromMultipleSides(tileEntity, ElectricityConnections.getDirections(tileEntity), electricityPack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,226 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
|
||||
/**
|
||||
* A helper class that provides additional useful functions to interact with the ElectricityNetwork
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricityNetworkHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Invalidates a TileEntity from the electrical network, thereby removing it from all
|
||||
* electricity network that are adjacent to it.
|
||||
*/
|
||||
public static void invalidate(TileEntity tileEntity)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
TileEntity checkTile = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
|
||||
if (checkTile instanceof INetworkProvider)
|
||||
{
|
||||
IElectricityNetwork network = ((INetworkProvider) checkTile).getNetwork();
|
||||
|
||||
if (network != null)
|
||||
{
|
||||
network.stopRequesting(tileEntity);
|
||||
network.stopProducing(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EnumSet<ForgeDirection> getDirections(TileEntity tileEntity)
|
||||
{
|
||||
EnumSet<ForgeDirection> possibleSides = EnumSet.noneOf(ForgeDirection.class);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
if (((IConnector) tileEntity).canConnect(direction))
|
||||
{
|
||||
possibleSides.add(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return possibleSides;
|
||||
}
|
||||
|
||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
return ElectricityNetworkHelper.produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces electricity from all specified sides. Use this as a simple helper function.
|
||||
*
|
||||
* @param tileEntity- The TileEntity consuming the electricity.
|
||||
* @param approachDirection - The sides in which you can connect to.
|
||||
* @param producePack - The amount of electricity to be produced.
|
||||
* @return What remained in the electricity pack.
|
||||
*/
|
||||
public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack producingPack)
|
||||
{
|
||||
ElectricityPack remainingElectricity = producingPack.clone();
|
||||
|
||||
if (tileEntity != null && approachingDirection != null)
|
||||
{
|
||||
final List<IElectricityNetwork> connectedNetworks = ElectricityNetworkHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
||||
|
||||
if (connectedNetworks.size() > 0)
|
||||
{
|
||||
/**
|
||||
* Requests an even amount of electricity from all sides.
|
||||
*/
|
||||
double wattsPerSide = (producingPack.getWatts() / connectedNetworks.size());
|
||||
double voltage = producingPack.voltage;
|
||||
|
||||
for (IElectricityNetwork network : connectedNetworks)
|
||||
{
|
||||
if (wattsPerSide > 0 && producingPack.getWatts() > 0)
|
||||
{
|
||||
double amperes = wattsPerSide / voltage;
|
||||
network.startProducing(tileEntity, amperes, voltage);
|
||||
remainingElectricity.amperes -= amperes;
|
||||
}
|
||||
else
|
||||
{
|
||||
network.stopProducing(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingElectricity;
|
||||
}
|
||||
|
||||
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||
{
|
||||
return ElectricityNetworkHelper.consumeFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests and attempts to consume electricity from all specified sides. Use this as a simple
|
||||
* helper function.
|
||||
*
|
||||
* @param tileEntity- The TileEntity consuming the electricity.
|
||||
* @param approachDirection - The sides in which you can connect.
|
||||
* @param requestPack - The amount of electricity to be requested.
|
||||
* @return The consumed ElectricityPack.
|
||||
*/
|
||||
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack requestPack)
|
||||
{
|
||||
ElectricityPack consumedPack = new ElectricityPack();
|
||||
|
||||
if (tileEntity != null && approachingDirection != null)
|
||||
{
|
||||
final List<IElectricityNetwork> connectedNetworks = ElectricityNetworkHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
||||
|
||||
if (connectedNetworks.size() > 0)
|
||||
{
|
||||
/**
|
||||
* Requests an even amount of electricity from all sides.
|
||||
*/
|
||||
double wattsPerSide = (requestPack.getWatts() / connectedNetworks.size());
|
||||
double voltage = requestPack.voltage;
|
||||
|
||||
for (IElectricityNetwork network : connectedNetworks)
|
||||
{
|
||||
if (wattsPerSide > 0 && requestPack.getWatts() > 0)
|
||||
{
|
||||
network.startRequesting(tileEntity, wattsPerSide / voltage, voltage);
|
||||
ElectricityPack receivedPack = network.consumeElectricity(tileEntity);
|
||||
consumedPack.amperes += receivedPack.amperes;
|
||||
consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage);
|
||||
}
|
||||
else
|
||||
{
|
||||
network.stopRequesting(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return consumedPack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tileEntity - The TileEntity's sides.
|
||||
* @param approachingDirection - The directions that can be connected.
|
||||
* @return A list of networks from all specified sides. There will be no repeated
|
||||
* ElectricityNetworks and it will never return null.
|
||||
*/
|
||||
public static List<IElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection)
|
||||
{
|
||||
final List<IElectricityNetwork> connectedNetworks = new ArrayList<IElectricityNetwork>();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
|
||||
if (approachingDirection.contains(direction))
|
||||
{
|
||||
Vector3 position = new Vector3(tileEntity);
|
||||
position.modifyPositionFromSide(direction);
|
||||
TileEntity outputConductor = position.getTileEntity(tileEntity.worldObj);
|
||||
IElectricityNetwork electricityNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputConductor, direction);
|
||||
|
||||
if (electricityNetwork != null && !connectedNetworks.contains(connectedNetworks))
|
||||
{
|
||||
connectedNetworks.add(electricityNetwork);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return connectedNetworks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find the electricity network based in a tile entity and checks to see if it is a
|
||||
* conductor. All machines should use this function to search for a connecting conductor around
|
||||
* it.
|
||||
*
|
||||
* @param conductor - The TileEntity conductor
|
||||
* @param approachDirection - The direction you are approaching this wire from.
|
||||
* @return The ElectricityNetwork or null if not found.
|
||||
*/
|
||||
public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection)
|
||||
{
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity instanceof INetworkProvider)
|
||||
{
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(approachDirection.getOpposite()))
|
||||
{
|
||||
return ((INetworkProvider) tileEntity).getNetwork();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((INetworkProvider) tileEntity).getNetwork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -22,19 +22,94 @@ public class ElectricityPack implements Cloneable
|
|||
this(0, 0);
|
||||
}
|
||||
|
||||
public static ElectricityPack getFromWatts(double watts, double voltage)
|
||||
{
|
||||
return new ElectricityPack(watts / voltage, voltage);
|
||||
}
|
||||
|
||||
public double getWatts()
|
||||
{
|
||||
return ElectricInfo.getWatts(amperes, voltage);
|
||||
return getWatts(amperes, voltage);
|
||||
}
|
||||
|
||||
public double getConductance()
|
||||
{
|
||||
return ElectricInfo.getConductance(amperes, voltage);
|
||||
return getConductance(amperes, voltage);
|
||||
}
|
||||
|
||||
public double getResistance()
|
||||
{
|
||||
return ElectricInfo.getResistance(amperes, voltage);
|
||||
return getResistance(amperes, voltage);
|
||||
}
|
||||
|
||||
public static double getJoules(double watts, double seconds)
|
||||
{
|
||||
return watts * seconds;
|
||||
}
|
||||
|
||||
public static double getJoules(double amps, double voltage, double seconds)
|
||||
{
|
||||
return amps * voltage * seconds;
|
||||
}
|
||||
|
||||
public static double getWattsFromJoules(double joules, double seconds)
|
||||
{
|
||||
return joules / seconds;
|
||||
}
|
||||
|
||||
public static double getAmps(double watts, double voltage)
|
||||
{
|
||||
return watts / voltage;
|
||||
}
|
||||
|
||||
public static double getAmps(double ampHours)
|
||||
{
|
||||
return ampHours * 3600;
|
||||
}
|
||||
|
||||
public static double getAmpsFromWattHours(double wattHours, double voltage)
|
||||
{
|
||||
return getWatts(wattHours) / voltage;
|
||||
}
|
||||
|
||||
public static double getWattHoursFromAmpHours(double ampHours, double voltage)
|
||||
{
|
||||
return ampHours * voltage;
|
||||
}
|
||||
|
||||
public static double getAmpHours(double amps)
|
||||
{
|
||||
return amps / 3600;
|
||||
}
|
||||
|
||||
public static double getWatts(double amps, double voltage)
|
||||
{
|
||||
return amps * voltage;
|
||||
}
|
||||
|
||||
public static double getWatts(double wattHours)
|
||||
{
|
||||
return wattHours * 3600;
|
||||
}
|
||||
|
||||
public static double getWattHours(double watts)
|
||||
{
|
||||
return watts / 3600;
|
||||
}
|
||||
|
||||
public static double getWattHours(double amps, double voltage)
|
||||
{
|
||||
return getWattHours(getWatts(amps, voltage));
|
||||
}
|
||||
|
||||
public static double getResistance(double amps, double voltage)
|
||||
{
|
||||
return voltage / amps;
|
||||
}
|
||||
|
||||
public static double getConductance(double amps, double voltage)
|
||||
{
|
||||
return amps / voltage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,7 +124,7 @@ public class ElectricityPack implements Cloneable
|
|||
return new ElectricityPack(this.amperes, this.voltage);
|
||||
}
|
||||
|
||||
public boolean isEquals(ElectricityPack electricityPack)
|
||||
public boolean isEqual(ElectricityPack electricityPack)
|
||||
{
|
||||
return this.amperes == electricityPack.amperes && this.voltage == electricityPack.voltage;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import universalelectricity.core.block.IConductor;
|
||||
|
||||
public interface IConductorRegistry
|
||||
{
|
||||
|
||||
void register(IConductor conductor);
|
||||
|
||||
void cleanConductors();
|
||||
|
||||
void resetAllConnections();
|
||||
|
||||
List<IConductor> getConductors();
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package universalelectricity.core.electricity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnectionProvider;
|
||||
|
||||
/**
|
||||
* The Electrical Network in interface form.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IElectricityNetwork
|
||||
{
|
||||
/**
|
||||
* Sets this TileEntity to start producing energy in this network.
|
||||
*/
|
||||
public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack);
|
||||
|
||||
public void startProducing(TileEntity tileEntity, double amperes, double voltage);
|
||||
|
||||
/**
|
||||
* Is this TileEntity producing electricity?
|
||||
*/
|
||||
public boolean isProducing(TileEntity tileEntity);
|
||||
|
||||
/**
|
||||
* Stops the TileEntity from producing electricity.
|
||||
*/
|
||||
public void stopProducing(TileEntity tileEntity);
|
||||
|
||||
/**
|
||||
* Sets a TileEntity to start requesting electricity from the network.
|
||||
*/
|
||||
public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack);
|
||||
|
||||
public void startRequesting(TileEntity tileEntity, double amperes, double voltage);
|
||||
|
||||
/**
|
||||
* Is this TileEntity requesting electricity?
|
||||
*/
|
||||
public boolean isRequesting(TileEntity tileEntity);
|
||||
|
||||
/**
|
||||
* Stops the TileEntity from requesting electricity from the network.
|
||||
*/
|
||||
public void stopRequesting(TileEntity tileEntity);
|
||||
|
||||
/**
|
||||
* Gets the total amount of electricity produced in the electricity network.
|
||||
*
|
||||
* @param ignoreTiles The TileEntities to ignore during this calculation (optional).
|
||||
*/
|
||||
public ElectricityPack getProduced(TileEntity... ignoreTiles);
|
||||
|
||||
/**
|
||||
* Gets the total amount of electricity requested in the electricity network. Takes account of
|
||||
* electricity being produced in the network.
|
||||
*
|
||||
* @param ignoreTiles The TileEntities to ignore during this calculation (optional).
|
||||
*/
|
||||
public ElectricityPack getRequest(TileEntity... ignoreTiles);
|
||||
|
||||
/**
|
||||
* Gets the total amount of electricity requested WITHOUT accounting in the electricity already
|
||||
* being produced.
|
||||
*/
|
||||
public ElectricityPack getRequestWithoutReduction();
|
||||
|
||||
/**
|
||||
* Attemps to consume electricity for this TileEntity based on what was requested.
|
||||
*
|
||||
* @return The actual amount of electricity consumed.
|
||||
*/
|
||||
public ElectricityPack consumeElectricity(TileEntity tileEntity);
|
||||
|
||||
/**
|
||||
* @return Gets a list of TileEntities currently producing electricity in the network.
|
||||
*
|
||||
*/
|
||||
public HashMap<TileEntity, ElectricityPack> getProducers();
|
||||
|
||||
public List<TileEntity> getProviders();
|
||||
|
||||
/**
|
||||
* @return Gets a list of TileEntities currently receiving electricity from the network.
|
||||
*
|
||||
*/
|
||||
public HashMap<TileEntity, ElectricityPack> getConsumers();
|
||||
|
||||
public List<TileEntity> getReceivers();
|
||||
|
||||
/**
|
||||
* @return A list of all conductors in this electrical network.
|
||||
*/
|
||||
public Set<IConductor> getConductors();
|
||||
|
||||
/**
|
||||
* @return The total amount of resistance of this electrical network. In Ohms.
|
||||
*/
|
||||
public double getTotalResistance();
|
||||
|
||||
/**
|
||||
* @return The lowest amount of current (amperage) that this electrical network can tolerate.
|
||||
*/
|
||||
public double getLowestCurrentCapacity();
|
||||
|
||||
/**
|
||||
* Cleans up and updates the list of conductors in the electricity network, removing dead ones.
|
||||
*/
|
||||
public void cleanUpConductors();
|
||||
|
||||
/**
|
||||
* Refreshes and recalculates wire connections in this electrical network.
|
||||
*
|
||||
*/
|
||||
public void refreshConductors();
|
||||
|
||||
/**
|
||||
* Merges another electrical network into this one, destroying the other network's existence.
|
||||
*
|
||||
* @param network
|
||||
*/
|
||||
public void mergeConnection(IElectricityNetwork network);
|
||||
|
||||
/**
|
||||
* Splits the electricity network at a given TileEntity position. Called usually when a wire is
|
||||
* broken to split the electrical network.
|
||||
*
|
||||
* @param splitPoint - The TileEntity that is being split.
|
||||
*/
|
||||
public void splitNetwork(IConnectionProvider splitPoint);
|
||||
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package universalelectricity.core.implement;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.electricity.ElectricityNetwork;
|
||||
|
||||
/**
|
||||
* Must be applied to all tile entities that are conductors.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IConductor
|
||||
{
|
||||
/**
|
||||
* The electrical network this conductor is on.
|
||||
*/
|
||||
public ElectricityNetwork getNetwork();
|
||||
|
||||
public void setNetwork(ElectricityNetwork network);
|
||||
|
||||
/**
|
||||
* The UE tile entities that this conductor is connected to.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TileEntity[] getConnectedBlocks();
|
||||
|
||||
/**
|
||||
* Gets the resistance of the conductor. Used to calculate energy loss. A higher resistance
|
||||
* means a higher energy loss.
|
||||
*
|
||||
* @return The amount of Ohm's of resistance.
|
||||
*/
|
||||
public double getResistance();
|
||||
|
||||
/**
|
||||
* The maximum amount of amps this conductor can handle before melting down. This is calculating
|
||||
* PER TICK!
|
||||
*
|
||||
* @return The amount of amps in volts
|
||||
*/
|
||||
public double getMaxAmps();
|
||||
|
||||
/**
|
||||
* Called when the electricity passing through exceeds the maximum voltage.
|
||||
*/
|
||||
public void onOverCharge();
|
||||
|
||||
/**
|
||||
* Resets the conductor and recalculate connection IDs again
|
||||
*/
|
||||
public void reset();
|
||||
|
||||
/**
|
||||
* Instantly refreshes all connected blocks
|
||||
*/
|
||||
public void refreshConnectedBlocks();
|
||||
|
||||
/**
|
||||
* Adds a connection between this conductor and a UE unit
|
||||
*
|
||||
* @param tileEntity - Must be either a producer, consumer or a conductor
|
||||
* @param side - side in which the connection is coming from
|
||||
*/
|
||||
public void updateConnection(TileEntity tileEntity, ForgeDirection side);
|
||||
|
||||
public void updateConnectionWithoutSplit(TileEntity connectorFromSide, ForgeDirection orientation);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package universalelectricity.core.implement;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemElectric extends IJouleStorage, IVoltage
|
||||
{
|
||||
/**
|
||||
* Called when this item receives electricity.
|
||||
*/
|
||||
public double onReceive(double amps, double voltage, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Called when something requests electricity from this item.
|
||||
*
|
||||
* @return - The amount of given joules
|
||||
*/
|
||||
public double onUse(double joulesNeeded, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* @return Returns true or false if this consumer can receive electricity at this given tick or
|
||||
* moment.
|
||||
*/
|
||||
public boolean canReceiveElectricity();
|
||||
|
||||
/**
|
||||
* Can this item give out electricity when placed in an tile entity? Electric items like
|
||||
* batteries should be able to produce electricity (if they are rechargeable).
|
||||
*
|
||||
* @return - True or False.
|
||||
*/
|
||||
public boolean canProduceElectricity();
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package universalelectricity.core.implement;
|
||||
|
||||
/**
|
||||
* This interface is to be applied to all tile entities which stores energy within them.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public interface IJouleStorage
|
||||
{
|
||||
/**
|
||||
* Returns the amount of joules this unit has stored.
|
||||
*/
|
||||
public double getJoules(Object... data);
|
||||
|
||||
/**
|
||||
* Sets the amount of joules this unit has stored.
|
||||
*/
|
||||
public void setJoules(double joules, Object... data);
|
||||
|
||||
/**
|
||||
* Gets the maximum amount of joules this unit can store.
|
||||
*/
|
||||
public double getMaxJoules(Object... data);
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
|
||||
/**
|
||||
* Some helper functions for electric items.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ElectricItemHelper
|
||||
{
|
||||
/**
|
||||
* Recharges an electric item.
|
||||
*
|
||||
* @param joules - The joules being provided to the electric item
|
||||
* @param voltage - The voltage in which is used to charge the electric item
|
||||
* @return The total amount of joules provided by the provider.
|
||||
*/
|
||||
public static double chargeItem(ItemStack itemStack, double joules, double voltage)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
IItemElectric electricItem = (IItemElectric) itemStack.getItem();
|
||||
double providingWatts = Math.min(joules, electricItem.getReceiveRequest(itemStack).getWatts());
|
||||
|
||||
if (providingWatts > 0)
|
||||
{
|
||||
ElectricityPack providedElectricity = electricItem.onReceive(ElectricityPack.getFromWatts(providingWatts, voltage), itemStack);
|
||||
return providedElectricity.getWatts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decharge an electric item.
|
||||
*
|
||||
* @param joules - The joules being withdrawn from the electric item
|
||||
* @param voltage - The voltage in which is used to decharge the electric item
|
||||
* @return The total amount of joules the provider received.
|
||||
*/
|
||||
public static double dechargeItem(ItemStack itemStack, double joules, double voltage)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
IItemElectric electricItem = (IItemElectric) itemStack.getItem();
|
||||
double requestingWatts = Math.min(joules, electricItem.getProvideRequest(itemStack).getWatts());
|
||||
|
||||
if (requestingWatts > 0)
|
||||
{
|
||||
ElectricityPack receivedElectricity = electricItem.onProvide(ElectricityPack.getFromWatts(requestingWatts, voltage), itemStack);
|
||||
return receivedElectricity.getWatts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an uncharged version of the electric item. Use this if you want the crafting recipe
|
||||
* to use a charged version of the electric item instead of an empty version of the electric
|
||||
* item
|
||||
*
|
||||
* @return An electrical ItemStack with a specific charge.
|
||||
*/
|
||||
public static ItemStack getWithCharge(ItemStack itemStack, double joules)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
((IItemElectric) itemStack.getItem()).setJoules(joules, itemStack);
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStack getWithCharge(Item item, double joules)
|
||||
{
|
||||
return getWithCharge(new ItemStack(item), joules);
|
||||
}
|
||||
|
||||
public static ItemStack getCloneWithCharge(ItemStack itemStack, double joules)
|
||||
{
|
||||
return getWithCharge(itemStack.copy(), joules);
|
||||
}
|
||||
|
||||
public static ItemStack getUncharged(ItemStack itemStack)
|
||||
{
|
||||
return getWithCharge(itemStack, 0);
|
||||
}
|
||||
|
||||
public static ItemStack getUncharged(Item item)
|
||||
{
|
||||
return getUncharged(new ItemStack(item));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
|
||||
/**
|
||||
* An interface applied to all electrical items. Should be applied to the Item class.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IItemElectric extends IItemElectricityStorage, IItemVoltage
|
||||
{
|
||||
/**
|
||||
* Called when this item receives electricity; being charged.
|
||||
*
|
||||
* @return The amount of electricity that was added to the electric item.
|
||||
*/
|
||||
public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Called when something requests electricity from this item; being decharged.
|
||||
*
|
||||
* @return - The amount of electricity that was removed from the electric item.
|
||||
*/
|
||||
public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* @return How much electricity does this item want to receive/take? This will affect the speed
|
||||
* in which items get charged per tick.
|
||||
*/
|
||||
public ElectricityPack getReceiveRequest(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return How much electricity does this item want to provide/give out? This will affect the
|
||||
* speed in which items get decharged per tick.
|
||||
*/
|
||||
public ElectricityPack getProvideRequest(ItemStack itemStack);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemElectricityStorage
|
||||
{
|
||||
/**
|
||||
* Returns the amount of joules this unit has stored.
|
||||
*/
|
||||
public double getJoules(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Sets the amount of joules this unit has stored.
|
||||
*/
|
||||
public void setJoules(double joules, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Gets the maximum amount of joules this unit can store.
|
||||
*/
|
||||
public double getMaxJoules(ItemStack itemStack);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Applies to items that has a voltage.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IItemVoltage
|
||||
{
|
||||
|
||||
/**
|
||||
* @return The voltage in which this item runs on.
|
||||
*/
|
||||
public double getVoltage(ItemStack itemStack);
|
||||
}
|
153
src/minecraft/universalelectricity/core/item/ItemElectric.java
Normal file
153
src/minecraft/universalelectricity/core/item/ItemElectric.java
Normal file
|
@ -0,0 +1,153 @@
|
|||
package universalelectricity.core.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
|
||||
/**
|
||||
* Extend from this class if your item requires electricity or to be charged. Optionally, you can
|
||||
* implement IItemElectric instead.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class ItemElectric extends Item implements IItemElectric
|
||||
{
|
||||
public ItemElectric(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(100);
|
||||
this.setNoRepair();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
|
||||
{
|
||||
String color = "";
|
||||
double joules = this.getJoules(itemStack);
|
||||
|
||||
if (joules <= this.getMaxJoules(itemStack) / 3)
|
||||
{
|
||||
color = "\u00a74";
|
||||
}
|
||||
else if (joules > this.getMaxJoules(itemStack) * 2 / 3)
|
||||
{
|
||||
color = "\u00a72";
|
||||
}
|
||||
else
|
||||
{
|
||||
color = "\u00a76";
|
||||
}
|
||||
|
||||
list.add(color + ElectricityDisplay.getDisplay(joules, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplay(this.getMaxJoules(itemStack), ElectricUnit.JOULES));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
|
||||
* not want this to happen!
|
||||
*/
|
||||
@Override
|
||||
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
itemStack = ElectricItemHelper.getUncharged(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack)
|
||||
{
|
||||
double rejectedElectricity = Math.max((this.getJoules(itemStack) + electricityPack.getWatts()) - this.getMaxJoules(itemStack), 0);
|
||||
double joulesToStore = electricityPack.getWatts() - rejectedElectricity;
|
||||
this.setJoules(this.getJoules(itemStack) + joulesToStore, itemStack);
|
||||
return ElectricityPack.getFromWatts(joulesToStore, this.getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack)
|
||||
{
|
||||
double electricityToUse = Math.min(this.getJoules(itemStack), electricityPack.getWatts());
|
||||
this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack);
|
||||
return ElectricityPack.getFromWatts(electricityToUse, this.getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getReceiveRequest(ItemStack itemStack)
|
||||
{
|
||||
return ElectricityPack.getFromWatts(Math.min(this.getMaxJoules(itemStack) - this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getProvideRequest(ItemStack itemStack)
|
||||
{
|
||||
return ElectricityPack.getFromWatts(Math.min(this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack));
|
||||
}
|
||||
|
||||
public double getTransferRate(ItemStack itemStack)
|
||||
{
|
||||
return this.getMaxJoules(itemStack) * 0.01;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets the electriicty. Do not directly call this function. Try to use
|
||||
* onReceiveElectricity or onUseElectricity instead.
|
||||
*
|
||||
* @param joules - The amount of electricity in joules
|
||||
*/
|
||||
@Override
|
||||
public void setJoules(double joules, ItemStack itemStack)
|
||||
{
|
||||
// Saves the frequency in the ItemStack
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
double electricityStored = Math.max(Math.min(joules, this.getMaxJoules(itemStack)), 0);
|
||||
itemStack.getTagCompound().setDouble("electricity", electricityStored);
|
||||
|
||||
/**
|
||||
* Sets the damage as a percentage to render the bar properly.
|
||||
*/
|
||||
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxJoules(itemStack)) * 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called to get the electricity stored in this item
|
||||
*
|
||||
* @return - The amount of electricity stored in watts
|
||||
*/
|
||||
@Override
|
||||
public double getJoules(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double electricityStored = itemStack.getTagCompound().getDouble("electricity");
|
||||
|
||||
/**
|
||||
* Sets the damage as a percentage to render the bar properly.
|
||||
*/
|
||||
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxJoules(itemStack)) * 100));
|
||||
return electricityStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
// Add an uncharged version of the electric item
|
||||
par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this)));
|
||||
// Add an electric item to the creative list that is fully charged
|
||||
ItemStack chargedItem = new ItemStack(this);
|
||||
par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxJoules(chargedItem)));
|
||||
}
|
||||
}
|
107
src/minecraft/universalelectricity/core/path/Pathfinder.java
Normal file
107
src/minecraft/universalelectricity/core/path/Pathfinder.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConnectionProvider;
|
||||
|
||||
/**
|
||||
* A class that allows flexible path finding in Minecraft Blocks.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class Pathfinder
|
||||
{
|
||||
public interface IPathCallBack
|
||||
{
|
||||
/**
|
||||
* Is this a valid node to search for?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isValidNode(Pathfinder finder, ForgeDirection direction, IConnectionProvider provider, IConnectionProvider node);
|
||||
|
||||
/**
|
||||
* Called when looping through nodes.
|
||||
*
|
||||
* @param finder
|
||||
* @param provider
|
||||
* @return True to stop the path finding operation.
|
||||
*/
|
||||
public boolean onSearch(Pathfinder finder, IConnectionProvider provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* A pathfinding call back interface used to call back on paths.
|
||||
*/
|
||||
public IPathCallBack callBackCheck;
|
||||
|
||||
/**
|
||||
* A list of nodes that the pathfinder went through.
|
||||
*/
|
||||
public List<IConnectionProvider> iteratedNodes;
|
||||
|
||||
/**
|
||||
* The results and findings found by the pathfinder.
|
||||
*/
|
||||
public List results;
|
||||
|
||||
public Pathfinder(IPathCallBack callBack)
|
||||
{
|
||||
this.callBackCheck = callBack;
|
||||
this.clear();
|
||||
}
|
||||
|
||||
public boolean findNodes(IConnectionProvider provider)
|
||||
{
|
||||
TileEntity[] connectedBlocks = provider.getAdjacentConnections();
|
||||
|
||||
this.iteratedNodes.add(provider);
|
||||
|
||||
if (this.callBackCheck.onSearch(this, provider))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
TileEntity connectedBlock = connectedBlocks[i];
|
||||
|
||||
if (connectedBlock instanceof IConnectionProvider)
|
||||
{
|
||||
if (!iteratedNodes.contains(connectedBlock))
|
||||
{
|
||||
if (this.callBackCheck.isValidNode(this, ForgeDirection.getOrientation(i), provider, (IConnectionProvider) connectedBlock))
|
||||
{
|
||||
if (!this.findNodes((IConnectionProvider) connectedBlock))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to execute the pathfinding operation.
|
||||
*/
|
||||
public Pathfinder init(IConnectionProvider provider)
|
||||
{
|
||||
this.findNodes(provider);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pathfinder clear()
|
||||
{
|
||||
this.iteratedNodes = new ArrayList<IConnectionProvider>();
|
||||
this.results = new ArrayList();
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnectionProvider;
|
||||
|
||||
/**
|
||||
* Check if a conductor connects with another.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class PathfinderChecker extends Pathfinder
|
||||
{
|
||||
public PathfinderChecker(final IConnectionProvider targetConnector, final IConnectionProvider... ignoreConnector)
|
||||
{
|
||||
super(new IPathCallBack()
|
||||
{
|
||||
@Override
|
||||
public boolean isValidNode(Pathfinder finder, ForgeDirection direction, IConnectionProvider provider, IConnectionProvider connectedBlock)
|
||||
{
|
||||
if (connectedBlock instanceof IConductor && !Arrays.asList(ignoreConnector).contains(connectedBlock))
|
||||
{
|
||||
if (((IConductor) connectedBlock).canConnect(direction.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSearch(Pathfinder finder, IConnectionProvider provider)
|
||||
{
|
||||
if (provider == targetConnector)
|
||||
{
|
||||
finder.results.add(provider);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package universalelectricity.core.path;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnectionProvider;
|
||||
|
||||
/**
|
||||
* Finds all the possible conductors. Inspired by A* Pathfinding Algorithm.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class PathfinderShortestConnection extends Pathfinder
|
||||
{
|
||||
/**
|
||||
* The score of this specific path. The higher the score, the better the path is.
|
||||
*/
|
||||
public HashMap<IConnectionProvider, Integer> gScore = new HashMap<IConnectionProvider, Integer>();
|
||||
|
||||
public PathfinderShortestConnection()
|
||||
{
|
||||
super(new IPathCallBack()
|
||||
{
|
||||
@Override
|
||||
public boolean isValidNode(Pathfinder finder, ForgeDirection direction, IConnectionProvider provider, IConnectionProvider connectedBlock)
|
||||
{
|
||||
if (connectedBlock instanceof IConductor)
|
||||
{
|
||||
if (((IConductor) connectedBlock).canConnect(direction.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSearch(Pathfinder finder, IConnectionProvider provider)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pathfinder clear()
|
||||
{
|
||||
this.gScore.clear();
|
||||
return super.clear();
|
||||
}
|
||||
}
|
|
@ -3,9 +3,7 @@ package universalelectricity.core.vector;
|
|||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Vector2 Class is used for defining objects in a 2D space. Vector2 makes it easier to handle the
|
||||
* coordinates of objects. Instead of fumbling with x and y variables, all x and y variables are
|
||||
* stored in one class. Vector3.x, Vector3.y.
|
||||
* Vector2 Class is used for defining objects in a 2D space.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
@ -20,19 +18,17 @@ public class Vector2 implements Cloneable
|
|||
this(0, 0);
|
||||
}
|
||||
|
||||
public Vector2(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vector2(double x, double y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
// Returns the values as an int
|
||||
/**
|
||||
* Returns the integer floor value.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int intX()
|
||||
{
|
||||
return (int) Math.floor(this.x);
|
||||
|
@ -52,42 +48,52 @@ public class Vector2 implements Cloneable
|
|||
return new Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
public static double distance(Vector2 par1, Vector2 par2)
|
||||
public static double distance(Vector2 point1, Vector2 point2)
|
||||
{
|
||||
double var2 = par1.x - par2.x;
|
||||
double var4 = par1.y - par2.y;
|
||||
return MathHelper.sqrt_double(var2 * var2 + var4 * var4);
|
||||
double xDifference = point1.x - point2.x;
|
||||
double yDiference = point1.y - point2.y;
|
||||
return MathHelper.sqrt_double(xDifference * xDifference + yDiference * yDiference);
|
||||
}
|
||||
|
||||
public static double slope(Vector2 par1, Vector2 par2)
|
||||
public static double slope(Vector2 point1, Vector2 point2)
|
||||
{
|
||||
double var2 = par1.x - par2.x;
|
||||
double var4 = par1.y - par2.y;
|
||||
return var4 / var2;
|
||||
double xDifference = point1.x - point2.x;
|
||||
double yDiference = point1.y - point2.y;
|
||||
return yDiference / xDifference;
|
||||
}
|
||||
|
||||
public void add(Vector2 par1)
|
||||
public double distanceTo(Vector2 target)
|
||||
{
|
||||
double xDifference = this.x - target.x;
|
||||
double yDifference = this.y - target.y;
|
||||
return MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference);
|
||||
}
|
||||
|
||||
public Vector2 add(Vector2 par1)
|
||||
{
|
||||
this.x += par1.x;
|
||||
this.y += par1.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void add(double par1)
|
||||
public Vector2 add(double par1)
|
||||
{
|
||||
this.x += par1;
|
||||
this.y += par1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void substract(Vector2 par1)
|
||||
public Vector2 invert()
|
||||
{
|
||||
this.x -= par1.x;
|
||||
this.y -= par1.y;
|
||||
this.multiply(-1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void substract(double par1)
|
||||
public Vector2 multiply(double amount)
|
||||
{
|
||||
this.x -= par1;
|
||||
this.y -= par1;
|
||||
this.x *= amount;
|
||||
this.y *= amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 round()
|
||||
|
@ -100,7 +106,7 @@ public class Vector2 implements Cloneable
|
|||
return new Vector2(Math.floor(this.x), Math.floor(this.y));
|
||||
}
|
||||
|
||||
public boolean isEquals(Vector2 vector)
|
||||
public boolean isEqual(Vector2 vector)
|
||||
{
|
||||
return this.x == vector.x && this.y == vector.y;
|
||||
}
|
||||
|
|
|
@ -13,18 +13,17 @@ import net.minecraft.util.Vec3;
|
|||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.electricity.ElectricityConnections;
|
||||
|
||||
/**
|
||||
* Vector3 Class is used for defining objects in a 3D space. Vector3 makes it easier to handle the
|
||||
* coordinates of objects. Instead of fumbling with x, y and z variables, all x, y and z variables
|
||||
* are stored in one class. Vector3.x, Vector3.y, Vector3.z.
|
||||
* Vector3 Class is used for defining objects in a 3D space.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
||||
public class Vector3 extends Vector2 implements Cloneable
|
||||
public class Vector3 implements Cloneable
|
||||
{
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
||||
public Vector3()
|
||||
|
@ -32,13 +31,6 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Vector3(int x, int y, int z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
|
@ -82,7 +74,7 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the coordinates as integers
|
||||
* Returns the coordinates as integers, ideal for block placement.
|
||||
*/
|
||||
public int intX()
|
||||
{
|
||||
|
@ -99,9 +91,12 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return (int) Math.floor(this.z);
|
||||
}
|
||||
|
||||
public boolean isEquals(Vector3 vector)
|
||||
/**
|
||||
* Compares two vectors and see if they are equal. True if so.
|
||||
*/
|
||||
public boolean isEqual(Vector3 vector3)
|
||||
{
|
||||
return this.x == vector.x && this.y == vector.y && this.z == vector.z;
|
||||
return (this.x == vector3.x && this.y == vector3.y && this.z == vector3.z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,6 +108,12 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return new Vector3(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Easy block access functions.
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public int getBlockID(IBlockAccess world)
|
||||
{
|
||||
return world.getBlockId(this.intX(), this.intY(), this.intZ());
|
||||
|
@ -128,24 +129,14 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return world.getBlockTileEntity(this.intX(), this.intY(), this.intZ());
|
||||
}
|
||||
|
||||
public void setBlock(World world, int id, int metadata)
|
||||
public boolean setBlock(World world, int id, int metadata)
|
||||
{
|
||||
world.setBlockAndMetadata(this.intX(), this.intY(), this.intZ(), id, metadata);
|
||||
return world.setBlockAndMetadataWithNotify(this.intX(), this.intY(), this.intZ(), id, metadata, 2);
|
||||
}
|
||||
|
||||
public void setBlock(World world, int id)
|
||||
public boolean setBlock(World world, int id)
|
||||
{
|
||||
world.setBlock(this.intX(), this.intY(), this.intZ(), id);
|
||||
}
|
||||
|
||||
public void setBlockWithNotify(World world, int id, int metadata)
|
||||
{
|
||||
world.setBlockAndMetadataWithNotify(this.intX(), this.intY(), this.intZ(), id, metadata);
|
||||
}
|
||||
|
||||
public void setBlockWithNotify(World world, int id)
|
||||
{
|
||||
world.setBlockWithNotify(this.intX(), this.intY(), this.intZ(), id);
|
||||
return world.setBlockAndMetadataWithNotify(this.intX(), this.intY(), this.intZ(), id, 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,14 +155,6 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return Vec3.createVectorHelper(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two vectors and see if they are equal. True if so.
|
||||
*/
|
||||
public boolean isEqual(Vector3 vector3)
|
||||
{
|
||||
return (this.x == vector3.x && this.y == vector3.y && this.z == vector3.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance between two vectors
|
||||
*
|
||||
|
@ -193,6 +176,55 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
|
||||
}
|
||||
|
||||
public Vector3 add(Vector3 par1)
|
||||
{
|
||||
this.x += par1.x;
|
||||
this.y += par1.y;
|
||||
this.z += par1.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 add(double par1)
|
||||
{
|
||||
this.x += par1;
|
||||
this.y += par1;
|
||||
this.z += par1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 subtract(Vector3 amount)
|
||||
{
|
||||
this.x -= amount.x;
|
||||
this.y -= amount.y;
|
||||
this.z -= amount.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies the vector by negative one.
|
||||
*/
|
||||
public Vector3 invert()
|
||||
{
|
||||
this.multiply(-1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 multiply(double amount)
|
||||
{
|
||||
this.x *= amount;
|
||||
this.y *= amount;
|
||||
this.z *= amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3 multiply(Vector3 vec)
|
||||
{
|
||||
this.x *= vec.x;
|
||||
this.y *= vec.y;
|
||||
this.z *= vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Vector3 subtract(Vector3 par1, Vector3 par2)
|
||||
{
|
||||
return new Vector3(par1.x - par2.x, par1.y - par2.y, par1.z - par2.z);
|
||||
|
@ -208,42 +240,6 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return new Vector3(par1.x + par2, par1.y + par2, par1.z + par2);
|
||||
}
|
||||
|
||||
public void add(Vector3 par1)
|
||||
{
|
||||
this.x += par1.x;
|
||||
this.y += par1.y;
|
||||
this.z += par1.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(double par1)
|
||||
{
|
||||
this.x += par1;
|
||||
this.y += par1;
|
||||
this.z += par1;
|
||||
}
|
||||
|
||||
public void subtract(Vector3 amount)
|
||||
{
|
||||
this.x -= amount.x;
|
||||
this.y -= amount.y;
|
||||
this.z -= amount.z;
|
||||
}
|
||||
|
||||
public void multiply(double amount)
|
||||
{
|
||||
this.x *= amount;
|
||||
this.y *= amount;
|
||||
this.z *= amount;
|
||||
}
|
||||
|
||||
public void multiply(Vector3 vec)
|
||||
{
|
||||
this.x *= vec.x;
|
||||
this.y *= vec.y;
|
||||
this.z *= vec.z;
|
||||
}
|
||||
|
||||
public static Vector3 multiply(Vector3 vec1, Vector3 vec2)
|
||||
{
|
||||
return new Vector3(vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z);
|
||||
|
@ -254,35 +250,11 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
return new Vector3(vec1.x * vec2, vec1.y * vec2, vec1.z * vec2);
|
||||
}
|
||||
|
||||
public static Vector3 readFromNBT(String prefix, NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
Vector3 tempVector = new Vector3();
|
||||
tempVector.x = par1NBTTagCompound.getDouble(prefix + "X");
|
||||
tempVector.y = par1NBTTagCompound.getDouble(prefix + "Y");
|
||||
tempVector.z = par1NBTTagCompound.getDouble(prefix + "Z");
|
||||
return tempVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this Vector3 to disk
|
||||
*
|
||||
* @param prefix - The prefix of this save. Use some unique string.
|
||||
* @param par1NBTTagCompound - The NBT compound object to save the data in
|
||||
*/
|
||||
public void writeToNBT(String prefix, NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
par1NBTTagCompound.setDouble(prefix + "X", this.x);
|
||||
par1NBTTagCompound.setDouble(prefix + "Y", this.y);
|
||||
par1NBTTagCompound.setDouble(prefix + "Z", this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 round()
|
||||
{
|
||||
return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 floor()
|
||||
{
|
||||
return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
|
||||
|
@ -297,13 +269,13 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets a position relative to another position's side
|
||||
* Gets a position relative to a position's side
|
||||
*
|
||||
* @param position - The position
|
||||
* @param side - The side. 0-5
|
||||
* @return The position relative to the original position's side
|
||||
*/
|
||||
public void modifyPositionFromSide(ForgeDirection side, double amount)
|
||||
public Vector3 modifyPositionFromSide(ForgeDirection side, double amount)
|
||||
{
|
||||
switch (side.ordinal())
|
||||
{
|
||||
|
@ -326,143 +298,45 @@ public class Vector3 extends Vector2 implements Cloneable
|
|||
this.x += amount;
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void modifyPositionFromSide(ForgeDirection side)
|
||||
public Vector3 modifyPositionFromSide(ForgeDirection side)
|
||||
{
|
||||
this.modifyPositionFromSide(side, 1);
|
||||
}
|
||||
|
||||
public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side)
|
||||
{
|
||||
position.modifyPositionFromSide(side);
|
||||
return world.getBlockTileEntity(position.intX(), position.intY(), position.intZ());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connector unit based on the given side.
|
||||
* Loads a Vector3 from an NBT compound.
|
||||
*/
|
||||
public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side)
|
||||
public static Vector3 readFromNBT(NBTTagCompound nbtCompound)
|
||||
{
|
||||
TileEntity tileEntity = getTileEntityFromSide(world, position, side);
|
||||
|
||||
if (ElectricityConnections.isConnector(tileEntity))
|
||||
{
|
||||
if (ElectricityConnections.canConnect(tileEntity, getOrientationFromSide(side, ForgeDirection.NORTH)))
|
||||
{
|
||||
return tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
Vector3 tempVector = new Vector3();
|
||||
tempVector.x = nbtCompound.getDouble("x");
|
||||
tempVector.y = nbtCompound.getDouble("y");
|
||||
tempVector.z = nbtCompound.getDouble("z");
|
||||
return tempVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the side of a block depending on it's facing direction from the given side. The side
|
||||
* numbers are compatible with the function "getBlockTextureFromSideAndMetadata".
|
||||
* Saves this Vector3 to disk
|
||||
*
|
||||
* Bottom: 0; Top: 1; Back: 2; Front: 3; Left: 4; Right: 5;
|
||||
*
|
||||
* @param front - The direction in which this block is facing/front. Use a number between 0 and
|
||||
* 5. Default is 3.
|
||||
* @param side - The side you are trying to find. A number between 0 and 5.
|
||||
* @return The side relative to the facing direction.
|
||||
* @param prefix - The prefix of this save. Use some unique string.
|
||||
* @param par1NBTTagCompound - The NBT compound object to save the data in
|
||||
*/
|
||||
|
||||
public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side)
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
switch (front.ordinal())
|
||||
{
|
||||
case 0:
|
||||
switch (side.ordinal())
|
||||
{
|
||||
case 0:
|
||||
return ForgeDirection.getOrientation(3);
|
||||
case 1:
|
||||
return ForgeDirection.getOrientation(2);
|
||||
case 2:
|
||||
return ForgeDirection.getOrientation(1);
|
||||
case 3:
|
||||
return ForgeDirection.getOrientation(0);
|
||||
case 4:
|
||||
return ForgeDirection.getOrientation(5);
|
||||
case 5:
|
||||
return ForgeDirection.getOrientation(4);
|
||||
}
|
||||
par1NBTTagCompound.setDouble("x", this.x);
|
||||
par1NBTTagCompound.setDouble("y", this.y);
|
||||
par1NBTTagCompound.setDouble("z", this.z);
|
||||
return par1NBTTagCompound;
|
||||
}
|
||||
|
||||
case 1:
|
||||
switch (side.ordinal())
|
||||
{
|
||||
case 0:
|
||||
return ForgeDirection.getOrientation(4);
|
||||
case 1:
|
||||
return ForgeDirection.getOrientation(5);
|
||||
case 2:
|
||||
return ForgeDirection.getOrientation(0);
|
||||
case 3:
|
||||
return ForgeDirection.getOrientation(1);
|
||||
case 4:
|
||||
return ForgeDirection.getOrientation(2);
|
||||
case 5:
|
||||
return ForgeDirection.getOrientation(3);
|
||||
}
|
||||
|
||||
case 2:
|
||||
switch (side.ordinal())
|
||||
{
|
||||
case 0:
|
||||
return ForgeDirection.getOrientation(0);
|
||||
case 1:
|
||||
return ForgeDirection.getOrientation(1);
|
||||
case 2:
|
||||
return ForgeDirection.getOrientation(3);
|
||||
case 3:
|
||||
return ForgeDirection.getOrientation(2);
|
||||
case 4:
|
||||
return ForgeDirection.getOrientation(5);
|
||||
case 5:
|
||||
return ForgeDirection.getOrientation(4);
|
||||
}
|
||||
|
||||
case 3:
|
||||
return side;
|
||||
|
||||
case 4:
|
||||
switch (side.ordinal())
|
||||
{
|
||||
case 0:
|
||||
return ForgeDirection.getOrientation(0);
|
||||
case 1:
|
||||
return ForgeDirection.getOrientation(1);
|
||||
case 2:
|
||||
return ForgeDirection.getOrientation(5);
|
||||
case 3:
|
||||
return ForgeDirection.getOrientation(4);
|
||||
case 4:
|
||||
return ForgeDirection.getOrientation(3);
|
||||
case 5:
|
||||
return ForgeDirection.getOrientation(2);
|
||||
}
|
||||
|
||||
case 5:
|
||||
switch (side.ordinal())
|
||||
{
|
||||
case 0:
|
||||
return ForgeDirection.getOrientation(0);
|
||||
case 1:
|
||||
return ForgeDirection.getOrientation(1);
|
||||
case 2:
|
||||
return ForgeDirection.getOrientation(4);
|
||||
case 3:
|
||||
return ForgeDirection.getOrientation(5);
|
||||
case 4:
|
||||
return ForgeDirection.getOrientation(2);
|
||||
case 5:
|
||||
return ForgeDirection.getOrientation(3);
|
||||
}
|
||||
}
|
||||
|
||||
return ForgeDirection.UNKNOWN;
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return ("X:" + this.x + "Y:" + this.y + "Z:" + this.z).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package universalelectricity.core.vector;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
|
||||
public class VectorHelper
|
||||
{
|
||||
public static final int[][] RELATIVE_MATRIX = { { 3, 2, 1, 0, 5, 4 }, { 4, 5, 0, 1, 2, 3 }, { 0, 1, 3, 2, 5, 4 }, { 0, 1, 2, 3, 4, 5 }, { 0, 1, 5, 4, 3, 2 }, { 0, 1, 4, 5, 2, 3 } };
|
||||
|
||||
/**
|
||||
* Finds the direction relative to a base direction.
|
||||
*
|
||||
* @param front - The direction in which this block is facing/front. Use a number between 0 and
|
||||
* 5. Default is 3.
|
||||
* @param side - The side you are trying to find. A number between 0 and 5.
|
||||
* @return The side relative to the facing direction.
|
||||
*/
|
||||
public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side)
|
||||
{
|
||||
if (front != ForgeDirection.UNKNOWN && side != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
return ForgeDirection.getOrientation(RELATIVE_MATRIX[front.ordinal()][side.ordinal()]);
|
||||
}
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connector unit based on the given side.
|
||||
*/
|
||||
public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side)
|
||||
{
|
||||
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world, position, side);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH)))
|
||||
{
|
||||
return tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side)
|
||||
{
|
||||
return position.clone().modifyPositionFromSide(side).getTileEntity(world);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import net.minecraft.util.DamageSource;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class CustomDamageSource extends DamageSource
|
||||
{
|
||||
/**
|
||||
* Use this damage source for all types of electrical attacks.
|
||||
*/
|
||||
public static final CustomDamageSource electrocution = ((CustomDamageSource) new CustomDamageSource("electrocution").setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!");
|
||||
|
||||
public CustomDamageSource(String damageType)
|
||||
{
|
||||
super(damageType);
|
||||
}
|
||||
|
||||
public CustomDamageSource setDeathMessage(String deathMessage)
|
||||
{
|
||||
LanguageRegistry.instance().addStringLocalization("death.attack." + this.damageType, deathMessage);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSource setDamageBypassesArmor()
|
||||
{
|
||||
return super.setDamageBypassesArmor();
|
||||
}
|
||||
|
||||
public DamageSource setDamageAllowedInCreativeMode()
|
||||
{
|
||||
return super.setDamageAllowedInCreativeMode();
|
||||
}
|
||||
|
||||
public DamageSource setFireDamage()
|
||||
{
|
||||
return super.setFireDamage();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
|
@ -123,22 +121,22 @@ public abstract class GuiBase extends GuiScreen
|
|||
}
|
||||
}
|
||||
|
||||
public void drawTooltip(List<String> toolTips, int x, int y)
|
||||
public void drawTooltip(int x, int y, String... toolTips)
|
||||
{
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
if (!toolTips.isEmpty())
|
||||
if (toolTips != null)
|
||||
{
|
||||
int var5 = 0;
|
||||
int var6;
|
||||
int var7;
|
||||
|
||||
for (var6 = 0; var6 < toolTips.size(); ++var6)
|
||||
for (var6 = 0; var6 < toolTips.length; ++var6)
|
||||
{
|
||||
var7 = this.fontRenderer.getStringWidth((String) toolTips.get(var6));
|
||||
var7 = this.fontRenderer.getStringWidth((String) toolTips[var6]);
|
||||
|
||||
if (var7 > var5)
|
||||
{
|
||||
|
@ -150,9 +148,9 @@ public abstract class GuiBase extends GuiScreen
|
|||
var7 = y - 12;
|
||||
int var9 = 8;
|
||||
|
||||
if (toolTips.size() > 1)
|
||||
if (toolTips.length > 1)
|
||||
{
|
||||
var9 += 2 + (toolTips.size() - 1) * 10;
|
||||
var9 += 2 + (toolTips.length - 1) * 10;
|
||||
}
|
||||
|
||||
if (this.guiTop + var7 + var9 + 6 > this.height)
|
||||
|
@ -174,9 +172,9 @@ public abstract class GuiBase extends GuiScreen
|
|||
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
|
||||
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
|
||||
|
||||
for (int var13 = 0; var13 < toolTips.size(); ++var13)
|
||||
for (int var13 = 0; var13 < toolTips.length; ++var13)
|
||||
{
|
||||
String var14 = "\u00a77" + toolTips.get(var13);
|
||||
String var14 = toolTips[var13];
|
||||
|
||||
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
|
||||
|
||||
|
@ -190,5 +188,10 @@ public abstract class GuiBase extends GuiScreen
|
|||
|
||||
this.zLevel = 0.0F;
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
}
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.electricity.ElectricInfo;
|
||||
import universalelectricity.core.electricity.ElectricInfo.ElectricUnit;
|
||||
import universalelectricity.core.implement.IItemElectric;
|
||||
|
||||
/**
|
||||
* Extend from this class if your item requires electricity or to be charged. Optionally, you can
|
||||
* implement IItemElectric instead.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class ItemElectric extends Item implements IItemElectric
|
||||
{
|
||||
public ItemElectric(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(100);
|
||||
this.setNoRepair();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows items to add custom lines of information to the mouseover description. If you want to
|
||||
* add more information to your item, you can super.addInformation() to keep the electiricty
|
||||
* info in the item info bar.
|
||||
*/
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||
{
|
||||
String color = "";
|
||||
double joules = this.getJoules(par1ItemStack);
|
||||
|
||||
if (joules <= this.getMaxJoules(par1ItemStack) / 3)
|
||||
{
|
||||
color = "\u00a74";
|
||||
}
|
||||
else if (joules > this.getMaxJoules(par1ItemStack) * 2 / 3)
|
||||
{
|
||||
color = "\u00a72";
|
||||
}
|
||||
else
|
||||
{
|
||||
color = "\u00a76";
|
||||
}
|
||||
|
||||
par3List.add(color + ElectricInfo.getDisplay(joules, ElectricUnit.JOULES) + " - " + Math.round((joules / this.getMaxJoules(par1ItemStack)) * 100) + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
|
||||
* not want this to happen!
|
||||
*/
|
||||
@Override
|
||||
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
par1ItemStack = this.getUncharged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double onReceive(double amps, double voltage, ItemStack itemStack)
|
||||
{
|
||||
double rejectedElectricity = Math.max((this.getJoules(itemStack) + ElectricInfo.getJoules(amps, voltage, 1)) - this.getMaxJoules(itemStack), 0);
|
||||
this.setJoules(this.getJoules(itemStack) + ElectricInfo.getJoules(amps, voltage, 1) - rejectedElectricity, itemStack);
|
||||
return rejectedElectricity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double onUse(double joulesNeeded, ItemStack itemStack)
|
||||
{
|
||||
double electricityToUse = Math.min(this.getJoules(itemStack), joulesNeeded);
|
||||
this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack);
|
||||
return electricityToUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveElectricity()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduceElectricity()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets the electriicty. Do not directly call this function. Try to use
|
||||
* onReceiveElectricity or onUseElectricity instead.
|
||||
*
|
||||
* @param wattHours - The amount of electricity in joules
|
||||
*/
|
||||
@Override
|
||||
public void setJoules(double wattHours, Object... data)
|
||||
{
|
||||
if (data[0] instanceof ItemStack)
|
||||
{
|
||||
ItemStack itemStack = (ItemStack) data[0];
|
||||
|
||||
// Saves the frequency in the ItemStack
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
double electricityStored = Math.max(Math.min(wattHours, this.getMaxJoules(itemStack)), 0);
|
||||
itemStack.getTagCompound().setDouble("electricity", electricityStored);
|
||||
|
||||
/**
|
||||
* Sets the damage as a percentage to render the bar properly.
|
||||
*/
|
||||
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxJoules()) * 100));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called to get the electricity stored in this item
|
||||
*
|
||||
* @return - The amount of electricity stored in watts
|
||||
*/
|
||||
@Override
|
||||
public double getJoules(Object... data)
|
||||
{
|
||||
if (data[0] instanceof ItemStack)
|
||||
{
|
||||
ItemStack itemStack = (ItemStack) data[0];
|
||||
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double electricityStored = itemStack.getTagCompound().getDouble("electricity");
|
||||
|
||||
/**
|
||||
* Sets the damage as a percentage to render the bar properly.
|
||||
*/
|
||||
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxJoules()) * 100));
|
||||
return electricityStored;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an uncharged version of the electric item. Use this if you want the crafting recipe
|
||||
* to use a charged version of the electric item instead of an empty version of the electric
|
||||
* item
|
||||
*
|
||||
* @return The ItemStack of a fully charged electric item
|
||||
*/
|
||||
public ItemStack getUncharged()
|
||||
{
|
||||
return this.getWithCharge(0);
|
||||
}
|
||||
|
||||
public ItemStack getWithCharge(double joules)
|
||||
{
|
||||
ItemStack chargedItem = new ItemStack(this);
|
||||
((IItemElectric) chargedItem.getItem()).setJoules(joules, chargedItem);
|
||||
return chargedItem;
|
||||
}
|
||||
|
||||
public static ItemStack getWithCharge(ItemStack itemStack, double joules)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
ItemStack chargedItem = itemStack.copy();
|
||||
((IItemElectric) chargedItem.getItem()).setJoules(joules, chargedItem);
|
||||
return chargedItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getUncharged(ItemStack itemStack)
|
||||
{
|
||||
return getWithCharge(itemStack, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
// Add an uncharged version of the electric item
|
||||
par3List.add(this.getUncharged());
|
||||
// Add an electric item to the creative list that is fully charged
|
||||
ItemStack chargedItem = new ItemStack(this);
|
||||
par3List.add(this.getWithCharge(this.getMaxJoules(chargedItem)));
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import universalelectricity.core.implement.IItemElectric;
|
||||
|
||||
/**
|
||||
* This slot should be used by any container that needs the slot for an electric items only.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class SlotElectricItem extends SlotSpecific
|
||||
{
|
||||
public SlotElectricItem(IInventory par2IInventory, int par3, int par4, int par5)
|
||||
{
|
||||
super(par2IInventory, par3, par4, par5, IItemElectric.class);
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.DamageSource;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class UEDamageSource extends DamageSource
|
||||
{
|
||||
public static final List<UEDamageSource> damageSources = new ArrayList<UEDamageSource>();
|
||||
|
||||
/**
|
||||
* Use this damage source for all types of electrical attacks.
|
||||
*/
|
||||
public static final UEDamageSource electrocution = (UEDamageSource) new UEDamageSource("electrocution", "%1$s got electrocuted!").setDamageBypassesArmor();
|
||||
|
||||
public String deathMessage;
|
||||
|
||||
public UEDamageSource(String damageType)
|
||||
{
|
||||
super(damageType);
|
||||
damageSources.add(this);
|
||||
}
|
||||
|
||||
public UEDamageSource(String damageType, String deathMessage)
|
||||
{
|
||||
this(damageType);
|
||||
this.setDeathMessage(deathMessage);
|
||||
}
|
||||
|
||||
public UEDamageSource setDeathMessage(String deathMessage)
|
||||
{
|
||||
this.deathMessage = deathMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSource setDamageBypassesArmor()
|
||||
{
|
||||
return super.setDamageBypassesArmor();
|
||||
}
|
||||
|
||||
public DamageSource setDamageAllowedInCreativeMode()
|
||||
{
|
||||
return super.setDamageAllowedInCreativeMode();
|
||||
}
|
||||
|
||||
public DamageSource setFireDamage()
|
||||
{
|
||||
return super.setFireDamage();
|
||||
}
|
||||
|
||||
public void registerDeathMessage()
|
||||
{
|
||||
LanguageRegistry.instance().addStringLocalization("death." + this.damageType, this.deathMessage);
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class UETab extends CreativeTabs
|
||||
{
|
||||
public static final UETab INSTANCE = new UETab("UniversalElectricity");
|
||||
private static ItemStack itemStack;
|
||||
|
||||
public UETab(String par2Str)
|
||||
{
|
||||
super(CreativeTabs.getNextID(), par2Str);
|
||||
LanguageRegistry.instance().addStringLocalization("itemGroup.UniversalElectricity", "en_US", "Universal Electricity");
|
||||
}
|
||||
|
||||
public static void setItemStack(ItemStack newItemStack)
|
||||
{
|
||||
if (itemStack == null)
|
||||
{
|
||||
itemStack = newItemStack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack()
|
||||
{
|
||||
if (itemStack == null)
|
||||
{
|
||||
return new ItemStack(Block.blocksList[this.getTabIconItemIndex()]);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
package universalelectricity.prefab;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* A class used to search online and check for updates for your mod and notify the player.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class UpdateNotifier implements IPlayerTracker
|
||||
{
|
||||
public static final UpdateNotifier INSTANCE = new UpdateNotifier();
|
||||
public static boolean isInitialized = false;
|
||||
|
||||
public static final HashMap<String, String> MODS_TO_UPDATE = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Add variables to this array if you want extra custom notifications to be output.
|
||||
*/
|
||||
public static final List<String> NOTIFICATIONS = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Call this in your FML Pre-Initialize Event.
|
||||
*
|
||||
* @param modName The name of your mod.
|
||||
* @param currentVersion The current version of your mod.
|
||||
* @param updateUrl The web address of your text file containing the latest version number.
|
||||
* @return The latest version number, empty if fail to check for update.
|
||||
*/
|
||||
public final String checkUpdate(String modName, String currentVersion, String updateUrl)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
GameRegistry.registerPlayerTracker(this);
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
String latestUpdate = getLatestVersion(updateUrl);
|
||||
|
||||
if (latestUpdate != null && latestUpdate != "" && !currentVersion.trim().equals(latestUpdate.trim()))
|
||||
{
|
||||
MODS_TO_UPDATE.put(modName, latestUpdate.trim());
|
||||
}
|
||||
|
||||
return latestUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to check for updates for your mod.
|
||||
*
|
||||
* @param updateUrl The web address of your text file containing the latest version number.
|
||||
* @return The latest version number, empty if fail to check for update.
|
||||
*/
|
||||
public static final String getLatestVersion(String updateUrl)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL versionFile = new URL(updateUrl);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(versionFile.openStream()));
|
||||
return reader.readLine();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Failed to check for mod updates.");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerLogin(EntityPlayer player)
|
||||
{
|
||||
if (MODS_TO_UPDATE.size() > 0)
|
||||
{
|
||||
// Output Notification Message.
|
||||
String updateNotification = "Please update the following mod(s): ";
|
||||
|
||||
Iterator it = MODS_TO_UPDATE.entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry pairs = (Map.Entry) it.next();
|
||||
|
||||
updateNotification += pairs.getKey() + " [" + pairs.getValue() + "] ";
|
||||
}
|
||||
|
||||
player.addChatMessage(updateNotification);
|
||||
}
|
||||
|
||||
// Output Extra Notifications
|
||||
for (String notification : NOTIFICATIONS)
|
||||
{
|
||||
player.addChatMessage(notification);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerLogout(EntityPlayer player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChangedDimension(EntityPlayer player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(EntityPlayer player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
package universalelectricity.prefab;
|
||||
package universalelectricity.prefab.block;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -12,43 +11,20 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.implement.IItemElectric;
|
||||
import universalelectricity.prefab.implement.ISneakUseWrench;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.prefab.implement.IToolConfigurator;
|
||||
|
||||
/**
|
||||
* A block you may extend from to create your machine blocks! You do not have to extend from this
|
||||
* block if you do not want to. It's optional but it comes with some useful functions that will make
|
||||
* coding easier for you.
|
||||
* An advanced block class that is to be extended for wrenching capabilities.
|
||||
*/
|
||||
public abstract class BlockMachine extends BlockContainer implements ISneakUseWrench
|
||||
public abstract class BlockAdvanced extends BlockContainer
|
||||
{
|
||||
public BlockMachine(int id, Material material)
|
||||
public BlockAdvanced(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
this.setHardness(0.6f);
|
||||
}
|
||||
|
||||
public BlockMachine(int id, int textureIndex, Material material)
|
||||
{
|
||||
super(id, textureIndex, material);
|
||||
this.setHardness(0.6f);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockMachine(String string, int id, Material material)
|
||||
{
|
||||
this(id, material);
|
||||
this.setBlockName(string);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockMachine(String string, int id, Material material, CreativeTabs creativeTab)
|
||||
{
|
||||
this(string, id, material);
|
||||
this.setCreativeTab(creativeTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* DO NOT OVERRIDE THIS FUNCTION! Called when the block is right clicked by the player. This
|
||||
* modified version detects electric items and wrench actions on your machine block. Do not
|
||||
|
@ -60,40 +36,50 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
* @param hitX , hitY, hitZ The position the player clicked on relative to the block.
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
int metadata = world.getBlockMetadata(x, y, z);
|
||||
|
||||
/**
|
||||
* Check if the player is holding a wrench or an electric item. If so, do not open the GUI.
|
||||
*/
|
||||
if (par5EntityPlayer.inventory.getCurrentItem() != null)
|
||||
if (entityPlayer.inventory.getCurrentItem() != null)
|
||||
{
|
||||
if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IToolConfigurator)
|
||||
if (entityPlayer.inventory.getCurrentItem().getItem() instanceof IToolConfigurator)
|
||||
{
|
||||
world.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
|
||||
((IToolConfigurator) par5EntityPlayer.inventory.getCurrentItem().getItem()).wrenchUsed(par5EntityPlayer, x, y, z);
|
||||
|
||||
return this.onUseWrench(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
|
||||
((IToolConfigurator) entityPlayer.inventory.getCurrentItem().getItem()).wrenchUsed(entityPlayer, x, y, z);
|
||||
|
||||
if (entityPlayer.isSneaking())
|
||||
{
|
||||
if (this.onSneakUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
||||
|
||||
}
|
||||
else if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IItemElectric)
|
||||
else if (entityPlayer.inventory.getCurrentItem().getItem() instanceof IItemElectric)
|
||||
{
|
||||
if (this.onUseElectricItem(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ))
|
||||
if (this.onUseElectricItem(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (par5EntityPlayer.isSneaking())
|
||||
if (entityPlayer.isSneaking())
|
||||
{
|
||||
if (this.onSneakMachineActivated(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ))
|
||||
if (this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.onMachineActivated(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
|
||||
return this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +87,7 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
*
|
||||
* @return True if something happens
|
||||
*/
|
||||
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -111,7 +97,7 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
*
|
||||
* @return True if something happens
|
||||
*/
|
||||
public boolean onSneakMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -121,7 +107,7 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
*
|
||||
* @return True if some happens
|
||||
*/
|
||||
public boolean onUseElectricItem(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onUseElectricItem(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -131,7 +117,7 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
*
|
||||
* @return True if some happens
|
||||
*/
|
||||
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -142,10 +128,9 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
*
|
||||
* @return True if some happens
|
||||
*/
|
||||
@Override
|
||||
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return this.onUseWrench(par1World, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
|
||||
return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,19 +144,19 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int x, int y, int z, int par5, int par6)
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
this.dropEntireInventory(par1World, x, y, z, par5, par6);
|
||||
super.breakBlock(par1World, x, y, z, par5, par6);
|
||||
this.dropEntireInventory(world, x, y, z, par5, par6);
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if you don't need it. This will eject all items out of this machine if it has
|
||||
* an inventory.
|
||||
*/
|
||||
public void dropEntireInventory(World par1World, int x, int y, int z, int par5, int par6)
|
||||
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z);
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
|
@ -200,7 +185,7 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
}
|
||||
|
||||
var7.stackSize -= var11;
|
||||
EntityItem var12 = new EntityItem(par1World, (x + var8), (y + var9), (z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
|
||||
EntityItem var12 = new EntityItem(world, (x + var8), (y + var9), (z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
|
||||
|
||||
if (var7.hasTagCompound())
|
||||
{
|
||||
|
@ -211,7 +196,7 @@ public abstract class BlockMachine extends BlockContainer implements ISneakUseWr
|
|||
var12.motionX = ((float) random.nextGaussian() * var13);
|
||||
var12.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
|
||||
var12.motionZ = ((float) random.nextGaussian() * var13);
|
||||
par1World.spawnEntityInWorld(var12);
|
||||
world.spawnEntityInWorld(var12);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package universalelectricity.prefab;
|
||||
package universalelectricity.prefab.block;
|
||||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.implement.IConductor;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
|
||||
public abstract class BlockConductor extends BlockContainer
|
||||
{
|
||||
|
@ -23,13 +23,9 @@ public abstract class BlockConductor extends BlockContainer
|
|||
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
((IConductor) tileEntity).refreshConnectedBlocks();
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
((IConductor) tileEntity).updateAdjacentConnections();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,13 +38,9 @@ public abstract class BlockConductor extends BlockContainer
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
((IConductor) tileEntity).refreshConnectedBlocks();
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
((IConductor) tileEntity).updateAdjacentConnections();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package universalelectricity.prefab.block;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.prefab.implement.IRotatable;
|
||||
|
||||
/**
|
||||
* A block that can rotate based on placed position and wrenching.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class BlockRotatable extends BlockAdvanced implements IRotatable
|
||||
{
|
||||
public BlockRotatable(int id, Material material)
|
||||
{
|
||||
super(id, material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack)
|
||||
{
|
||||
int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
int change = 3;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 0:
|
||||
change = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
change = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
change = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
change = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
this.setDirection(world, x, y, z, ForgeDirection.getOrientation(change));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
/**
|
||||
* NOTE! This will rotate the block only in all 4 horizontal directions. If your block
|
||||
* rotates up or down, you should override this.
|
||||
*/
|
||||
this.setDirection(world, x, y, z, ForgeDirection.getOrientation(ForgeDirection.ROTATION_MATRIX[0][this.getDirection(world, x, y, z).ordinal()]));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getDirection(World world, int x, int y, int z)
|
||||
{
|
||||
return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, facingDirection.ordinal(), 3);
|
||||
}
|
||||
}
|
319
src/minecraft/universalelectricity/prefab/flag/CommandFlag.java
Normal file
319
src/minecraft/universalelectricity/prefab/flag/CommandFlag.java
Normal file
|
@ -0,0 +1,319 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* Commands used for flags and regions. This can be used for protection for specific mod components
|
||||
* that might be dangerous.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class CommandFlag extends CommandBase
|
||||
{
|
||||
public static final String[] COMMANDS = new String[] { "list", "setregion", "removeregion", "set" };
|
||||
public String commandName = "modflag";
|
||||
public ModFlag modFlagData;
|
||||
|
||||
public CommandFlag(ModFlag modFlag)
|
||||
{
|
||||
this.modFlagData = modFlag;
|
||||
}
|
||||
|
||||
public CommandFlag(ModFlag modFlag, String commandName)
|
||||
{
|
||||
this(modFlag);
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender par1ICommandSender)
|
||||
{
|
||||
String returnString = "";
|
||||
|
||||
for (String command : COMMANDS)
|
||||
{
|
||||
returnString = returnString + "\n/" + this.getCommandName() + " " + command;
|
||||
}
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer) sender;
|
||||
|
||||
// The world data the player is on.
|
||||
FlagWorld flagWorld = this.modFlagData.getFlagWorld(entityPlayer.worldObj);
|
||||
|
||||
String commandName = args[0].toLowerCase();
|
||||
|
||||
if (commandName.equalsIgnoreCase("list"))
|
||||
{
|
||||
/**
|
||||
* The list command lists out all regions in this world/region.
|
||||
*/
|
||||
if (args.length > 1)
|
||||
{
|
||||
String regionName = args[1];
|
||||
|
||||
if (regionName.equalsIgnoreCase("all"))
|
||||
{
|
||||
String msg = "";
|
||||
|
||||
Iterator<FlagWorld> itWorlds = this.modFlagData.getFlagWorlds().iterator();
|
||||
|
||||
while (itWorlds.hasNext())
|
||||
{
|
||||
Iterator<FlagRegion> itRegion = itWorlds.next().getRegions().iterator();
|
||||
|
||||
while (itRegion.hasNext())
|
||||
{
|
||||
FlagRegion flagRegion = itRegion.next();
|
||||
msg = msg + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",";
|
||||
}
|
||||
}
|
||||
|
||||
if (msg != "")
|
||||
{
|
||||
msg = "List of regions in world:\n" + msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "No regions in this world.";
|
||||
}
|
||||
|
||||
sender.sendChatToPlayer(msg);
|
||||
}
|
||||
else if (flagWorld.getRegion(regionName) != null)
|
||||
{
|
||||
String msg = "";
|
||||
|
||||
Iterator<Flag> i = flagWorld.getRegion(regionName).getFlags().iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
Flag flag = i.next();
|
||||
msg = msg + " " + flag.name + " => " + flag.value + ",";
|
||||
}
|
||||
|
||||
if (msg != "")
|
||||
{
|
||||
msg = "List of flags in region " + regionName + ":\n" + msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "No flags in this region.";
|
||||
}
|
||||
|
||||
sender.sendChatToPlayer(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = "Region does not exist, but here are existing flags in the position you are standing on:\n";
|
||||
|
||||
Iterator<Flag> i = flagWorld.getFlagsInPosition(new Vector3(entityPlayer)).iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
Flag flag = i.next();
|
||||
msg = msg + " " + flag.name + "=>" + flag.value + ",";
|
||||
}
|
||||
|
||||
sender.sendChatToPlayer(msg);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = "";
|
||||
|
||||
Iterator<FlagRegion> i = flagWorld.getRegions().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
FlagRegion flagRegion = i.next();
|
||||
msg = msg + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",";
|
||||
}
|
||||
|
||||
if (msg != "")
|
||||
{
|
||||
msg = "List of regions in this dimension:\n" + msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "No regions in this dimension.";
|
||||
}
|
||||
|
||||
sender.sendChatToPlayer(msg);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (commandName.equalsIgnoreCase("setregion"))
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
String regionName = args[1];
|
||||
|
||||
if (regionName.equalsIgnoreCase(FlagWorld.GLOBAL_REGION))
|
||||
{
|
||||
if (flagWorld.addRegion(regionName, new Vector3(entityPlayer), 1))
|
||||
{
|
||||
sender.sendChatToPlayer("Created global dimension region setting.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (args.length > 2)
|
||||
{
|
||||
int radius = 0;
|
||||
|
||||
try
|
||||
{
|
||||
radius = Integer.parseInt(args[2]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new WrongUsageException("Radius not a number!");
|
||||
}
|
||||
|
||||
if (radius > 0)
|
||||
{
|
||||
FlagRegion region = flagWorld.getRegion(regionName);
|
||||
if (region == null)
|
||||
{
|
||||
if (flagWorld.addRegion(regionName, new Vector3(entityPlayer), radius))
|
||||
{
|
||||
sender.sendChatToPlayer("Region " + regionName + " added.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
region.edit(new Vector3(entityPlayer), radius);
|
||||
sender.sendChatToPlayer("Region " + regionName + " already exists. Modified region to have a radius of: " + radius);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("Radius has to be greater than zero!");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("/" + this.getCommandName() + " addregion <name> <radius>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("Please specify the region name.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (commandName.equalsIgnoreCase("removeregion"))
|
||||
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
String regionName = args[1];
|
||||
|
||||
if (flagWorld.removeRegion(regionName))
|
||||
{
|
||||
sender.sendChatToPlayer("Region with name " + regionName + " is removed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("The specified region does not exist in this world.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("Please specify the region name.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (commandName.equalsIgnoreCase("set"))
|
||||
{
|
||||
if (args.length > 2)
|
||||
{
|
||||
String regionName = args[1];
|
||||
String flagName = args[2];
|
||||
FlagRegion flagRegion = flagWorld.getRegion(regionName);
|
||||
|
||||
if (flagRegion != null)
|
||||
{
|
||||
if (FlagRegistry.flags.contains(flagName))
|
||||
{
|
||||
if (args.length > 3)
|
||||
{
|
||||
String flagValue = args[3];
|
||||
|
||||
flagRegion.setFlag(flagName, flagValue);
|
||||
sender.sendChatToPlayer("Flag '" + flagName + "' has been set to '" + flagValue + "' in " + regionName + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
flagRegion.removeFlag(flagName);
|
||||
sender.sendChatToPlayer("Removed flag '" + flagName + "'.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String flags = "Flag does not exist. Existing flags:\n";
|
||||
|
||||
for (String registeredFlag : FlagRegistry.flags)
|
||||
{
|
||||
flags = flags + registeredFlag + ", ";
|
||||
}
|
||||
|
||||
throw new WrongUsageException(flags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("The specified region '" + regionName + "' does not exist.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("/" + this.getCommandName() + " set <regionName> <flagName> <value>");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new WrongUsageException(this.getCommandUsage(sender));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, COMMANDS) : null;
|
||||
}
|
||||
|
||||
}
|
43
src/minecraft/universalelectricity/prefab/flag/Flag.java
Normal file
43
src/minecraft/universalelectricity/prefab/flag/Flag.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class Flag extends FlagBase
|
||||
{
|
||||
/**
|
||||
* The region in which this flag has affect in.
|
||||
*/
|
||||
public FlagRegion flagRegion;
|
||||
|
||||
public String name;
|
||||
|
||||
public String value;
|
||||
|
||||
public Flag(FlagRegion flagRegion)
|
||||
{
|
||||
this.flagRegion = flagRegion;
|
||||
}
|
||||
|
||||
public Flag(FlagRegion flagRegion, String name, String value)
|
||||
{
|
||||
this(flagRegion);
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
this.name = nbt.getString("name");
|
||||
this.value = nbt.getString("value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setString("name", this.name);
|
||||
nbt.setString("value", this.value);
|
||||
|
||||
}
|
||||
}
|
26
src/minecraft/universalelectricity/prefab/flag/FlagBase.java
Normal file
26
src/minecraft/universalelectricity/prefab/flag/FlagBase.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public abstract class FlagBase
|
||||
{
|
||||
public abstract void readFromNBT(NBTTagCompound nbt);
|
||||
|
||||
public abstract void writeToNBT(NBTTagCompound nbt);
|
||||
|
||||
public NBTTagCompound getNBT()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
try
|
||||
{
|
||||
this.writeToNBT(nbt);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed to read flag");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
}
|
184
src/minecraft/universalelectricity/prefab/flag/FlagRegion.java
Normal file
184
src/minecraft/universalelectricity/prefab/flag/FlagRegion.java
Normal file
|
@ -0,0 +1,184 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.vector.Region3;
|
||||
|
||||
/**
|
||||
* A defined region.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class FlagRegion extends FlagBase
|
||||
{
|
||||
/**
|
||||
* The region in which this flag has affect in.
|
||||
*/
|
||||
public FlagWorld flagWorld;
|
||||
|
||||
public String name;
|
||||
public Region3 region;
|
||||
private final List<Flag> flags = new ArrayList<Flag>();
|
||||
|
||||
public FlagRegion(FlagWorld worldFlagData)
|
||||
{
|
||||
this.flagWorld = worldFlagData;
|
||||
}
|
||||
|
||||
public FlagRegion(FlagWorld flagWorld, String name, Region3 region)
|
||||
{
|
||||
this.flagWorld = flagWorld;
|
||||
this.name = name;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
this.name = nbt.getName();
|
||||
|
||||
Vector3 startVector = Vector3.readFromNBT(nbt.getCompoundTag("min"));
|
||||
Vector3 endVector = Vector3.readFromNBT(nbt.getCompoundTag("max"));
|
||||
|
||||
this.region = new Region3(startVector, endVector);
|
||||
|
||||
/**
|
||||
* Child Data
|
||||
*/
|
||||
NBTTagList flagList = nbt.getTagList("flags");
|
||||
|
||||
for (int i = 0; i < flagList.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound childNode = (NBTTagCompound) flagList.tagAt(i);
|
||||
|
||||
try
|
||||
{
|
||||
Flag flag = new Flag(this);
|
||||
flag.readFromNBT(childNode);
|
||||
this.flags.add(flag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Mod Flag: Failed to read flag data: " + childNode.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setName(this.name);
|
||||
|
||||
nbt.setTag("min", this.region.min.writeToNBT(new NBTTagCompound()));
|
||||
nbt.setTag("max", this.region.max.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
NBTTagList flagList = new NBTTagList();
|
||||
|
||||
for (Flag flag : this.getFlags())
|
||||
{
|
||||
try
|
||||
{
|
||||
flagList.appendTag(flag.getNBT());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed to save world flag data: " + flag.name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
nbt.setTag("flags", flagList);
|
||||
}
|
||||
|
||||
public boolean containsValue(String flagName, String checkValue, Vector3 position)
|
||||
{
|
||||
for (Flag flag : this.flags)
|
||||
{
|
||||
if (flag.name.equalsIgnoreCase(flagName) && flag.value.equalsIgnoreCase(checkValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setFlag(String flagName, String value)
|
||||
{
|
||||
this.removeFlag(flagName);
|
||||
|
||||
if (value != null && value != "")
|
||||
{
|
||||
if (!containsFlag(flagName))
|
||||
{
|
||||
return this.flags.add(new Flag(this, flagName, value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsFlag(String flagName)
|
||||
{
|
||||
for (Flag region : this.flags)
|
||||
{
|
||||
if (region.name.equalsIgnoreCase(flagName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeFlag(String flagName)
|
||||
{
|
||||
for (Flag region : this.flags)
|
||||
{
|
||||
if (region.name.equalsIgnoreCase(flagName))
|
||||
{
|
||||
this.flags.remove(region);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Flag> getFlags()
|
||||
{
|
||||
Iterator<Flag> it = this.flags.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
Flag flag = it.next();
|
||||
|
||||
if (flag == null)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flag.name == null || flag.name == "")
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return this.flags;
|
||||
}
|
||||
|
||||
public void edit(Vector3 position, int radius)
|
||||
{
|
||||
Vector3 minVec = new Vector3(position.intX() - radius, 0, position.intZ() - radius);
|
||||
Vector3 maxVec = new Vector3(position.intX() + radius, this.flagWorld.world.getHeight(), position.intZ() + radius);
|
||||
this.region = new Region3(minVec, maxVec);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All the different types of flags that can be registered.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class FlagRegistry
|
||||
{
|
||||
public static final String DEFAULT_NAME = "ModFlags";
|
||||
|
||||
private static final HashMap<String, ModFlag> MOD_FLAGS = new HashMap<String, ModFlag>();
|
||||
|
||||
public static final List<String> flags = new ArrayList<String>();
|
||||
public static boolean isInitiated = false;
|
||||
|
||||
public static void registerModFlag(String name, ModFlag flagData)
|
||||
{
|
||||
MOD_FLAGS.put(name, flagData);
|
||||
}
|
||||
|
||||
public static ModFlag getModFlag(String name)
|
||||
{
|
||||
return MOD_FLAGS.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a flag name, allowing it to be used and called by the player. Call this in your
|
||||
* mod's init function.
|
||||
*/
|
||||
public static String registerFlag(String name)
|
||||
{
|
||||
if (!isInitiated)
|
||||
{
|
||||
isInitiated = true;
|
||||
}
|
||||
|
||||
name = name.toLowerCase();
|
||||
|
||||
if (!flags.contains(name))
|
||||
{
|
||||
flags.add(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
200
src/minecraft/universalelectricity/prefab/flag/FlagWorld.java
Normal file
200
src/minecraft/universalelectricity/prefab/flag/FlagWorld.java
Normal file
|
@ -0,0 +1,200 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.vector.Region3;
|
||||
|
||||
/**
|
||||
* Data structure for world protection.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class FlagWorld extends FlagBase
|
||||
{
|
||||
public static final String GLOBAL_REGION = "dimension";
|
||||
|
||||
public World world;
|
||||
private final List<FlagRegion> regions = new ArrayList<FlagRegion>();
|
||||
|
||||
public FlagWorld(World world)
|
||||
{
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
// A list containing all flags within it for this world.
|
||||
Iterator<NBTTagCompound> childCompounds = nbt.getTags().iterator();
|
||||
|
||||
while (childCompounds.hasNext())
|
||||
{
|
||||
NBTTagCompound childCompound = childCompounds.next();
|
||||
|
||||
try
|
||||
{
|
||||
FlagRegion flagRegion = new FlagRegion(this);
|
||||
flagRegion.readFromNBT(childCompound);
|
||||
this.regions.add(flagRegion);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Mod Flag: Failed to read flag data: " + childCompound.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
for (FlagRegion region : this.regions)
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound flagCompound = new NBTTagCompound();
|
||||
region.writeToNBT(flagCompound);
|
||||
nbt.setTag(region.name, flagCompound);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed to save world flag data: " + region.name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the flags that have an effect in this position.
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public List<Flag> getFlagsInPosition(Vector3 position)
|
||||
{
|
||||
List<Flag> returnFlags = new ArrayList<Flag>();
|
||||
|
||||
for (FlagRegion flagRegion : this.regions)
|
||||
{
|
||||
if (flagRegion.region.isIn(position) || flagRegion.name.equalsIgnoreCase(GLOBAL_REGION))
|
||||
{
|
||||
for (Flag flag : flagRegion.getFlags())
|
||||
{
|
||||
returnFlags.add(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the values of the flags in this position.
|
||||
*/
|
||||
public List<String> getValues(String flagName, Vector3 position)
|
||||
{
|
||||
List<String> values = new ArrayList<String>();
|
||||
|
||||
for (Flag flag : this.getFlagsInPosition(position))
|
||||
{
|
||||
values.add(flag.value);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a flag in this position that has a specific value.
|
||||
*/
|
||||
public boolean containsValue(String flagName, String checkValue, Vector3 position)
|
||||
{
|
||||
for (Flag flag : this.getFlagsInPosition(position))
|
||||
{
|
||||
if (flag.name.equalsIgnoreCase(flagName) && flag.value.equalsIgnoreCase(checkValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addRegion(String name, Vector3 position, int radius)
|
||||
{
|
||||
Vector3 minVec = new Vector3(position.intX() - radius, 0, position.intZ() - radius);
|
||||
Vector3 maxVec = new Vector3(position.intX() + radius, this.world.getHeight(), position.intZ() + radius);
|
||||
|
||||
return this.regions.add(new FlagRegion(this, name, new Region3(minVec, maxVec)));
|
||||
}
|
||||
|
||||
public FlagRegion getRegion(String name)
|
||||
{
|
||||
for (FlagRegion region : this.regions)
|
||||
{
|
||||
if (region.name.equals(name))
|
||||
{
|
||||
return region;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all regions that intersect this point.
|
||||
*/
|
||||
public List<FlagRegion> getRegions(Vector3 position)
|
||||
{
|
||||
List<FlagRegion> returnRegions = new ArrayList<FlagRegion>();
|
||||
for (FlagRegion region : this.regions)
|
||||
{
|
||||
if (region.region.isIn(position))
|
||||
{
|
||||
returnRegions.add(region);
|
||||
}
|
||||
}
|
||||
return returnRegions;
|
||||
}
|
||||
|
||||
public boolean removeRegion(String name)
|
||||
{
|
||||
for (FlagRegion region : this.regions)
|
||||
{
|
||||
if (region.name.equals(name))
|
||||
{
|
||||
this.regions.remove(region);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<FlagRegion> getRegions()
|
||||
{
|
||||
Iterator<FlagRegion> it = this.regions.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
FlagRegion region = it.next();
|
||||
|
||||
if (region == null)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (region.name == null || region.name == "")
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return this.regions;
|
||||
}
|
||||
}
|
111
src/minecraft/universalelectricity/prefab/flag/ModFlag.java
Normal file
111
src/minecraft/universalelectricity/prefab/flag/ModFlag.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
public class ModFlag extends FlagBase
|
||||
{
|
||||
/**
|
||||
* An array of world flag data. Each representing a world.
|
||||
*/
|
||||
private final List<FlagWorld> flagWorlds = new ArrayList<FlagWorld>();
|
||||
|
||||
/**
|
||||
* Initiates a new mod flag data and loads everything from NBT into memory. Only exists server
|
||||
* side.
|
||||
*
|
||||
* @param nbt
|
||||
*/
|
||||
public ModFlag(NBTTagCompound nbt)
|
||||
{
|
||||
this.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
// A list containing all dimension ID and data within it.
|
||||
Iterator dimensions = nbt.getTags().iterator();
|
||||
|
||||
while (dimensions.hasNext())
|
||||
{
|
||||
NBTTagCompound dimensionCompound = (NBTTagCompound) dimensions.next();
|
||||
|
||||
try
|
||||
{
|
||||
int dimensionID = Integer.parseInt(dimensionCompound.getName().replace("dim_", ""));
|
||||
World world = DimensionManager.getWorld(dimensionID);
|
||||
FlagWorld flagWorld = new FlagWorld(world);
|
||||
flagWorld.readFromNBT(dimensionCompound);
|
||||
this.flagWorlds.add(flagWorld);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Mod Flag: Failed to read dimension data: " + dimensionCompound.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
for (FlagWorld worldData : this.flagWorlds)
|
||||
{
|
||||
try
|
||||
{
|
||||
nbt.setTag("dim_" + worldData.world.provider.dimensionId, worldData.getNBT());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Mod Flag: Failed to save world flag data: " + worldData.world);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FlagWorld getFlagWorld(World world)
|
||||
{
|
||||
FlagWorld worldData = null;
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
for (FlagWorld data : this.flagWorlds)
|
||||
{
|
||||
if (data.world != null && data.world.provider != null)
|
||||
{
|
||||
if (data.world.provider.dimensionId == world.provider.dimensionId)
|
||||
{
|
||||
worldData = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If data is null, create it.
|
||||
if (worldData == null)
|
||||
{
|
||||
worldData = new FlagWorld(world);
|
||||
this.flagWorlds.add(worldData);
|
||||
}
|
||||
}
|
||||
|
||||
return worldData;
|
||||
}
|
||||
|
||||
public boolean containsValue(World world, String flagName, String checkValue, Vector3 position)
|
||||
{
|
||||
return this.getFlagWorld(world).containsValue(flagName, checkValue, position);
|
||||
}
|
||||
|
||||
public List<FlagWorld> getFlagWorlds()
|
||||
{
|
||||
return this.flagWorlds;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package universalelectricity.prefab.flag;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
public class NBTFileLoader
|
||||
{
|
||||
/**
|
||||
* Saves NBT data in the world folder.
|
||||
*
|
||||
* @return True on success.
|
||||
*/
|
||||
public static boolean saveData(File saveDirectory, String filename, NBTTagCompound data)
|
||||
{
|
||||
try
|
||||
{
|
||||
File tempFile = new File(saveDirectory, filename + "_tmp.dat");
|
||||
File file = new File(saveDirectory, filename + ".dat");
|
||||
|
||||
CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
|
||||
tempFile.renameTo(file);
|
||||
|
||||
FMLLog.fine("Saved " + filename + " NBT data file successfully.");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed to save " + filename + ".dat!");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean saveData(String filename, NBTTagCompound data)
|
||||
{
|
||||
return saveData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads NBT data from the world folder.
|
||||
*
|
||||
* @return The NBT data
|
||||
*/
|
||||
public static NBTTagCompound loadData(File saveDirectory, String filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
File file = new File(saveDirectory, filename + ".dat");
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
FMLLog.fine("Loaded " + filename + " data.");
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.fine("Created new " + filename + " data.");
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed to load " + filename + ".dat!");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTTagCompound loadData(String filename)
|
||||
{
|
||||
return loadData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename);
|
||||
}
|
||||
|
||||
public static File getSaveDirectory(String worldName)
|
||||
{
|
||||
File parent = getBaseDirectory();
|
||||
|
||||
if (FMLCommonHandler.instance().getSide().isClient())
|
||||
{
|
||||
parent = new File(getBaseDirectory(), "saves" + File.separator);
|
||||
}
|
||||
|
||||
return new File(parent, worldName + File.separator);
|
||||
}
|
||||
|
||||
public static File getBaseDirectory()
|
||||
{
|
||||
if (FMLCommonHandler.instance().getSide().isClient())
|
||||
{
|
||||
FMLClientHandler.instance().getClient();
|
||||
return Minecraft.getMinecraftDir();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new File(".");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package universalelectricity.core.implement;
|
||||
package universalelectricity.prefab.implement;
|
||||
|
||||
/**
|
||||
* This class should be applied to all tile entities (mainly machines) that can be disabled (by
|
|
@ -1,11 +1,10 @@
|
|||
package universalelectricity.prefab.implement;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This interface should be applied onto all tile entities that are rotatable. This interface
|
||||
* however is optional and you do not need it for your add-on to function. It just makes things
|
||||
* easier for you to code.
|
||||
* The interface is applied to Blocks and TileEntities that can rotate.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
|
@ -14,19 +13,12 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
public interface IRotatable
|
||||
{
|
||||
/**
|
||||
* Gets the facing direction of the tile entity. Always returns the front side of the tile
|
||||
* entity.
|
||||
*
|
||||
* @return The facing side from 0-5 The full list of which side the number represents is in the
|
||||
* UniversalElectricity class.
|
||||
* @return Gets the facing direction. Always returns the front side of the block.
|
||||
*/
|
||||
public ForgeDirection getDirection();
|
||||
public ForgeDirection getDirection(World world, int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Sets the facing direction of the tile entity.
|
||||
*
|
||||
* @param facingDirection - A direction from 0-5. The full list of which side the number
|
||||
* represents is in the UniversalElectricity class.
|
||||
* @param Sets the facing direction.
|
||||
*/
|
||||
public void setDirection(ForgeDirection facingDirection);
|
||||
public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection);
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package universalelectricity.prefab.implement;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ISneakUseWrench
|
||||
{
|
||||
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package universalelectricity.prefab.modifier;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This must be applied to an item that acts as a modifier or an upgrade.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IModifier
|
||||
{
|
||||
/**
|
||||
* @return - The name of the modifier.
|
||||
*/
|
||||
public String getName(ItemStack itemstack);
|
||||
|
||||
/**
|
||||
* @return - How much effect does this modifier have?
|
||||
*/
|
||||
public int getEffectiveness(ItemStack itemstack);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package universalelectricity.prefab.modifier;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This slot should be used by any container that contains an item that is a modifier. An example of
|
||||
* this would be upgrade slots.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class SlotModifier extends Slot
|
||||
{
|
||||
public SlotModifier(IInventory par2IInventory, int par3, int par4, int par5)
|
||||
{
|
||||
super(par2IInventory, par3, par4, par5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack)
|
||||
{
|
||||
return par1ItemStack.getItem() instanceof IModifier;
|
||||
}
|
||||
}
|
|
@ -18,12 +18,12 @@ public class BlockMulti extends BlockContainer
|
|||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
this.setHardness(0.8F);
|
||||
this.setBlockName("MultiBlock");
|
||||
this.setUnlocalizedName("MultiBlock");
|
||||
}
|
||||
|
||||
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock)
|
||||
{
|
||||
worldObj.setBlockWithNotify(position.intX(), position.intY(), position.intZ(), this.blockID);
|
||||
worldObj.setBlockAndMetadataWithNotify(position.intX(), position.intY(), position.intZ(), this.blockID, 0, 2);
|
||||
((TileEntityMulti) worldObj.getBlockTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,22 +84,22 @@ public class TileEntityMulti extends TileEntity implements IPacketReceiver
|
|||
* Reads a tile entity from NBT.
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(par1NBTTagCompound);
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
this.mainBlockPosition = Vector3.readFromNBT("mainBlockPosition", par1NBTTagCompound);
|
||||
this.mainBlockPosition = Vector3.readFromNBT(nbt.getCompoundTag("mainBlockPosition"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tile entity to NBT.
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(par1NBTTagCompound);
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
this.mainBlockPosition.writeToNBT("mainBlockPosition", par1NBTTagCompound);
|
||||
nbt.setCompoundTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,17 +51,36 @@ public class PacketManager implements IPacketHandler, IPacketReceiver
|
|||
/**
|
||||
* Writes a compressed NBTTagCompound to the OutputStream
|
||||
*/
|
||||
public static void writeNBTTagCompound(NBTTagCompound tag, DataOutputStream stream) throws IOException
|
||||
public static void writeNBTTagCompound(NBTTagCompound tag, DataOutputStream dataStream) throws IOException
|
||||
{
|
||||
if (tag == null)
|
||||
{
|
||||
stream.writeShort(-1);
|
||||
dataStream.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = CompressedStreamTools.compress(tag);
|
||||
stream.writeShort((short) var2.length);
|
||||
stream.write(var2);
|
||||
dataStream.writeShort((short) var2.length);
|
||||
dataStream.write(var2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compressed NBTTagCompount in a ByteStream.
|
||||
*/
|
||||
public static NBTTagCompound readNBTTagCompound(ByteArrayDataInput dataStream) throws IOException
|
||||
{
|
||||
short var1 = dataStream.readShort();
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = new byte[var1];
|
||||
dataStream.readFully(var2);
|
||||
return CompressedStreamTools.decompress(var2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package universalelectricity.prefab.ore;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/**
|
||||
* This class is used for storing ore generation data. If you are too lazy to generate your own
|
||||
* ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores
|
||||
* to generate.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class OreGenBase
|
||||
{
|
||||
public String name;
|
||||
|
||||
public String oreDictionaryName;
|
||||
|
||||
public boolean shouldGenerate = false;
|
||||
|
||||
public int blockIndexTexture;
|
||||
|
||||
public ItemStack oreStack;
|
||||
|
||||
public int oreID;
|
||||
|
||||
public int oreMeta;
|
||||
|
||||
/**
|
||||
* What harvest level does this machine need to be acquired?
|
||||
*/
|
||||
public int harvestLevel;
|
||||
|
||||
/**
|
||||
* The predefined tool classes are "pickaxe", "shovel", "axe". You can add others for custom
|
||||
* tools.
|
||||
*/
|
||||
public String harvestTool;
|
||||
|
||||
/**
|
||||
* @param name - The name of the ore for display
|
||||
* @param textureFile - The 16x16 png texture of your ore to override
|
||||
* @param minGenerateLevel - The highest generation level of your ore
|
||||
* @param maxGenerateLevel - The lowest generation level of your ore
|
||||
* @param amountPerChunk - The amount of ores to generate per chunk
|
||||
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with
|
||||
* a lot of other coal next to it. How much do you want?
|
||||
*/
|
||||
public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel)
|
||||
{
|
||||
if (stack != null)
|
||||
{
|
||||
this.name = name;
|
||||
this.harvestTool = harvestTool;
|
||||
this.harvestLevel = harvestLevel;
|
||||
this.oreDictionaryName = oreDiectionaryName;
|
||||
this.oreStack = stack;
|
||||
this.oreID = stack.itemID;
|
||||
this.oreMeta = stack.getItemDamage();
|
||||
|
||||
OreDictionary.registerOre(oreDictionaryName, stack);
|
||||
MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.severe("ItemStack is null while registering ore generation!");
|
||||
}
|
||||
}
|
||||
|
||||
public OreGenBase enable(Configuration config)
|
||||
{
|
||||
this.shouldGenerate = shouldGenerateOre(config, this.name);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the config file and see if Universal Electricity should generate this ore
|
||||
*/
|
||||
private static boolean shouldGenerateOre(Configuration configuration, String oreName)
|
||||
{
|
||||
configuration.load();
|
||||
boolean shouldGenerate = configuration.get("Ore Generation", "Generate " + oreName, true).getBoolean(true);
|
||||
configuration.save();
|
||||
return shouldGenerate;
|
||||
}
|
||||
|
||||
public abstract void generate(World world, Random random, int varX, int varZ);
|
||||
|
||||
public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator);
|
||||
}
|
152
src/minecraft/universalelectricity/prefab/ore/OreGenReplace.java
Normal file
152
src/minecraft/universalelectricity/prefab/ore/OreGenReplace.java
Normal file
|
@ -0,0 +1,152 @@
|
|||
package universalelectricity.prefab.ore;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.ChunkProviderEnd;
|
||||
import net.minecraft.world.gen.ChunkProviderGenerate;
|
||||
import net.minecraft.world.gen.ChunkProviderHell;
|
||||
|
||||
/**
|
||||
* This class is used for storing ore generation data. If you are too lazy to generate your own
|
||||
* ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores
|
||||
* to generate.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class OreGenReplace extends OreGenBase
|
||||
{
|
||||
|
||||
public int minGenerateLevel;
|
||||
public int maxGenerateLevel;
|
||||
public int amountPerChunk;
|
||||
public int amountPerBranch;
|
||||
public int replaceID;
|
||||
|
||||
/**
|
||||
* Dimensions to ignore ore generation
|
||||
*/
|
||||
public boolean ignoreSurface = false;
|
||||
public boolean ignoreNether = true;
|
||||
public boolean ignoreEnd = true;
|
||||
|
||||
/**
|
||||
* @param name - The name of the ore for display
|
||||
* @param textureFile - The 16x16 png texture of your ore to override
|
||||
* @param minGenerateLevel - The highest generation level of your ore
|
||||
* @param maxGenerateLevel - The lowest generation level of your ore
|
||||
* @param amountPerChunk - The amount of ores to generate per chunk
|
||||
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with
|
||||
* a lot of other coal next to it. How much do you want?
|
||||
*/
|
||||
public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
|
||||
{
|
||||
super(name, oreDiectionaryName, stack, harvestTool, harvestLevel);
|
||||
this.minGenerateLevel = minGenerateLevel;
|
||||
this.maxGenerateLevel = maxGenerateLevel;
|
||||
this.amountPerChunk = amountPerChunk;
|
||||
this.amountPerBranch = amountPerBranch;
|
||||
this.replaceID = replaceID;
|
||||
}
|
||||
|
||||
public void generate(World world, Random random, int varX, int varZ)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < this.amountPerChunk; i++)
|
||||
{
|
||||
int x = varX + random.nextInt(16);
|
||||
int z = varZ + random.nextInt(16);
|
||||
int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel;
|
||||
this.generateReplace(world, random, x, y, z);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Error generating ore: " + this.name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5)
|
||||
{
|
||||
float var6 = par2Random.nextFloat() * (float) Math.PI;
|
||||
double var7 = (double) ((float) (par3 + 8) + MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F);
|
||||
double var9 = (double) ((float) (par3 + 8) - MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F);
|
||||
double var11 = (double) ((float) (par5 + 8) + MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F);
|
||||
double var13 = (double) ((float) (par5 + 8) - MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F);
|
||||
double var15 = (double) (par4 + par2Random.nextInt(3) - 2);
|
||||
double var17 = (double) (par4 + par2Random.nextInt(3) - 2);
|
||||
|
||||
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
|
||||
{
|
||||
double var20 = var7 + (var9 - var7) * (double) var19 / (double) this.amountPerBranch;
|
||||
double var22 = var15 + (var17 - var15) * (double) var19 / (double) this.amountPerBranch;
|
||||
double var24 = var11 + (var13 - var11) * (double) var19 / (double) this.amountPerBranch;
|
||||
double var26 = par2Random.nextDouble() * (double) this.amountPerBranch / 16.0D;
|
||||
double var28 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
||||
double var30 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
||||
int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
|
||||
int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
|
||||
int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
|
||||
int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
|
||||
int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
|
||||
int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);
|
||||
|
||||
for (int var38 = var32; var38 <= var35; ++var38)
|
||||
{
|
||||
double var39 = ((double) var38 + 0.5D - var20) / (var28 / 2.0D);
|
||||
|
||||
if (var39 * var39 < 1.0D)
|
||||
{
|
||||
for (int var41 = var33; var41 <= var36; ++var41)
|
||||
{
|
||||
double var42 = ((double) var41 + 0.5D - var22) / (var30 / 2.0D);
|
||||
|
||||
if (var39 * var39 + var42 * var42 < 1.0D)
|
||||
{
|
||||
for (int var44 = var34; var44 <= var37; ++var44)
|
||||
{
|
||||
double var45 = ((double) var44 + 0.5D - var24) / (var28 / 2.0D);
|
||||
|
||||
int block = par1World.getBlockId(var38, var41, var44);
|
||||
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID))
|
||||
{
|
||||
par1World.setBlockAndMetadataWithNotify(var38, var41, var44, this.oreID, this.oreMeta, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator)
|
||||
{
|
||||
if (!this.shouldGenerate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ignoreNether && chunkGenerator instanceof ChunkProviderHell)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ignoreEnd && chunkGenerator instanceof ChunkProviderEnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package universalelectricity.prefab.ore;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class OreGenReplaceStone extends OreGenReplace
|
||||
{
|
||||
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
|
||||
{
|
||||
super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel);
|
||||
}
|
||||
|
||||
// A simplified version of the constructor
|
||||
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch)
|
||||
{
|
||||
this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package universalelectricity.prefab.ore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class OreGenerator implements IWorldGenerator
|
||||
{
|
||||
public static boolean isInitiated = false;
|
||||
|
||||
/**
|
||||
* Add your ore data to this list of ores for it to automatically generate! No hassle indeed!
|
||||
*/
|
||||
private static final List<OreGenBase> ORES_TO_GENERATE = new ArrayList<OreGenBase>();
|
||||
|
||||
/**
|
||||
* Adds an ore to the ore generate list. Do this in pre-init.
|
||||
*/
|
||||
public static void addOre(OreGenBase data)
|
||||
{
|
||||
if (!isInitiated)
|
||||
{
|
||||
GameRegistry.registerWorldGenerator(new OreGenerator());
|
||||
}
|
||||
|
||||
ORES_TO_GENERATE.add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if this ore
|
||||
*
|
||||
* @param oreName
|
||||
* @return
|
||||
*/
|
||||
public static boolean oreExists(String oreName)
|
||||
{
|
||||
for (OreGenBase ore : ORES_TO_GENERATE)
|
||||
{
|
||||
if (ore.oreDictionaryName == oreName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an ore to the ore generate list. Do this in init.
|
||||
*/
|
||||
public static void removeOre(OreGenBase data)
|
||||
{
|
||||
ORES_TO_GENERATE.remove(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
||||
{
|
||||
chunkX = chunkX << 4;
|
||||
chunkZ = chunkZ << 4;
|
||||
|
||||
// Checks to make sure this is the normal
|
||||
// world
|
||||
for (OreGenBase oreData : ORES_TO_GENERATE)
|
||||
{
|
||||
if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator))
|
||||
{
|
||||
oreData.generate(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package universalelectricity.prefab.potion;
|
||||
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
public abstract class CustomPotion extends Potion
|
||||
{
|
||||
/**
|
||||
* Creates a new type of potion
|
||||
*
|
||||
* @param id - The ID of this potion. Make it greater than 20.
|
||||
* @param isBadEffect - Is this potion a good potion or a bad one?
|
||||
* @param color - The color of this potion.
|
||||
* @param name - The name of this potion.
|
||||
*/
|
||||
public CustomPotion(int id, boolean isBadEffect, int color, String name)
|
||||
{
|
||||
super(id, isBadEffect, color);
|
||||
this.setPotionName("potion." + name);
|
||||
Potion.potionTypes[this.getId()] = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Potion setIconIndex(int par1, int par2)
|
||||
{
|
||||
super.setIconIndex(par1, par2);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Potion setEffectiveness(double par1)
|
||||
{
|
||||
super.setEffectiveness(par1);
|
||||
return this;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue