The Mana Spreader now takes a list of all positions and blocks visited by the scan beam and checks against that before doing another simulation, this is a much needed performance change, hopefully server owners won't hate me anymore :)

This commit is contained in:
Vasco Lavos committed 2014-03-24 15:37:43 +00:00
1 parent 0bddc4b573
commit ea8f497575
2 files changed
+78 -31

No files matched your search

@@ -11,6 +11,8 @@
*/
package vazkii.botania.common.block.tile;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.entity.RenderItem;
@@ -40,6 +42,7 @@ import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.entity.EntityManaBurst;
import vazkii.botania.common.entity.EntityManaBurst.PositionProperties;
import vazkii.botania.common.lib.LibBlockNames;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
@@ -59,9 +62,12 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
IManaReceiver receiver = null;
public boolean canShootBurst = true;
public int lastBurstDeathTick = -1;
public int burstParticleTick = 0;
List<PositionProperties> lastTentativeBurst;
@Override
public boolean isFull() {
return mana >= MAX_MANA;
@@ -111,6 +117,9 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
redstone = true;
}
if(needsNewBurstSimulation())
checkForReceiver();
if(!redstone)
tryShootBurst();
}
@@ -132,14 +141,6 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
if(cmp.hasKey(TAG_KNOWN_MANA))
knownMana = cmp.getInteger(TAG_KNOWN_MANA);
if(worldObj != null && worldObj.isRemote) {
EntityManaBurst fakeBurst = getBurst(true);
TileEntity receiver = fakeBurst.getCollidedTile(true);
if(receiver != null && receiver instanceof IManaReceiver)
this.receiver = (IManaReceiver) receiver;
else this.receiver = null;
}
}
@Override
@@ -187,47 +188,50 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
this.receiver = (IManaReceiver) receiver;
else this.receiver = null;
checkForReceiver();
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
}
}
}
public boolean canShootBurst = true;
private boolean needsNewBurstSimulation() {
if(lastTentativeBurst == null)
return true;
for(PositionProperties props : lastTentativeBurst)
if(!props.contentsEqual(worldObj))
return true;
return false;
}
public void tryShootBurst() {
if(receiver == null) {
EntityManaBurst fakeBurst = getBurst(true);
TileEntity receiver = fakeBurst.getCollidedTile(true);
if(receiver != null && receiver instanceof IManaReceiver)
this.receiver = (IManaReceiver) receiver;
}
if(receiver != null) {
forceCheckReceiver();
if(receiver != null) {
if(canShootBurst && receiver.canRecieveManaFromBursts() && !receiver.isFull()) {
EntityManaBurst burst = getBurst(false);
if(burst != null) {
if(!worldObj.isRemote) {
mana -= burst.getStartingMana();
worldObj.spawnEntityInWorld(burst);
}
canShootBurst = false;
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
if(canShootBurst && receiver.canRecieveManaFromBursts() && !receiver.isFull()) {
EntityManaBurst burst = getBurst(false);
if(burst != null) {
if(!worldObj.isRemote) {
mana -= burst.getStartingMana();
worldObj.spawnEntityInWorld(burst);
}
canShootBurst = false;
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
}
}
}
}
public void forceCheckReceiver() {
public void checkForReceiver() {
System.out.println("check");
EntityManaBurst fakeBurst = getBurst(true);
fakeBurst.setScanBeam();
TileEntity receiver = fakeBurst.getCollidedTile(true);
if(receiver != null && receiver instanceof IManaReceiver)
this.receiver = (IManaReceiver) receiver;
else this.receiver = null;
lastTentativeBurst = fakeBurst.propsList;
}
public EntityManaBurst getBurst(boolean fake) {
@@ -362,7 +366,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector
@Override
public void onInventoryChanged() {
forceCheckReceiver();
checkForReceiver();
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
}
}
@@ -63,6 +63,9 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
List<String> alreadyCollidedAt = new ArrayList();
boolean fullManaLastTick = true;
boolean scanBeam = false;
public List<PositionProperties> propsList = new ArrayList();
public EntityManaBurst(World world) {
super(world);
@@ -356,6 +359,17 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
setMotion(motionX, motionY, motionZ);
fullManaLastTick = getMana() == getStartingMana();
if(scanBeam) {
PositionProperties props = new PositionProperties(this);
if(propsList.isEmpty())
propsList.add(props);
else {
PositionProperties lastProps = propsList.get(propsList.size() - 1);
if(!props.coordsEqual(lastProps))
propsList.add(props);
}
}
}
@Override
@@ -553,6 +567,10 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
public boolean isFake() {
return fake;
}
public void setScanBeam() {
scanBeam = true;
}
@Override
public int getColor() {
@@ -696,4 +714,29 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
if(tile != null && tile instanceof TileSpreader)
((TileSpreader) tile).lastBurstDeathTick = ticksExisted;
}
public static class PositionProperties {
public final ChunkCoordinates coords;
public final int id; int meta;
public PositionProperties(Entity entity) {
int x = (int) entity.posX;
int y = (int) entity.posY;
int z = (int) entity.posZ;
coords = new ChunkCoordinates(x, y, z);
id = entity.worldObj.getBlockId(x, y, z);
meta = entity.worldObj.getBlockMetadata(x, y, z);
}
public boolean coordsEqual(PositionProperties props) {
return coords.equals(props.coords);
}
public boolean contentsEqual(World world) {
int id = world.getBlockId(coords.posX, coords.posY, coords.posZ);
int meta = world.getBlockMetadata(coords.posX, coords.posY, coords.posZ);
return id == this.id && meta == this.meta;
}
}
}