mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-21 20:42:17 +00:00
Tweaking of lasers for packet-efficiency
This commit is contained in:
1 parent
c66676dd55
commit
775ba68482
9 files changed
+66
-97
No files matched your search
@@ -1,15 +1,23 @@
|
||||
package mekanism.common.tile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.lasers.LaserManager;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class TileEntityLaser extends TileEntityElectricBlock
|
||||
{
|
||||
public static final double LASER_ENERGY = 50000;
|
||||
|
||||
public boolean on;
|
||||
|
||||
public TileEntityLaser()
|
||||
{
|
||||
super("Laser", 100000);
|
||||
@@ -21,10 +29,48 @@ public class TileEntityLaser extends TileEntityElectricBlock
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
if(getEnergy() >= LASER_ENERGY)
|
||||
if(worldObj.isRemote)
|
||||
{
|
||||
LaserManager.fireLaser(Coord4D.get(this), ForgeDirection.getOrientation(facing), LASER_ENERGY, worldObj);
|
||||
setEnergy(getEnergy()-LASER_ENERGY);
|
||||
if(on)
|
||||
{
|
||||
LaserManager.fireLaserClient(Coord4D.get(this), ForgeDirection.getOrientation(facing), worldObj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(getEnergy() >= LASER_ENERGY)
|
||||
{
|
||||
if(!on)
|
||||
{
|
||||
on = true;
|
||||
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
|
||||
}
|
||||
LaserManager.fireLaser(Coord4D.get(this), ForgeDirection.getOrientation(facing), LASER_ENERGY, worldObj);
|
||||
setEnergy(getEnergy() - LASER_ENERGY);
|
||||
}
|
||||
else if(on)
|
||||
{
|
||||
on = false;
|
||||
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList getNetworkedData(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(on);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(ByteBuf dataStream)
|
||||
{
|
||||
super.handlePacketData(dataStream);
|
||||
|
||||
on = dataStream.readBoolean();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user