Fixed Modular Battery not working with BuildCraft

This commit is contained in:
Calclavia 2013-08-07 23:25:48 -04:00
parent 2710f976f9
commit ada50089e9
5 changed files with 94 additions and 53 deletions

@ -1 +1 @@
Subproject commit e34b3fdae603d3ae7a4345df8da321c5903b357b Subproject commit 3538b31ba452890fa742b472df2fb9d1555a61cd

View file

@ -55,9 +55,18 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick) public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick)
{ {
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
if (entityPlayer.isSneaking()) if (entityPlayer.isSneaking())
{ {
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.ROTATION_MATRIX[world.getBlockMetadata(x, y, z)][side], 3); boolean result = tileEntity.toggleSide(ForgeDirection.getOrientation(side));
if (!world.isRemote)
{
entityPlayer.addChatMessage("Toggled side to: " + (result ? "input" : "output"));
}
return true;
} }
else else
{ {
@ -69,8 +78,6 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
{ {
if (!world.isRemote) if (!world.isRemote)
{ {
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
if (tileEntity.structure.addCell(entityPlayer.getCurrentEquippedItem())) if (tileEntity.structure.addCell(entityPlayer.getCurrentEquippedItem()))
{ {
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null); entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null);

View file

@ -45,6 +45,9 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
public int clientCells; public int clientCells;
public float clientMaxEnergy; public float clientMaxEnergy;
private EnumSet inputSides = EnumSet.allOf(ForgeDirection.class);
private EnumSet outputSides = EnumSet.noneOf(ForgeDirection.class);
@Override @Override
public void updateEntity() public void updateEntity()
{ {
@ -327,11 +330,11 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
@Override @Override
public float getMaxEnergyStored() public float getMaxEnergyStored()
{ {
if (!worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
float max = 0; float max = 0;
for (ItemStack itemStack : structure.inventory) for (ItemStack itemStack : this.structure.inventory)
{ {
if (itemStack != null) if (itemStack != null)
{ {
@ -346,18 +349,18 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
} }
else else
{ {
return clientMaxEnergy; return this.clientMaxEnergy;
} }
} }
@Override @Override
public float getEnergyStored() public float getEnergyStored()
{ {
if (!worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
float energy = 0; float energy = 0;
for (ItemStack itemStack : structure.inventory) for (ItemStack itemStack : this.structure.inventory)
{ {
if (itemStack != null) if (itemStack != null)
{ {
@ -548,9 +551,9 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) public boolean isItemValidForSlot(int i, ItemStack itemsSack)
{ {
return false; return itemsSack.getItem() instanceof IItemElectric;
} }
@Override @Override
@ -565,9 +568,34 @@ public class TileEntityBattery extends TileEntityUniversalElectrical implements
return this.getEnergyStored(); return this.getEnergyStored();
} }
@Override
public EnumSet<ForgeDirection> getInputDirections()
{
return this.inputSides;
}
@Override @Override
public EnumSet<ForgeDirection> getOutputDirections() public EnumSet<ForgeDirection> getOutputDirections()
{ {
return EnumSet.allOf(ForgeDirection.class); return this.outputSides;
}
/**
* Toggles the input/output sides of the battery.
*/
public boolean toggleSide(ForgeDirection orientation)
{
if (this.inputSides.contains(orientation))
{
this.inputSides.remove(orientation);
this.outputSides.add(orientation);
return false;
}
else
{
this.outputSides.remove(orientation);
this.inputSides.add(orientation);
return true;
}
} }
} }

View file

@ -59,45 +59,48 @@ public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketR
{ {
super.updateEntity(); super.updateEntity();
if (this.ticks % 20 == 0) if (!this.worldObj.isRemote)
{ {
float prevDetectedEnergy = this.detectedEnergy; if (this.ticks % 20 == 0)
this.detectedEnergy = this.doGetDetectedEnergy();
this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2;
this.peakDetection = Math.max(peakDetection, this.detectedEnergy);
boolean outputRedstone = false;
switch (detectMode)
{ {
default: float prevDetectedEnergy = this.detectedEnergy;
break; this.detectedEnergy = this.doGetDetectedEnergy();
case EQUAL: this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2;
outputRedstone = this.detectedEnergy == this.energyLimit; this.peakDetection = Math.max(peakDetection, this.detectedEnergy);
break;
case GREATER_THAN:
outputRedstone = this.detectedEnergy > this.energyLimit;
break;
case GREATER_THAN_EQUAL:
outputRedstone = this.detectedEnergy >= this.energyLimit;
break;
case LESS_THAN:
outputRedstone = this.detectedEnergy < this.energyLimit;
break;
case LESS_THAN_EQUAL:
outputRedstone = this.detectedEnergy <= this.energyLimit;
break;
}
if (outputRedstone != this.redstoneOn) boolean outputRedstone = false;
{
this.redstoneOn = outputRedstone;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, ResonantInduction.blockMultimeter.blockID);
}
if (prevDetectedEnergy != this.detectedEnergy) switch (detectMode)
{ {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); default:
break;
case EQUAL:
outputRedstone = this.detectedEnergy == this.energyLimit;
break;
case GREATER_THAN:
outputRedstone = this.detectedEnergy > this.energyLimit;
break;
case GREATER_THAN_EQUAL:
outputRedstone = this.detectedEnergy >= this.energyLimit;
break;
case LESS_THAN:
outputRedstone = this.detectedEnergy < this.energyLimit;
break;
case LESS_THAN_EQUAL:
outputRedstone = this.detectedEnergy <= this.energyLimit;
break;
}
if (outputRedstone != this.redstoneOn)
{
this.redstoneOn = outputRedstone;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, ResonantInduction.blockMultimeter.blockID);
}
if (prevDetectedEnergy != this.detectedEnergy)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
} }
} }

View file

@ -173,7 +173,7 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
{ {
float transferEnergy = this.getEnergyStored() / transferTeslaCoils.size(); float transferEnergy = this.getEnergyStored() / transferTeslaCoils.size();
int count = 0; int count = 0;
for (ITesla tesla : transferTeslaCoils) for (ITesla tesla : transferTeslaCoils)
{ {
if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS) if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS)
@ -275,13 +275,10 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
BlockFurnace.updateFurnaceBlockState(furnaceTile.furnaceBurnTime > 0, furnaceTile.worldObj, furnaceTile.xCoord, furnaceTile.yCoord, furnaceTile.zCoord); BlockFurnace.updateFurnaceBlockState(furnaceTile.furnaceBurnTime > 0, furnaceTile.worldObj, furnaceTile.xCoord, furnaceTile.yCoord, furnaceTile.zCoord);
} }
} }
if (this.ticks % 20 == 0)
{
this.produce();
}
} }
this.produce();
if (!this.worldObj.isRemote && this.getEnergyStored() > 0 != doPacketUpdate) if (!this.worldObj.isRemote && this.getEnergyStored() > 0 != doPacketUpdate)
{ {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
@ -303,6 +300,12 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
return this.canReceive && !this.outputBlacklist.contains(tileEntity) && this.getRequest(ForgeDirection.UNKNOWN) > 0; return this.canReceive && !this.outputBlacklist.contains(tileEntity) && this.getRequest(ForgeDirection.UNKNOWN) > 0;
} }
@Override
public boolean canConnect(ForgeDirection direction)
{
return this.isController();
}
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {