Phased out any usage of World.getTotalWorldTime() in favor of internal tickers. SubTileEntity now has a session and packet safe internal ticker.

This commit is contained in:
Lizbeth Rika committed 2014-12-05 19:20:17 +00:00
1 parent 0a7d5ec220
commit 765e302c7e
23 files changed
+47 -46

No files matched your search

@@ -33,20 +33,36 @@ import cpw.mods.fml.relauncher.SideOnly;
public class SubTileEntity {
protected TileEntity supertile;
public int ticksExisted = 0;
/** The Tag items should use to store which sub tile they are. **/
public static final String TAG_TYPE = "type";
public static final String TAG_TICKS_EXISTED = "ticksExisted";
public void setSupertile(TileEntity tile) {
supertile = tile;
}
public boolean canUpdate() {
return false;
return true;
}
public void onUpdate() { }
public void onUpdate() {
ticksExisted++;
}
public final void writeToPacketNBTInternal(NBTTagCompound cmp) {
cmp.setInteger(TAG_TICKS_EXISTED, ticksExisted);
writeToPacketNBT(cmp);
}
public final void readFromPacketNBTInternal(NBTTagCompound cmp) {
if(cmp.hasKey(TAG_TICKS_EXISTED))
ticksExisted = cmp.getInteger(TAG_TICKS_EXISTED);
readFromPacketNBT(cmp);
}
/**
* Writes some extra data to a network packet. This data is read
* by readFromPacketNBT on the client that receives the packet.
@@ -47,11 +47,6 @@ public class SubTileFunctional extends SubTileEntity {
ChunkCoordinates cachedPoolCoordinates = null;
@Override
public boolean canUpdate() {
return true;
}
/**
* If set to true, redstoneSignal will be updated every tick.
*/
@@ -32,7 +32,6 @@ import vazkii.botania.api.mana.IManaCollector;
public class SubTileGenerating extends SubTileEntity {
private static final String TAG_MANA = "mana";
private static final String TAG_TICKS_EXISTED = "ticksExisted";
private static final String TAG_COLLECTOR_X = "collectorX";
private static final String TAG_COLLECTOR_Y = "collectorY";
@@ -40,18 +39,12 @@ public class SubTileGenerating extends SubTileEntity {
protected int mana;
int ticksExisted = 0;
int sizeLastCheck = -1;
protected TileEntity linkedCollector = null;
public int knownMana = -1;
ChunkCoordinates cachedCollectorCoordinates = null;
@Override
public boolean canUpdate() {
return true;
}
@Override
public void onUpdate() {
super.onUpdate();
@@ -60,7 +53,7 @@ public class SubTileGenerating extends SubTileEntity {
if(canGeneratePassively()) {
int delay = getDelayBetweenPassiveGeneration();
if(delay > 0 && supertile.getWorldObj().getWorldTime() % delay == 0) {
if(delay > 0 && ticksExisted % delay == 0) {
if(shouldSyncPassiveGeneration())
sync();
addMana(getValueForPassiveGeneration());
@@ -24,13 +24,10 @@ public class SubTileManastar extends SubTileEntity {
int manaLastTick = -1;
@Override
public boolean canUpdate() {
return true;
}
@Override
public void onUpdate() {
super.onUpdate();
int mana = 0;
for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS) {
TileEntity tile = supertile.getWorldObj().getTileEntity(supertile.xCoord + dir.offsetX, supertile.yCoord, supertile.zCoord + dir.offsetZ);
@@ -43,7 +40,7 @@ public class SubTileManastar extends SubTileEntity {
Botania.proxy.wispFX(supertile.getWorldObj(), supertile.xCoord + 0.55 + Math.random() * 0.2 - 0.1, supertile.yCoord + 0.75 + Math.random() * 0.2 - 0.1, supertile.zCoord + 0.5, more ? 0.05F : 1F, 0.05F, more ? 1F : 0.05F, (float) Math.random() / 7, (float) -Math.random() / 50);
}
if(supertile.getWorldObj().getTotalWorldTime() % 60 == 0)
if(ticksExisted % 60 == 0)
manaLastTick = mana;
}
@@ -44,13 +44,10 @@ public class SubTilePureDaisy extends SubTileEntity {
int positionAt = 0;
int[] ticksRemaining = new int[] { 200, 200, 200, 200, 200, 200, 200, 200 };
@Override
public boolean canUpdate() {
return true;
}
@Override
public void onUpdate() {
super.onUpdate();
positionAt++;
if(positionAt == POSITIONS.length)
positionAt = 0;
@@ -28,7 +28,7 @@ public class SubTileAgricarnation extends SubTileFunctional {
public void onUpdate() {
super.onUpdate();
if(supertile.getWorldObj().getTotalWorldTime() % 6 == 0 && redstoneSignal == 0) {
if(ticksExisted % 6 == 0 && redstoneSignal == 0) {
int range = 5;
int x = supertile.xCoord + supertile.getWorldObj().rand.nextInt(range * 2 + 1) - range;
int z = supertile.zCoord + supertile.getWorldObj().rand.nextInt(range * 2 + 1) - range;
@@ -45,7 +45,7 @@ public class SubTileBellethorn extends SubTileFunctional {
final int range = 6;
final int manaToUse = getManaCost();
if(supertile.getWorldObj().getTotalWorldTime() % 5 == 0) {
if(ticksExisted % 5 == 0) {
List<EntityLivingBase> entities = supertile.getWorldObj().getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(supertile.xCoord - range, supertile.yCoord, supertile.zCoord - range, supertile.xCoord + range, supertile.yCoord + 1, supertile.zCoord + range));
IEntitySelector selector = getSelector();
@@ -30,7 +30,7 @@ public class SubTileClayconia extends SubTileFunctional {
public void onUpdate() {
super.onUpdate();
if(!supertile.getWorldObj().isRemote && supertile.getWorldObj().getTotalWorldTime() % 5 == 0) {
if(!supertile.getWorldObj().isRemote && ticksExisted % 5 == 0) {
int manaCost = 80;
if(mana >= manaCost) {
ChunkCoordinates coords = getCoordsToPut();
@@ -48,7 +48,7 @@ public class SubTileExoflame extends SubTileFunctional {
BlockFurnace.updateFurnaceBlockState(true, supertile.getWorldObj(), x, y, z);
furnace.furnaceBurnTime = 200;
}
if(supertile.getWorldObj().getTotalWorldTime() % 2 == 0)
if(ticksExisted % 2 == 0)
furnace.furnaceCookTime = Math.min(199, furnace.furnaceCookTime + 1);
mana -= 2;
@@ -62,7 +62,7 @@ public class SubTileExoflame extends SubTileFunctional {
if(heatable.canSmelt() && mana > 2) {
if(heatable.getBurnTime() == 0)
heatable.boostBurnTime();
if(supertile.getWorldObj().getTotalWorldTime() % 2 == 0)
if(ticksExisted % 2 == 0)
heatable.boostCookTime();
mana -= 2;
@@ -31,7 +31,7 @@ public class SubTileJadedAmaranthus extends SubTileFunctional {
if(redstoneSignal > 0)
return;
if(mana >= COST && !supertile.getWorldObj().isRemote && supertile.getWorldObj().getTotalWorldTime() % 30 == 0) {
if(mana >= COST && !supertile.getWorldObj().isRemote && ticksExisted % 30 == 0) {
int range = 4;
int x = supertile.xCoord - range + supertile.getWorldObj().rand.nextInt(range * 2 + 1);
int y = supertile.yCoord + range;
@@ -27,7 +27,7 @@ public class SubTileLoonuim extends SubTileFunctional {
@Override
public void onUpdate() {
super.onUpdate();
if(redstoneSignal == 0 && supertile.getWorldObj().getTotalWorldTime() % 200 == 0 && mana >= COST) {
if(redstoneSignal == 0 && ticksExisted % 200 == 0 && mana >= COST) {
Random rand = supertile.getWorldObj().rand;
ItemStack stack = ChestGenHooks.getOneItem(ChestGenHooks.DUNGEON_CHEST, rand);
EntityItem entity = new EntityItem(supertile.getWorldObj(), supertile.xCoord - 3 + rand.nextInt(7) , supertile.yCoord + 1, supertile.zCoord - 3 + rand.nextInt(7), stack);
@@ -47,7 +47,7 @@ public class SubTileRannuncarpus extends SubTileFunctional {
if(redstoneSignal > 0)
return;
if(supertile.getWorldObj().getTotalWorldTime() % 10 == 0) {
if(ticksExisted % 10 == 0) {
BlockData filter = getUnderlyingBlock();
boolean scanned = false;
@@ -58,7 +58,7 @@ public class SubTileTangleberrie extends SubTileFunctional {
}
}
if(supertile.getWorldObj().getTotalWorldTime() % 4 == 0) {
if(ticksExisted % 4 == 0) {
mana--;
sync();
}
@@ -38,7 +38,7 @@ public class SubtileOrechid extends SubTileFunctional {
if(redstoneSignal > 0)
return;
if(!supertile.getWorldObj().isRemote && mana >= COST && supertile.getWorldObj().getTotalWorldTime() % 100 == 0) {
if(!supertile.getWorldObj().isRemote && mana >= COST && ticksExisted % 100 == 0) {
ChunkCoordinates coords = getCoordsToPut();
if(coords != null) {
ItemStack stack = getOreToPut();
@@ -60,7 +60,7 @@ public class SubTileDaybloom extends SubTileGenerating {
float b = color.getBlue() / 255F;
float m = 0.045F;
if(supertile.getWorldObj().getTotalWorldTime() % 10 == 0)
if(ticksExisted % 10 == 0)
Botania.proxy.wispFX(supertile.getWorldObj(), supertile.xCoord + 0.5, supertile.yCoord + 0.05, supertile.zCoord + 0.5, r, g, b, 0.1F, dir.offsetX * m, dir.offsetY * m, dir.offsetZ * m);
}
}
@@ -33,7 +33,7 @@ public class SubTileHydroangeas extends SubTileGenerating {
boolean didSomething = false;
if(burnTime == 0) {
if(supertile.getWorldObj().getWorldTime() % 40L == 0)
if(ticksExisted % 40L == 0)
if(mana < getMaxMana() && !supertile.getWorldObj().isRemote) {
Random random = new Random();
int randomInt = random.nextInt(3);
@@ -25,7 +25,7 @@ public class SubTileKekimurus extends SubTileGenerating {
int mana = 640;
if(getMaxMana() - this.mana >= mana && !supertile.getWorldObj().isRemote && supertile.getWorldObj().getTotalWorldTime() % 50 == 0) {
if(getMaxMana() - this.mana >= mana && !supertile.getWorldObj().isRemote && ticksExisted % 50 == 0) {
int range = 5;
for(int i = 0; i < range * 2 + 1; i++)
for(int j = 0; j < range * 2 + 1; j++)
@@ -31,7 +31,7 @@ public class SubTileMunchdew extends SubTileGenerating {
super.onUpdate();
int manaPerLeaf = 16;
if(getMaxMana() - mana >= manaPerLeaf && !supertile.getWorldObj().isRemote && supertile.getWorldObj().getTotalWorldTime() % 4 == 0) {
if(getMaxMana() - mana >= manaPerLeaf && !supertile.getWorldObj().isRemote && ticksExisted % 4 == 0) {
List<ChunkCoordinates> coords = new ArrayList();
int range = 8;
int rangeY = 16;
@@ -25,9 +25,11 @@ public class TilePylon extends TileEntity {
boolean activated = false;
int centerX, centerY, centerZ;
int ticks = 0;
@Override
public void updateEntity() {
++ticks;
int meta = getBlockMetadata();
if(activated && worldObj.isRemote) {
@@ -40,7 +42,7 @@ public class TilePylon extends TileEntity {
if(meta == 1) {
if(ConfigHandler.elfPortalParticlesEnabled) {
double worldTime = (int) worldObj.getTotalWorldTime();
double worldTime = ticks;
worldTime += new Random(xCoord ^ yCoord ^ zCoord).nextInt(1000);
worldTime /= 5;
@@ -103,7 +103,7 @@ public class TileSpecialFlower extends TileMod implements IWandBindable, ISubTil
cmp.setTag(TAG_SUBTILE_CMP, subCmp);
if(subTile != null)
subTile.writeToPacketNBT(subCmp);
subTile.readFromPacketNBTInternal(subCmp);
}
@Override
@@ -117,7 +117,7 @@ public class TileSpecialFlower extends TileMod implements IWandBindable, ISubTil
provideSubTile(subTileName);
if(subTile != null)
subTile.readFromPacketNBT(subCmp);
subTile.readFromPacketNBTInternal(subCmp);
}
public IIcon getIcon() {
@@ -27,7 +27,7 @@ public class ItemAuraRing extends ItemBauble {
@Override
public void onWornTick(ItemStack stack, EntityLivingBase player) {
super.onWornTick(stack, player);
if(player instanceof EntityPlayer && player.worldObj.getTotalWorldTime() % 2 == 0)
if(player instanceof EntityPlayer && player.ticksExisted % 2 == 0)
ManaItemHandler.dispatchManaExact(stack, (EntityPlayer) player, 1, true);
}
@@ -28,7 +28,7 @@ public class ItemGreaterAuraRing extends ItemBauble {
public void onWornTick(ItemStack stack, EntityLivingBase player) {
super.onWornTick(stack, player);
if(player instanceof EntityPlayer)
ManaItemHandler.dispatchManaExact(stack, (EntityPlayer) player, player.worldObj.getTotalWorldTime() % 3 == 0 ? 2 : 1, true);
ManaItemHandler.dispatchManaExact(stack, (EntityPlayer) player, player.ticksExisted % 3 == 0 ? 2 : 1, true);
}
@Override
@@ -27,6 +27,7 @@ import vazkii.botania.api.internal.IGuiLexiconEntry;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.lexicon.LexiconRecipeMappings;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.handler.ConfigHandler;
@@ -67,7 +68,7 @@ public class PagePetalRecipe<T extends RecipePetals> extends PageRecipe {
List<Object> inputs = recipe.getInputs();
int degreePerInput = (int) (360F / inputs.size());
int currentDegree = ConfigHandler.lexiconRotatingItems ? (int) Minecraft.getMinecraft().theWorld.getTotalWorldTime() : 0;
int currentDegree = ConfigHandler.lexiconRotatingItems ? (int) ClientTickHandler.ticksInGame : 0;
for(Object obj : inputs) {
Object input = obj;