Fixed GC lag in force fields and breathing manager

This commit is contained in:
Unknown 2019-10-16 00:01:42 +02:00 committed by unknown
parent 8628eda807
commit 5bf4b6c4e7
4 changed files with 34 additions and 24 deletions

View file

@ -26,6 +26,7 @@ import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.World;
public class BreathingManager {
@ -47,9 +48,10 @@ public class BreathingManager {
private static final HashMap<UUID, Integer> player_airTank = new HashMap<>();
public static boolean hasAirBlock(final EntityLivingBase entityLivingBase, final int x, final int y, final int z) {
final MutableBlockPos mutableBlockPos = new MutableBlockPos();
for (final VectorI vOffset : vAirOffsets) {
final VectorI vPosition = new VectorI(x + vOffset.x, y + vOffset.y, z + vOffset.z);
final Block block = vPosition.getBlockState(entityLivingBase.world).getBlock();
mutableBlockPos.setPos(x + vOffset.x, y + vOffset.y, z + vOffset.z);
final Block block = entityLivingBase.world.getBlockState(mutableBlockPos).getBlock();
if (isAirBlock(block)) {
return true;
}
@ -91,27 +93,27 @@ public class BreathingManager {
// find an air block
final UUID uuidEntity = entityLivingBase.getUniqueID();
VectorI vAirBlock = null;
boolean notInVacuum = false;
final MutableBlockPos mutableBlockPos = new MutableBlockPos();
IBlockState blockState;
Block block;
for (final VectorI vOffset : vAirOffsets) {
final VectorI vPosition = new VectorI(x + vOffset.x, y + vOffset.y, z + vOffset.z);
blockState = vPosition.getBlockState(entityLivingBase.world);
mutableBlockPos.setPos(x + vOffset.x, y + vOffset.y, z + vOffset.z);
blockState = entityLivingBase.world.getBlockState(mutableBlockPos);
block = blockState.getBlock();
if (isAirBlock(block)) {
vAirBlock = vPosition;
notInVacuum = true;
break;
} else if (block != Blocks.AIR) {
final StateAir stateAir = ChunkHandler.getStateAir(entityLivingBase.world, vPosition.x, vPosition.y, vPosition.z);
final StateAir stateAir = ChunkHandler.getStateAir(entityLivingBase.world, mutableBlockPos.getX(), mutableBlockPos.getY(), mutableBlockPos.getZ());
if ( stateAir == null
|| stateAir.concentration > 0 ) {
vAirBlock = vPosition;
notInVacuum = true;
break;
}
}
}
final boolean notInVacuum = vAirBlock != null;
Integer air = entity_airBlock.get(uuidEntity);
if (notInVacuum) {// no atmosphere with air blocks
if (air == null) {

View file

@ -12,7 +12,6 @@ import cr0s.warpdrive.data.EnumPermissionNode;
import cr0s.warpdrive.data.EnumTier;
import cr0s.warpdrive.data.ForceFieldSetup;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import cr0s.warpdrive.event.ModelBakeEventHandler;
import cr0s.warpdrive.render.BakedModelCamouflage;
@ -252,7 +251,15 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
private ForceFieldSetup getForceFieldSetup(@Nonnull final IBlockAccess blockAccess, @Nonnull final BlockPos blockPos) {
final TileEntity tileEntity = blockAccess.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityForceField) {
return ((TileEntityForceField) tileEntity).getForceFieldSetup();
try {
return ((TileEntityForceField) tileEntity).getForceFieldSetup();
} catch (final Exception exception) {
if (Commons.throttleMe("BlockForceField.getForceFieldSetup")) {
WarpDrive.logger.error(String.format("Exception trying to get force field setup %s",
Commons.format(blockAccess, blockPos) ));
exception.printStackTrace();
}
}
}
return null;
}
@ -390,7 +397,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
if (tileEntityForceFieldProjector != null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityForceField) {
((TileEntityForceField) tileEntity).setProjector(new VectorI(tileEntityForceFieldProjector));
((TileEntityForceField) tileEntity).setProjector(tileEntityForceFieldProjector.getPos());
}
}

View file

@ -18,10 +18,11 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
public class TileEntityForceField extends TileEntity {
private VectorI vProjector;
private BlockPos blockPosProjector;
// cache parameters used for rendering, force projector check for others
private int cache_beamFrequency;
@ -42,10 +43,10 @@ public class TileEntityForceField extends TileEntity {
super.readFromNBT(tagCompound);
if (tagCompound.hasKey("projector")) {// are we server side and is it a valid force field block?
vProjector = VectorI.createFromNBT(tagCompound.getCompoundTag("projector"));
blockPosProjector = Commons.createBlockPosFromNBT(tagCompound.getCompoundTag("projector"));
cache_beamFrequency = tagCompound.getInteger(IBeamFrequency.BEAM_FREQUENCY_TAG);
} else {
vProjector = null;
blockPosProjector = null;
cache_beamFrequency = -1;
}
if (tagCompound.hasKey("camouflage")) {
@ -77,8 +78,8 @@ public class TileEntityForceField extends TileEntity {
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
tagCompound = super.writeToNBT(tagCompound);
if (vProjector != null) {
tagCompound.setTag("projector", vProjector.writeToNBT(new NBTTagCompound()));
if (blockPosProjector != null) {
tagCompound.setTag("projector", Commons.writeBlockPosToNBT(blockPosProjector, new NBTTagCompound()));
tagCompound.setInteger(IBeamFrequency.BEAM_FREQUENCY_TAG, cache_beamFrequency);
if (cache_blockStateCamouflage != null && cache_blockStateCamouflage.getBlock() != Blocks.AIR) {
final NBTTagCompound nbtCamouflage = new NBTTagCompound();
@ -116,8 +117,8 @@ public class TileEntityForceField extends TileEntity {
readFromNBT(tagCompound);
}
public void setProjector(final VectorI vectorI) {
vProjector = vectorI;
public void setProjector(final BlockPos blockPos) {
blockPosProjector = blockPos.toImmutable();
final ForceFieldSetup forceFieldSetup = getForceFieldSetup();
if (forceFieldSetup != null) {
cache_beamFrequency = forceFieldSetup.beamFrequency;
@ -134,8 +135,8 @@ public class TileEntityForceField extends TileEntity {
}
public TileEntityForceFieldProjector getProjector() {
if (vProjector != null) {
final TileEntity tileEntity = vProjector.getTileEntity(world);
if (blockPosProjector != null) {
final TileEntity tileEntity = world.getTileEntity(blockPosProjector);
if (tileEntity instanceof TileEntityForceFieldProjector) {
final TileEntityForceFieldProjector tileEntityForceFieldProjector = (TileEntityForceFieldProjector) tileEntity;
if (world.isRemote) {

View file

@ -488,7 +488,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
if (tileEntityForceFieldProjector == null) {
// orphan force field, probably from an explosion
// => recover it
tileEntityForceField.setProjector(new VectorI(this));
tileEntityForceField.setProjector(pos);
tileEntityForceField.cache_blockStateCamouflage = forceFieldSetup.getCamouflageBlockState();
// world.setBlockState(vector.getBlockPos(), tileEntityForceField.cache_blockStateCamouflage, 2);
@ -550,7 +550,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
final TileEntity tileEntity = world.getTileEntity(vector.getBlockPos());
if (tileEntity instanceof TileEntityForceField) {
((TileEntityForceField) tileEntity).setProjector(new VectorI(this));
((TileEntityForceField) tileEntity).setProjector(pos);
}
vForceFields.add(vector);
@ -627,7 +627,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
final TileEntity tileEntity = world.getTileEntity(vector.getBlockPos());
if (tileEntity instanceof TileEntityForceField) {
((TileEntityForceField) tileEntity).setProjector(new VectorI(this));
((TileEntityForceField) tileEntity).setProjector(pos);
}
vForceFields.add(vector);