mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Changed Tile Updating methodo to reduce performance usage and lag
This commit is contained in:
parent
fdd63c6d5e
commit
f62b1ede79
26 changed files with 76 additions and 44 deletions
|
@ -92,7 +92,7 @@ public class BlockBookletStand extends BlockContainerBase implements IActAddItem
|
|||
if(tile.assignedPlayer == null){
|
||||
tile.assignedPlayer = player.getCommandSenderName();
|
||||
tile.markDirty();
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
tile.sendUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ public class ItemLaserWrench extends Item implements IActAddItemOrBlock{
|
|||
if(savedPos.getTileEntity() instanceof TileEntityLaserRelay && LaserRelayConnectionHandler.getInstance().addConnection(savedPos, otherPos)){
|
||||
ItemPhantomConnector.clearStorage(stack);
|
||||
|
||||
savedPos.update();
|
||||
otherPos.update();
|
||||
((TileEntityLaserRelay)savedPos.getTileEntity()).sendUpdate();
|
||||
((TileEntityLaserRelay)otherPos.getTileEntity()).sendUpdate();
|
||||
|
||||
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".laser.connected.desc")));
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class PacketBookletStandButton implements IMessage{
|
|||
if(tile instanceof TileEntityBookletStand){
|
||||
if(Objects.equals(player.getCommandSenderName(), ((TileEntityBookletStand)tile).assignedPlayer)){
|
||||
((TileEntityBookletStand)tile).setEntry(message.entryID, message.chapterID, message.pageID, message.pageInIndex);
|
||||
world.markBlockForUpdate(message.tileX, message.tileY, message.tileZ);
|
||||
((TileEntityBookletStand)tile).sendUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* This file ("VanillaPacketSyncer.java") is part of the Actually Additions Mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015 Ellpeck
|
||||
*/
|
||||
|
||||
package ellpeck.actuallyadditions.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VanillaPacketSyncer{
|
||||
|
||||
public static void sendTileToNearbyPlayers(TileEntity tile){
|
||||
List allPlayers = tile.getWorldObj().playerEntities;
|
||||
for(Object player : allPlayers){
|
||||
if(player instanceof EntityPlayerMP){
|
||||
sendTileToPlayer(tile, (EntityPlayerMP)player, 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendTileToPlayer(TileEntity tile, EntityPlayerMP player, int maxDistance){
|
||||
if(player.getDistance(tile.xCoord, tile.yCoord, tile.zCoord) <= maxDistance){
|
||||
sendTileToPlayer(tile, player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendTileToPlayer(TileEntity tile, EntityPlayerMP player){
|
||||
player.playerNetServerHandler.sendPacket(tile.getDescriptionPacket());
|
||||
}
|
||||
}
|
|
@ -229,13 +229,13 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
|||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
this.sendUpdate();
|
||||
return super.decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
super.setInventorySlotContents(i, stack);
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
this.sendUpdate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ package ellpeck.actuallyadditions.tile;
|
|||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||
import ellpeck.actuallyadditions.network.VanillaPacketSyncer;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -112,13 +113,17 @@ public abstract class TileEntityBase extends TileEntity{
|
|||
|
||||
}
|
||||
|
||||
protected boolean trySendUpdate(){
|
||||
protected boolean sendUpdateWithInterval(){
|
||||
if(this.ticksElapsed % ConfigIntValues.TILE_ENTITY_UPDATE_INTERVAL.getValue() == 0){
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
this.sendUpdate();
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendUpdate(){
|
||||
VanillaPacketSyncer.sendTileToNearbyPlayers(this);
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
|
|||
}
|
||||
}
|
||||
|
||||
if((this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.trySendUpdate()){
|
||||
if((this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()){
|
||||
this.lastEnergyStored = this.storage.getEnergyStored();
|
||||
this.lastProcessTime = this.currentProcessTime;
|
||||
this.lastTankAmount = this.tank.getFluidAmount();
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
|||
}
|
||||
}
|
||||
|
||||
if((this.storage.getEnergyStored() != this.lastEnergy || this.currentBurnTime != this.lastCurrentBurnTime || this.lastBurnTime != this.maxBurnTime) && this.trySendUpdate()){
|
||||
if((this.storage.getEnergyStored() != this.lastEnergy || this.currentBurnTime != this.lastCurrentBurnTime || this.lastBurnTime != this.maxBurnTime) && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
this.lastCurrentBurnTime = this.currentBurnTime;
|
||||
this.lastBurnTime = this.currentBurnTime;
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
|||
this.brew();
|
||||
}
|
||||
|
||||
if((this.coffeeCacheAmount != this.lastCoffeeAmount || this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.brewTime != this.lastBrewTime) && this.trySendUpdate()){
|
||||
if((this.coffeeCacheAmount != this.lastCoffeeAmount || this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.brewTime != this.lastBrewTime) && this.sendUpdateWithInterval()){
|
||||
this.lastCoffeeAmount = coffeeCacheAmount;
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
this.lastTank = this.tank.getFluidAmount();
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
|
|||
}
|
||||
}
|
||||
|
||||
if(this.storage.getEnergyStored() != this.lastEnergy && this.trySendUpdate()){
|
||||
if(this.storage.getEnergyStored() != this.lastEnergy && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements IEne
|
|||
}
|
||||
}
|
||||
|
||||
if(lastEnergy != this.storage.getEnergyStored() && this.trySendUpdate()){
|
||||
if(lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
|
|||
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.WEST, storage);
|
||||
}
|
||||
|
||||
if(lastEnergy != this.storage.getEnergyStored() && this.trySendUpdate()){
|
||||
if(lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
|
|||
this.markDirty();
|
||||
}
|
||||
|
||||
if((this.lastAnimalAmount != this.currentAnimalAmount || this.lastTimer != this.currentTimer) && this.trySendUpdate()){
|
||||
if((this.lastAnimalAmount != this.currentAnimalAmount || this.lastTimer != this.currentTimer) && this.sendUpdateWithInterval()){
|
||||
this.lastAnimalAmount = this.currentAnimalAmount;
|
||||
this.lastTimer = this.currentTimer;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class TileEntityFermentingBarrel extends TileEntityInventoryBase implemen
|
|||
}
|
||||
}
|
||||
|
||||
if((this.canolaTank.getFluidAmount() != this.lastCanola || this.oilTank.getFluidAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime) && this.trySendUpdate()){
|
||||
if((this.canolaTank.getFluidAmount() != this.lastCanola || this.oilTank.getFluidAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()){
|
||||
this.lastProcessTime = this.currentProcessTime;
|
||||
this.lastCanola = this.canolaTank.getFluidAmount();
|
||||
this.lastOil = this.oilTank.getFluidAmount();
|
||||
|
|
|
@ -146,7 +146,7 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
|
|||
}
|
||||
}
|
||||
|
||||
if(lastTankAmount != this.tank.getFluidAmount() && this.trySendUpdate()){
|
||||
if(lastTankAmount != this.tank.getFluidAmount() && this.sendUpdateWithInterval()){
|
||||
lastTankAmount = this.tank.getFluidAmount();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
|||
}
|
||||
}
|
||||
|
||||
if((lastEnergy != this.storage.getEnergyStored() || this.lastFirstSmelt != this.firstSmeltTime || this.lastSecondSmelt != this.secondSmeltTime) && this.trySendUpdate()){
|
||||
if((lastEnergy != this.storage.getEnergyStored() || this.lastFirstSmelt != this.firstSmeltTime || this.lastSecondSmelt != this.secondSmeltTime) && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
this.lastFirstSmelt = this.firstSmeltTime;
|
||||
this.lastSecondSmelt = this.secondSmeltTime;
|
||||
|
|
|
@ -126,7 +126,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IEnerg
|
|||
}
|
||||
}
|
||||
|
||||
if((lastEnergy != this.storage.getEnergyStored() || this.lastFirstCrush != this.firstCrushTime || this.lastSecondCrush != this.secondCrushTime) && this.trySendUpdate()){
|
||||
if((lastEnergy != this.storage.getEnergyStored() || this.lastFirstCrush != this.firstCrushTime || this.lastSecondCrush != this.secondCrushTime) && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
this.lastFirstCrush = this.firstCrushTime;
|
||||
this.lastSecondCrush = this.secondCrushTime;
|
||||
|
|
|
@ -99,7 +99,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
}
|
||||
|
||||
//Update the Client
|
||||
if((this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.isPullWhitelist != lastPullWhite || this.isPutWhitelist != this.lastPutWhite) && this.trySendUpdate()){
|
||||
if((this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.isPullWhitelist != lastPullWhite || this.isPutWhitelist != this.lastPutWhite) && this.sendUpdateWithInterval()){
|
||||
this.lastPutSide = this.sideToPut;
|
||||
this.lastPullSide = this.sideToPull;
|
||||
this.lastPullStart = this.slotToPullStart;
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I
|
|||
this.nextRepairTick = 0;
|
||||
}
|
||||
|
||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.trySendUpdate()){
|
||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TileEntityOilGenerator extends TileEntityInventoryBase implements I
|
|||
}
|
||||
}
|
||||
|
||||
if((this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.lastBurnTime != this.currentBurnTime) && this.trySendUpdate()){
|
||||
if((this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.lastBurnTime != this.currentBurnTime) && this.sendUpdateWithInterval()){
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
this.lastTank = this.tank.getFluidAmount();
|
||||
this.lastBurnTime = this.currentBurnTime;
|
||||
|
|
|
@ -16,7 +16,6 @@ import ellpeck.actuallyadditions.blocks.BlockPhantom;
|
|||
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
||||
import ellpeck.actuallyadditions.util.Util;
|
||||
import ellpeck.actuallyadditions.util.WorldPos;
|
||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -55,7 +54,14 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
|
|||
this.rangeBefore = this.range;
|
||||
this.boundPosBefore = this.boundPosition;
|
||||
this.boundBlockBefore = this.boundPosition == null ? null : this.boundPosition.getBlock();
|
||||
WorldUtil.updateTileAndTilesAround(this);
|
||||
|
||||
this.getWorldObj().markBlockForUpdate(this.xCoord+1, this.yCoord, this.zCoord);
|
||||
this.getWorldObj().markBlockForUpdate(this.xCoord-1, this.yCoord, this.zCoord);
|
||||
this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord+1, this.zCoord);
|
||||
this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord-1, this.zCoord);
|
||||
this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord+1);
|
||||
this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord-1);
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -57,7 +57,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
|
|||
}
|
||||
}
|
||||
|
||||
if(this.isWhitelist != this.lastWhitelist && this.trySendUpdate()){
|
||||
if(this.isWhitelist != this.lastWhitelist && this.sendUpdateWithInterval()){
|
||||
this.lastWhitelist = this.isWhitelist;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TileEntitySmileyCloud extends TileEntityBase implements IStringReac
|
|||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
if(!worldObj.isRemote){
|
||||
if(!Objects.equals(this.name, this.nameBefore) && this.trySendUpdate()){
|
||||
if(!Objects.equals(this.name, this.nameBefore) && this.sendUpdateWithInterval()){
|
||||
this.nameBefore = this.name;
|
||||
this.markDirty();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
|
|||
}
|
||||
}
|
||||
|
||||
if(this.lastAmount != this.amount && this.trySendUpdate()){
|
||||
if(this.lastAmount != this.amount && this.sendUpdateWithInterval()){
|
||||
this.lastAmount = this.amount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,12 +86,6 @@ public class WorldPos{
|
|||
return this.z;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(this.getWorld() != null){
|
||||
this.getWorld().markBlockForUpdate(this.x, this.y, this.z);
|
||||
}
|
||||
}
|
||||
|
||||
public WorldPos copy(){
|
||||
return new WorldPos(this.getWorld(), this.x, this.y, this.z);
|
||||
}
|
||||
|
|
|
@ -111,17 +111,6 @@ public class WorldUtil{
|
|||
return true;
|
||||
}
|
||||
|
||||
public static void updateTileAndTilesAround(TileEntity tile){
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord+1, tile.yCoord, tile.zCoord);
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord-1, tile.yCoord, tile.zCoord);
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord+1, tile.zCoord);
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord-1, tile.zCoord);
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord+1);
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord-1);
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
tile.markDirty();
|
||||
}
|
||||
|
||||
public static void pushFluid(World world, int x, int y, int z, ForgeDirection side, FluidTank tank){
|
||||
TileEntity tile = getTileEntityFromSide(side, world, x, y, z);
|
||||
if(tile != null && tank.getFluid() != null && tile instanceof IFluidHandler){
|
||||
|
|
Loading…
Reference in a new issue