From 92195e8613b4bfd2cae5f15fea506535c94e684c Mon Sep 17 00:00:00 2001 From: SirSengir Date: Fri, 14 Sep 2012 18:24:20 +0200 Subject: [PATCH] Synch powerAverage on laser entities. Partial fix for #263 --- common/buildcraft/core/EntityEnergyLaser.java | 25 +++++++++++++++++++ common/buildcraft/core/EntityLaser.java | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/core/EntityEnergyLaser.java b/common/buildcraft/core/EntityEnergyLaser.java index 6c93ddc2..3dc5b5c6 100644 --- a/common/buildcraft/core/EntityEnergyLaser.java +++ b/common/buildcraft/core/EntityEnergyLaser.java @@ -56,4 +56,29 @@ public class EntityEnergyLaser extends EntityLaser { else return DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_4.png"; } + + @Override + protected void updateData() { + super.updateData(); + + powerAverage = (float)decodeDouble(dataWatcher.getWatchableObjectInt(15)); + } + + @Override + public void setPositions(Position head, Position tail) { + super.setPositions(head, tail); + dataWatcher.updateObject(15, Integer.valueOf(encodeDouble((double)powerAverage))); + } + + @Override + protected void initClientSide() { + super.initClientSide(); + dataWatcher.addObject(15, Integer.valueOf(0)); + } + + @Override + protected void initServerSide() { + super.initServerSide(); + dataWatcher.addObject(15, encodeDouble((double)powerAverage)); + } } diff --git a/common/buildcraft/core/EntityLaser.java b/common/buildcraft/core/EntityLaser.java index 8f17c8cf..5894e15e 100644 --- a/common/buildcraft/core/EntityLaser.java +++ b/common/buildcraft/core/EntityLaser.java @@ -160,11 +160,11 @@ public class EntityLaser extends Entity { return texture; } - private int encodeDouble(double d) { + protected int encodeDouble(double d) { return (int) (d * 8000); } - private double decodeDouble(int i) { + protected double decodeDouble(int i) { return (i / 8000D); }