Merge branch 'master' of https://github.com/calclavia/Resonant-Induction
This commit is contained in:
commit
daa52ba109
5 changed files with 303 additions and 235 deletions
|
@ -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
|
|
@ -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 */
|
||||||
|
|
|
@ -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
|
||||||
|
@ -41,9 +48,9 @@ public class ItemCapacitor extends ItemBase implements IBattery
|
||||||
{
|
{
|
||||||
itemStack.setTagCompound(new NBTTagCompound());
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -53,10 +60,10 @@ public class ItemCapacitor extends ItemBase implements IBattery
|
||||||
{
|
{
|
||||||
itemStack.setTagCompound(new NBTTagCompound());
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -30,9 +30,9 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
public class TileEntityBattery extends TileEntityBase implements IPacketReceiver, IInventory, ITesla
|
public class TileEntityBattery extends TileEntityBase implements IPacketReceiver, IInventory, ITesla
|
||||||
{
|
{
|
||||||
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
|
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
|
||||||
|
|
||||||
public SynchronizedBatteryData prevStructure;
|
public SynchronizedBatteryData prevStructure;
|
||||||
|
|
||||||
public float clientEnergy;
|
public float clientEnergy;
|
||||||
public int clientCells;
|
public int clientCells;
|
||||||
public float clientMaxEnergy;
|
public float clientMaxEnergy;
|
||||||
|
@ -41,267 +41,268 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
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;
|
||||||
structure.sortInventory();
|
structure.sortInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray());
|
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
prevStructure = structure;
|
prevStructure = structure;
|
||||||
|
|
||||||
structure.wroteInventory = false;
|
structure.wroteInventory = false;
|
||||||
structure.didTick = false;
|
structure.didTick = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate()
|
public void invalidate()
|
||||||
{
|
{
|
||||||
TeslaGrid.instance().unregister(this);
|
TeslaGrid.instance().unregister(this);
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound nbtTags)
|
|
||||||
{
|
|
||||||
super.readFromNBT(nbtTags);
|
|
||||||
|
|
||||||
//Main inventory
|
|
||||||
if(nbtTags.hasKey("Items"))
|
|
||||||
{
|
|
||||||
NBTTagList tagList = nbtTags.getTagList("Items");
|
|
||||||
structure.inventory = new ArrayList<ItemStack>();
|
|
||||||
|
|
||||||
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
|
|
||||||
int slotID = tagCompound.getInteger("Slot");
|
|
||||||
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Visible inventory
|
|
||||||
if(nbtTags.hasKey("VisibleItems"))
|
|
||||||
{
|
|
||||||
NBTTagList tagList = nbtTags.getTagList("VisibleItems");
|
|
||||||
structure.visibleInventory = new ItemStack[3];
|
|
||||||
|
|
||||||
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
|
|
||||||
byte slotID = tagCompound.getByte("Slot");
|
|
||||||
|
|
||||||
if(slotID >= 0 && slotID < structure.visibleInventory.length)
|
|
||||||
{
|
|
||||||
if(slotID == 0)
|
|
||||||
{
|
|
||||||
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setInventorySlotContents(slotID+1, ItemStack.loadItemStackFromNBT(tagCompound));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbtTags)
|
public void readFromNBT(NBTTagCompound nbtTags)
|
||||||
{
|
{
|
||||||
super.writeToNBT(nbtTags);
|
super.readFromNBT(nbtTags);
|
||||||
|
|
||||||
if(!structure.wroteInventory)
|
// Main inventory
|
||||||
{
|
if (nbtTags.hasKey("Items"))
|
||||||
//Inventory
|
{
|
||||||
if(structure.inventory != null)
|
NBTTagList tagList = nbtTags.getTagList("Items");
|
||||||
{
|
structure.inventory = new ArrayList<ItemStack>();
|
||||||
NBTTagList tagList = new NBTTagList();
|
|
||||||
|
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
||||||
for(int slotCount = 0; slotCount < structure.inventory.size(); slotCount++)
|
{
|
||||||
{
|
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
|
||||||
if(structure.inventory.get(slotCount) != null)
|
int slotID = tagCompound.getInteger("Slot");
|
||||||
{
|
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
||||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
}
|
||||||
tagCompound.setInteger("Slot", slotCount);
|
}
|
||||||
structure.inventory.get(slotCount).writeToNBT(tagCompound);
|
|
||||||
tagList.appendTag(tagCompound);
|
// Visible inventory
|
||||||
}
|
if (nbtTags.hasKey("VisibleItems"))
|
||||||
}
|
{
|
||||||
|
NBTTagList tagList = nbtTags.getTagList("VisibleItems");
|
||||||
nbtTags.setTag("Items", tagList);
|
structure.visibleInventory = new ItemStack[3];
|
||||||
}
|
|
||||||
|
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
||||||
//Visible inventory
|
{
|
||||||
if(structure.visibleInventory != null)
|
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
|
||||||
{
|
byte slotID = tagCompound.getByte("Slot");
|
||||||
NBTTagList tagList = new NBTTagList();
|
|
||||||
|
if (slotID >= 0 && slotID < structure.visibleInventory.length)
|
||||||
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
{
|
||||||
{
|
if (slotID == 0)
|
||||||
if(slotCount > 0)
|
{
|
||||||
{
|
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
||||||
slotCount++;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
if(getStackInSlot(slotCount) != null)
|
setInventorySlotContents(slotID + 1, ItemStack.loadItemStackFromNBT(tagCompound));
|
||||||
{
|
}
|
||||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
}
|
||||||
tagCompound.setByte("Slot", (byte)slotCount);
|
}
|
||||||
getStackInSlot(slotCount).writeToNBT(tagCompound);
|
}
|
||||||
tagList.appendTag(tagCompound);
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbtTags)
|
||||||
nbtTags.setTag("VisibleItems", tagList);
|
{
|
||||||
}
|
super.writeToNBT(nbtTags);
|
||||||
|
|
||||||
structure.wroteInventory = true;
|
if (!structure.wroteInventory)
|
||||||
}
|
{
|
||||||
}
|
// Inventory
|
||||||
|
if (structure.inventory != null)
|
||||||
|
{
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
|
||||||
|
for (int slotCount = 0; slotCount < structure.inventory.size(); slotCount++)
|
||||||
|
{
|
||||||
|
if (structure.inventory.get(slotCount) != null)
|
||||||
|
{
|
||||||
|
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||||
|
tagCompound.setInteger("Slot", slotCount);
|
||||||
|
structure.inventory.get(slotCount).writeToNBT(tagCompound);
|
||||||
|
tagList.appendTag(tagCompound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nbtTags.setTag("Items", tagList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Visible inventory
|
||||||
|
if (structure.visibleInventory != null)
|
||||||
|
{
|
||||||
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
|
||||||
|
for (int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
||||||
|
{
|
||||||
|
if (slotCount > 0)
|
||||||
|
{
|
||||||
|
slotCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getStackInSlot(slotCount) != null)
|
||||||
|
{
|
||||||
|
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||||
|
tagCompound.setByte("Slot", (byte) slotCount);
|
||||||
|
getStackInSlot(slotCount).writeToNBT(tagCompound);
|
||||||
|
tagList.appendTag(tagCompound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nbtTags.setTag("VisibleItems", tagList);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return added energy
|
* @return added energy
|
||||||
*/
|
*/
|
||||||
public float addEnergy(float amount, boolean doAdd)
|
public float addEnergy(float amount, boolean doAdd)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return removed energy
|
* @return removed energy
|
||||||
*/
|
*/
|
||||||
public float removeEnergy(float amount, boolean doRemove)
|
public float removeEnergy(float amount, boolean doRemove)
|
||||||
{
|
{
|
||||||
List<ItemStack> inverse = ListUtil.inverse(structure.inventory);
|
List<ItemStack> inverse = ListUtil.inverse(structure.inventory);
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMaxEnergyStored()
|
public float getMaxEnergyStored()
|
||||||
{
|
{
|
||||||
if(!worldObj.isRemote)
|
if (!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
float max = 0;
|
float max = 0;
|
||||||
|
|
||||||
for (ItemStack itemStack : structure.inventory)
|
for (ItemStack itemStack : structure.inventory)
|
||||||
{
|
{
|
||||||
if (itemStack != null)
|
if (itemStack != null)
|
||||||
|
@ -312,20 +313,21 @@ 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;
|
||||||
|
|
||||||
for (ItemStack itemStack : structure.inventory)
|
for (ItemStack itemStack : structure.inventory)
|
||||||
{
|
{
|
||||||
if (itemStack != null)
|
if (itemStack != null)
|
||||||
|
@ -336,48 +338,53 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return clientEnergy;
|
return clientEnergy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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();
|
||||||
clientCells = input.readInt();
|
clientCells = input.readInt();
|
||||||
clientMaxEnergy = input.readFloat();
|
clientMaxEnergy = input.readFloat();
|
||||||
|
|
||||||
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
|
||||||
public ArrayList getNetworkedData(ArrayList data)
|
public ArrayList getNetworkedData(ArrayList data)
|
||||||
{
|
{
|
||||||
data.add(structure.isMultiblock);
|
data.add(structure.isMultiblock);
|
||||||
|
|
||||||
data.add(getEnergyStored());
|
data.add(getEnergyStored());
|
||||||
data.add(structure.inventory.size());
|
data.add(structure.inventory.size());
|
||||||
data.add(getMaxEnergyStored());
|
data.add(getMaxEnergyStored());
|
||||||
|
|
||||||
data.add(structure.height);
|
data.add(structure.height);
|
||||||
data.add(structure.length);
|
data.add(structure.length);
|
||||||
data.add(structure.width);
|
data.add(structure.width);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory()
|
public int getSizeInventory()
|
||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
@ -385,88 +392,95 @@ 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
|
||||||
public ItemStack getStackInSlotOnClosing(int i)
|
public ItemStack getStackInSlotOnClosing(int i)
|
||||||
{
|
{
|
||||||
return getStackInSlot(i);
|
return getStackInSlot(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,37 +491,41 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInvNameLocalized()
|
public boolean isInvNameLocalized()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit()
|
public int getInventoryStackLimit()
|
||||||
{
|
{
|
||||||
return 64;
|
return 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float transfer(float transferEnergy, boolean doTransfer)
|
public float transfer(float transferEnergy, boolean doTransfer)
|
||||||
{
|
{
|
||||||
return addEnergy(transferEnergy, doTransfer);
|
return addEnergy(transferEnergy, doTransfer);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue