This commit is contained in:
Aidan Brady 2013-08-05 13:17:47 -04:00
commit daa52ba109
5 changed files with 303 additions and 235 deletions

View file

@ -2,6 +2,6 @@ dir.development=./
dir.mcp=${dir.development}forge/mcp dir.mcp=${dir.development}forge/mcp
version.minecraft=1.6.2 version.minecraft=1.6.2
version.mod.major=0 version.mod.major=0
version.mod.minor=0 version.mod.minor=1
version.mod.revis=1 version.mod.revis=0
version.universalelectricity=2.0.0 version.universalelectricity=2.0.0

View file

@ -91,7 +91,7 @@ public class ResonantInduction
* Settings * Settings
*/ */
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), NAME + ".cfg")); public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), NAME + ".cfg"));
public static float POWER_PER_COAL = 8; public static float POWER_PER_COAL = 5;
public static boolean SOUND_FXS = true; public static boolean SOUND_FXS = true;
/** Block ID by Jyzarc */ /** Block ID by Jyzarc */

View file

@ -9,6 +9,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import resonantinduction.api.IBattery; import resonantinduction.api.IBattery;
import resonantinduction.base.ItemBase; import resonantinduction.base.ItemBase;
@ -31,7 +32,13 @@ public class ItemCapacitor extends ItemBase implements IBattery
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{ {
double energyStored = this.getEnergyStored(itemStack); double energyStored = this.getEnergyStored(itemStack);
par3List.add("Energy: " + (int)energyStored + " KJ"); par3List.add("Energy: " + (int) energyStored + "/" + (int) this.getMaxEnergyStored(itemStack) + " KJ");
}
@Override
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
this.setEnergyStored(par1ItemStack, 0);
} }
@Override @Override
@ -43,7 +50,7 @@ public class ItemCapacitor extends ItemBase implements IBattery
} }
itemStack.getTagCompound().setFloat("energyStored", amount); itemStack.getTagCompound().setFloat("energyStored", amount);
itemStack.setItemDamage((int)(100 - (amount / getMaxEnergyStored(itemStack)) * 100)); itemStack.setItemDamage((int) (100 - (amount / getMaxEnergyStored(itemStack)) * 100));
} }
@Override @Override
@ -55,7 +62,7 @@ public class ItemCapacitor extends ItemBase implements IBattery
} }
float amount = itemStack.getTagCompound().getFloat("energyStored"); float amount = itemStack.getTagCompound().getFloat("energyStored");
itemStack.setItemDamage((int)(100 - (amount / getMaxEnergyStored(itemStack)) * 100)); itemStack.setItemDamage((int) (100 - (amount / getMaxEnergyStored(itemStack)) * 100));
return amount; return amount;
} }
@ -69,7 +76,7 @@ public class ItemCapacitor extends ItemBase implements IBattery
@Override @Override
public float getMaxEnergyStored(ItemStack itemStack) public float getMaxEnergyStored(ItemStack itemStack)
{ {
return 10; return 20;
} }
@Override @Override

View file

@ -42,26 +42,26 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{ {
ticks++; ticks++;
if(ticks == 1) if (ticks == 1)
{ {
TeslaGrid.instance().register(this); TeslaGrid.instance().register(this);
} }
if(!worldObj.isRemote) if (!worldObj.isRemote)
{ {
if(playersUsing.size() > 0) if (playersUsing.size() > 0)
{ {
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray()); PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray());
} }
if(ticks == 5 && !structure.isMultiblock) if (ticks == 5 && !structure.isMultiblock)
{ {
update(); update();
} }
if(structure.visibleInventory[0] != null) if (structure.visibleInventory[0] != null)
{ {
if(structure.inventory.size() < structure.getMaxCells()) if (structure.inventory.size() < structure.getMaxCells())
{ {
structure.inventory.add(structure.visibleInventory[0]); structure.inventory.add(structure.visibleInventory[0]);
structure.visibleInventory[0] = null; structure.visibleInventory[0] = null;
@ -69,33 +69,33 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
} }
} }
if(structure.visibleInventory[1] != null) if (structure.visibleInventory[1] != null)
{ {
ItemStack itemStack = structure.visibleInventory[1]; ItemStack itemStack = structure.visibleInventory[1];
IBattery battery = (IBattery)itemStack.getItem(); IBattery battery = (IBattery) itemStack.getItem();
float energyStored = getMaxEnergyStored(); float energyStored = getMaxEnergyStored();
float batteryNeeded = battery.getMaxEnergyStored(itemStack)-battery.getEnergyStored(itemStack); float batteryNeeded = battery.getMaxEnergyStored(itemStack) - battery.getEnergyStored(itemStack);
float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded)); float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded));
battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + removeEnergy(toGive, true)); battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + removeEnergy(toGive, true));
} }
if(structure.visibleInventory[2] != null) if (structure.visibleInventory[2] != null)
{ {
ItemStack itemStack = structure.visibleInventory[2]; ItemStack itemStack = structure.visibleInventory[2];
IBattery battery = (IBattery)itemStack.getItem(); IBattery battery = (IBattery) itemStack.getItem();
float energyNeeded = getMaxEnergyStored()-getEnergyStored(); float energyNeeded = getMaxEnergyStored() - getEnergyStored();
float batteryStored = battery.getEnergyStored(itemStack); float batteryStored = battery.getEnergyStored(itemStack);
float toReceive = Math.min(energyNeeded, Math.min(battery.getTransfer(itemStack), batteryStored)); float toReceive = Math.min(energyNeeded, Math.min(battery.getTransfer(itemStack), batteryStored));
battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - addEnergy(toReceive, true)); battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - addEnergy(toReceive, true));
} }
if(prevStructure != structure) if (prevStructure != structure)
{ {
for(EntityPlayer player : playersUsing) for (EntityPlayer player : playersUsing)
{ {
player.closeScreen(); player.closeScreen();
} }
@ -118,110 +118,111 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbtTags) public void readFromNBT(NBTTagCompound nbtTags)
{ {
super.readFromNBT(nbtTags); super.readFromNBT(nbtTags);
//Main inventory // Main inventory
if(nbtTags.hasKey("Items")) if (nbtTags.hasKey("Items"))
{ {
NBTTagList tagList = nbtTags.getTagList("Items"); NBTTagList tagList = nbtTags.getTagList("Items");
structure.inventory = new ArrayList<ItemStack>(); structure.inventory = new ArrayList<ItemStack>();
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++) for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{ {
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount); NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
int slotID = tagCompound.getInteger("Slot"); int slotID = tagCompound.getInteger("Slot");
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound)); structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
} }
} }
//Visible inventory // Visible inventory
if(nbtTags.hasKey("VisibleItems")) if (nbtTags.hasKey("VisibleItems"))
{ {
NBTTagList tagList = nbtTags.getTagList("VisibleItems"); NBTTagList tagList = nbtTags.getTagList("VisibleItems");
structure.visibleInventory = new ItemStack[3]; structure.visibleInventory = new ItemStack[3];
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++) for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{ {
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount); NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
byte slotID = tagCompound.getByte("Slot"); byte slotID = tagCompound.getByte("Slot");
if(slotID >= 0 && slotID < structure.visibleInventory.length) if (slotID >= 0 && slotID < structure.visibleInventory.length)
{ {
if(slotID == 0) if (slotID == 0)
{ {
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound)); setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
} }
else { else
setInventorySlotContents(slotID+1, ItemStack.loadItemStackFromNBT(tagCompound)); {
} setInventorySlotContents(slotID + 1, ItemStack.loadItemStackFromNBT(tagCompound));
} }
} }
} }
} }
}
@Override @Override
public void writeToNBT(NBTTagCompound nbtTags) public void writeToNBT(NBTTagCompound nbtTags)
{ {
super.writeToNBT(nbtTags); super.writeToNBT(nbtTags);
if(!structure.wroteInventory) if (!structure.wroteInventory)
{ {
//Inventory // Inventory
if(structure.inventory != null) if (structure.inventory != null)
{ {
NBTTagList tagList = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for(int slotCount = 0; slotCount < structure.inventory.size(); slotCount++) for (int slotCount = 0; slotCount < structure.inventory.size(); slotCount++)
{ {
if(structure.inventory.get(slotCount) != null) if (structure.inventory.get(slotCount) != null)
{ {
NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setInteger("Slot", slotCount); tagCompound.setInteger("Slot", slotCount);
structure.inventory.get(slotCount).writeToNBT(tagCompound); structure.inventory.get(slotCount).writeToNBT(tagCompound);
tagList.appendTag(tagCompound); tagList.appendTag(tagCompound);
} }
} }
nbtTags.setTag("Items", tagList); nbtTags.setTag("Items", tagList);
} }
//Visible inventory // Visible inventory
if(structure.visibleInventory != null) if (structure.visibleInventory != null)
{ {
NBTTagList tagList = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++) for (int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
{ {
if(slotCount > 0) if (slotCount > 0)
{ {
slotCount++; slotCount++;
} }
if(getStackInSlot(slotCount) != null) if (getStackInSlot(slotCount) != null)
{ {
NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte)slotCount); tagCompound.setByte("Slot", (byte) slotCount);
getStackInSlot(slotCount).writeToNBT(tagCompound); getStackInSlot(slotCount).writeToNBT(tagCompound);
tagList.appendTag(tagCompound); tagList.appendTag(tagCompound);
} }
} }
nbtTags.setTag("VisibleItems", tagList); nbtTags.setTag("VisibleItems", tagList);
} }
structure.wroteInventory = true; structure.wroteInventory = true;
} }
} }
public void update() public void update()
{ {
if(!worldObj.isRemote && (structure == null || !structure.didTick)) if (!worldObj.isRemote && (structure == null || !structure.didTick))
{ {
new BatteryUpdateProtocol(this).updateBatteries(); new BatteryUpdateProtocol(this).updateBatteries();
if(structure != null) if (structure != null)
{ {
structure.didTick = true; structure.didTick = true;
} }
@ -235,23 +236,23 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{ {
float added = 0; float added = 0;
for(ItemStack itemStack : structure.inventory) for (ItemStack itemStack : structure.inventory)
{ {
if(itemStack.getItem() instanceof IBattery) if (itemStack.getItem() instanceof IBattery)
{ {
IBattery battery = (IBattery)itemStack.getItem(); IBattery battery = (IBattery) itemStack.getItem();
float needed = amount-added; float needed = amount - added;
float itemAdd = Math.min(battery.getMaxEnergyStored(itemStack)-battery.getEnergyStored(itemStack), needed); float itemAdd = Math.min(battery.getMaxEnergyStored(itemStack) - battery.getEnergyStored(itemStack), needed);
if(doAdd) if (doAdd)
{ {
battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + itemAdd); battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + itemAdd);
} }
added += itemAdd; added += itemAdd;
if(amount == added) if (amount == added)
{ {
break; break;
} }
@ -270,23 +271,23 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
float removed = 0; float removed = 0;
for(ItemStack itemStack : inverse) for (ItemStack itemStack : inverse)
{ {
if(itemStack.getItem() instanceof IBattery) if (itemStack.getItem() instanceof IBattery)
{ {
IBattery battery = (IBattery)itemStack.getItem(); IBattery battery = (IBattery) itemStack.getItem();
float needed = amount-removed; float needed = amount - removed;
float itemRemove = Math.min(battery.getEnergyStored(itemStack), needed); float itemRemove = Math.min(battery.getEnergyStored(itemStack), needed);
if(doRemove) if (doRemove)
{ {
battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - itemRemove); battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - itemRemove);
} }
removed += itemRemove; removed += itemRemove;
if(amount == removed) if (amount == removed)
{ {
break; break;
} }
@ -298,7 +299,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
public float getMaxEnergyStored() public float getMaxEnergyStored()
{ {
if(!worldObj.isRemote) if (!worldObj.isRemote)
{ {
float max = 0; float max = 0;
@ -315,14 +316,15 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
return max; return max;
} }
else { else
{
return clientMaxEnergy; return clientMaxEnergy;
} }
} }
public float getEnergyStored() public float getEnergyStored()
{ {
if(!worldObj.isRemote) if (!worldObj.isRemote)
{ {
float energy = 0; float energy = 0;
@ -339,7 +341,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
return energy; return energy;
} }
else { else
{
return clientEnergy; return clientEnergy;
} }
} }
@ -347,7 +350,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public void handle(ByteArrayDataInput input) public void handle(ByteArrayDataInput input)
{ {
try { try
{
structure.isMultiblock = input.readBoolean(); structure.isMultiblock = input.readBoolean();
clientEnergy = input.readFloat(); clientEnergy = input.readFloat();
@ -357,7 +361,10 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
structure.height = input.readInt(); structure.height = input.readInt();
structure.length = input.readInt(); structure.length = input.readInt();
structure.width = input.readInt(); structure.width = input.readInt();
} catch(Exception e) {} }
catch (Exception e)
{
}
} }
@Override @Override
@ -385,52 +392,56 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public ItemStack getStackInSlot(int i) public ItemStack getStackInSlot(int i)
{ {
if(i == 0) if (i == 0)
{ {
return structure.visibleInventory[0]; return structure.visibleInventory[0];
} }
else if(i == 1) else if (i == 1)
{ {
if(!worldObj.isRemote) if (!worldObj.isRemote)
{ {
return ListUtil.getTop(structure.inventory); return ListUtil.getTop(structure.inventory);
} }
else { else
{
return structure.tempStack; return structure.tempStack;
} }
} }
else { else
return structure.visibleInventory[i-1]; {
return structure.visibleInventory[i - 1];
} }
} }
@Override @Override
public ItemStack decrStackSize(int slotID, int amount) public ItemStack decrStackSize(int slotID, int amount)
{ {
if(getStackInSlot(slotID) != null) if (getStackInSlot(slotID) != null)
{ {
ItemStack tempStack; ItemStack tempStack;
if(getStackInSlot(slotID).stackSize <= amount) if (getStackInSlot(slotID).stackSize <= amount)
{ {
tempStack = getStackInSlot(slotID); tempStack = getStackInSlot(slotID);
setInventorySlotContents(slotID, null); setInventorySlotContents(slotID, null);
return tempStack; return tempStack;
} }
else { else
tempStack = getStackInSlot(slotID).splitStack(amount); {
tempStack = getStackInSlot(slotID).splitStack(amount);
if(getStackInSlot(slotID).stackSize == 0) if (getStackInSlot(slotID).stackSize == 0)
{ {
setInventorySlotContents(slotID, null); setInventorySlotContents(slotID, null);
} }
return tempStack; return tempStack;
} }
} }
else { else
return null; {
} return null;
}
} }
@Override @Override
@ -442,31 +453,34 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public void setInventorySlotContents(int i, ItemStack itemstack) public void setInventorySlotContents(int i, ItemStack itemstack)
{ {
if(i == 0) if (i == 0)
{ {
structure.visibleInventory[0] = itemstack; structure.visibleInventory[0] = itemstack;
} }
else if(i == 1) else if (i == 1)
{ {
if(itemstack == null) if (itemstack == null)
{ {
if(!worldObj.isRemote) if (!worldObj.isRemote)
{ {
structure.inventory.remove(ListUtil.getTop(structure.inventory)); structure.inventory.remove(ListUtil.getTop(structure.inventory));
} }
else { else
{
structure.tempStack = null; structure.tempStack = null;
} }
} }
else { else
if(worldObj.isRemote) {
if (worldObj.isRemote)
{ {
structure.tempStack = itemstack; structure.tempStack = itemstack;
} }
} }
} }
else { else
structure.visibleInventory[i-1] = itemstack; {
structure.visibleInventory[i - 1] = itemstack;
} }
} }
@ -495,10 +509,14 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
} }
@Override @Override
public void openChest() {} public void openChest()
{
}
@Override @Override
public void closeChest() {} public void closeChest()
{
}
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) public boolean isItemValidForSlot(int i, ItemStack itemstack)
@ -515,6 +533,6 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public boolean canReceive(TileEntity transferTile) public boolean canReceive(TileEntity transferTile)
{ {
return true; return this.getMaxEnergyStored() - this.getEnergyStored() > 0;
} }
} }

View file

@ -6,6 +6,9 @@ package resonantinduction.multimeter;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -29,9 +32,49 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider
this.func_111022_d(ResonantInduction.PREFIX + "machine"); this.func_111022_d(ResonantInduction.PREFIX + "machine");
} }
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
return null;
}
@Override
public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3)
{
int metadata = par1World.getBlockMetadata(par2, par3, par4) & 7;
float thickness = 0.15f;
System.out.println(metadata);
if (metadata == 0)
{
this.setBlockBounds(0, 0, 0, 1, thickness, 1);
}
else if (metadata == 1)
{
this.setBlockBounds(0, 1 - thickness, 0, 1, 1, 1);
}
else if (metadata == 2)
{
this.setBlockBounds(0, 0, 0, 1, 1, thickness);
}
else if (metadata == 3)
{
this.setBlockBounds(0, 0, 1 - thickness, 1, 1, 1);
}
else if (metadata == 4)
{
this.setBlockBounds(0, 0, 0, thickness, 1, 1);
}
else if (metadata == 5)
{
this.setBlockBounds(1 - thickness, 0, 0, 1, 1, 1);
}
return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3);
}
/** /**
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY,
* hitZ, block metadata * hi@OverridetZ, block metadata
*/ */
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int side, float hitX, float hitY, float hitZ, int metadata) public int onBlockPlaced(World par1World, int par2, int par3, int par4, int side, float hitX, float hitY, float hitZ, int metadata)
{ {