mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
Fixed cap. bank performance.
This commit is contained in:
1 parent
641a9d440c
commit
1855feabec
5 files changed
+114
-14
No files matched your search
@@ -43,6 +43,7 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
|
||||
|
||||
public static BlockCapacitorBank create() {
|
||||
EnderIO.packetPipeline.registerPacket(PacketClientState.class);
|
||||
EnderIO.packetPipeline.registerPacket(PacketPowerStorage.class);
|
||||
|
||||
BlockCapacitorBank res = new BlockCapacitorBank();
|
||||
res.init();
|
||||
|
||||
@@ -90,8 +90,9 @@ public class CapBankRenderer2 implements ISimpleBlockRenderingHandler {
|
||||
if(!(te instanceof TileCapacitorBank)) {
|
||||
return;
|
||||
}
|
||||
TileCapacitorBank capBank = ((TileCapacitorBank) te);
|
||||
List<GaugeBounds> gaugeBounds = null;
|
||||
gaugeBounds = ((TileCapacitorBank) te).getGaugeBounds();
|
||||
gaugeBounds = capBank.getGaugeBounds();
|
||||
|
||||
if(gaugeBounds == null || gaugeBounds.isEmpty()) {
|
||||
return;
|
||||
@@ -122,7 +123,8 @@ public class CapBankRenderer2 implements ISimpleBlockRenderingHandler {
|
||||
tes.setColorRGBA_F(col.x, col.y, col.z, col.w);
|
||||
}
|
||||
renderGaugeOnFace(gb, EnderIO.blockCapacitorBank.overlayIcon, refVertices, x, y, z);
|
||||
renderFillBarOnFace(gb, EnderIO.blockCapacitorBank.fillBarIcon, ((TileCapacitorBank) te).getEnergyStoredRatio(), refVertices, x, y, z);
|
||||
renderFillBarOnFace(gb, EnderIO.blockCapacitorBank.fillBarIcon,capBank.getEnergyStoredRatio(), refVertices, x, y, z);
|
||||
capBank.lastRenderStoredRatio = capBank.getEnergyStoredRatio();
|
||||
tes.addTranslation((float) -x, (float) -y, (float) -z);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package crazypants.enderio.machine.power;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.network.IPacketEio;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class PacketPowerStorage implements IPacketEio {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private float storedEnergy;
|
||||
|
||||
public PacketPowerStorage() {
|
||||
}
|
||||
|
||||
public PacketPowerStorage(TileCapacitorBank ent) {
|
||||
x = ent.xCoord;
|
||||
y = ent.yCoord;
|
||||
z = ent.zCoord;
|
||||
storedEnergy = ent.storedEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeFloat(storedEnergy);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
storedEnergy = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
handle(player);
|
||||
}
|
||||
|
||||
private void handle(EntityPlayer player) {
|
||||
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapacitorBank) {
|
||||
TileCapacitorBank me = (TileCapacitorBank) te;
|
||||
me.storedEnergy = storedEnergy;
|
||||
|
||||
float dif = Math.abs(me.lastRenderStoredRatio - me.getEnergyStoredRatio());
|
||||
if(dif > 0.025) { //update rendering at a 2.5% diff
|
||||
if(!me.isMultiblock()) {
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
} else {
|
||||
BlockCoord[] mb = me.multiblock;
|
||||
for(BlockCoord bc : mb) {
|
||||
updateGaugeRender(player.worldObj, bc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGaugeRender(World worldObj, BlockCoord bc) {
|
||||
TileEntity te = worldObj.getTileEntity(bc.x, bc.y, bc.z);
|
||||
if(te instanceof TileCapacitorBank) {
|
||||
TileCapacitorBank me = (TileCapacitorBank) te;
|
||||
List<GaugeBounds> gb = me.getGaugeBounds();
|
||||
if(gb != null && !gb.isEmpty()) {
|
||||
worldObj.markBlockForUpdate(bc.x, bc.y, bc.z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
|
||||
private float lastSyncPowerStored;
|
||||
|
||||
private float storedEnergy;
|
||||
float storedEnergy;
|
||||
|
||||
private int maxStoredEnergy;
|
||||
|
||||
@@ -95,6 +95,8 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
|
||||
private boolean isCreative = false;
|
||||
|
||||
float lastRenderStoredRatio;
|
||||
|
||||
public TileCapacitorBank() {
|
||||
inventory = new ItemStack[4];
|
||||
storedEnergy = 0;
|
||||
@@ -215,8 +217,8 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return;
|
||||
}
|
||||
|
||||
boolean requiresClientSync = false;
|
||||
requiresClientSync = chargeItems();
|
||||
|
||||
chargeItems();
|
||||
|
||||
boolean hasSignal = isRecievingRedstoneSignal();
|
||||
if(inputControlMode == RedstoneControlMode.IGNORE) {
|
||||
@@ -247,14 +249,11 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
storedEnergy = getMaxEnergyStored()/2;
|
||||
}
|
||||
|
||||
requiresClientSync |= lastSyncPowerStored != storedEnergy && worldObj.getTotalWorldTime() % 10 == 0;
|
||||
|
||||
if(requiresClientSync) {
|
||||
if(lastSyncPowerStored != storedEnergy && worldObj.getTotalWorldTime() % 10 == 0) {
|
||||
lastSyncPowerStored = storedEnergy;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
markDirty();
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketPowerStorage(this), this, 64);
|
||||
}
|
||||
|
||||
|
||||
if(notifyNeighbours) {
|
||||
worldObj.notifyBlockOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
|
||||
notifyNeighbours = false;
|
||||
@@ -269,7 +268,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return gaugeBounds;
|
||||
}
|
||||
|
||||
private boolean chargeItems() {
|
||||
private void chargeItems() {
|
||||
boolean chargedItem = false;
|
||||
float available = Math.min(maxIO, storedEnergy);
|
||||
for (ItemStack item : inventory) {
|
||||
@@ -296,7 +295,9 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
}
|
||||
}
|
||||
}
|
||||
return chargedItem;
|
||||
if(chargedItem) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOutputEnabled() {
|
||||
|
||||
@@ -212,8 +212,12 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, IPacke
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
public void sendToAllAround(IPacketEio message, TileEntity te, int range) {
|
||||
sendToAllAround(message, new TargetPoint(te.getWorldObj().provider.dimensionId, te.xCoord, te.yCoord, te.zCoord, range));
|
||||
}
|
||||
|
||||
public void sendToAllAround(IPacketEio message, TileEntity te) {
|
||||
sendToAllAround(message, new TargetPoint(te.getWorldObj().provider.dimensionId, te.xCoord, te.yCoord, te.zCoord, 16));
|
||||
sendToAllAround(message, te, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user