Skip to content

Commit 259516b

Browse files
authored
Faster markDirty implementation for saving (GregTechCEu#2016)
1 parent 7ac46eb commit 259516b

File tree

11 files changed

+25
-91
lines changed

11 files changed

+25
-91
lines changed

src/main/java/gregtech/api/block/machines/BlockMachine.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,6 @@ public void neighborChanged(@Nonnull IBlockState state, @Nonnull World worldIn,
367367
}
368368
}
369369

370-
@Override
371-
public int getComparatorInputOverride(@Nonnull IBlockState blockState, @Nonnull World worldIn, @Nonnull BlockPos pos) {
372-
MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
373-
return metaTileEntity == null ? 0 : metaTileEntity.getComparatorValue();
374-
}
375-
376370
protected final ThreadLocal<MetaTileEntity> tileEntities = new ThreadLocal<>();
377371

378372
@Override
@@ -382,11 +376,6 @@ public void harvestBlock(@Nonnull World worldIn, @Nonnull EntityPlayer player, @
382376
tileEntities.set(null);
383377
}
384378

385-
@Override
386-
public boolean hasComparatorInputOverride(@Nonnull IBlockState state) {
387-
return true;
388-
}
389-
390379
@Nullable
391380
@Override
392381
public TileEntity createNewTileEntity(@Nullable World worldIn, int meta) {

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import net.minecraftforge.items.ItemStackHandler;
7575
import org.apache.commons.lang3.ArrayUtils;
7676
import org.apache.commons.lang3.tuple.Pair;
77+
import org.jetbrains.annotations.ApiStatus;
7778

7879
import javax.annotation.Nonnull;
7980
import javax.annotation.Nullable;
@@ -114,7 +115,6 @@ public abstract class MetaTileEntity implements ICoverable, IVoidable {
114115

115116
private final int[] sidedRedstoneOutput = new int[6];
116117
private final int[] sidedRedstoneInput = new int[6];
117-
private int cachedComparatorValue;
118118
private int cachedLightValue;
119119
protected boolean isFragile = false;
120120

@@ -159,6 +159,7 @@ public BlockPos getPos() {
159159
return holder == null ? null : holder.pos();
160160
}
161161

162+
@Override
162163
public void markDirty() {
163164
if (holder != null) {
164165
holder.markAsDirty();
@@ -668,7 +669,6 @@ public boolean shouldRenderBackSide() {
668669
}
669670

670671
public void onLoad() {
671-
this.cachedComparatorValue = getActualComparatorValue();
672672
for (EnumFacing side : EnumFacing.VALUES) {
673673
this.sidedRedstoneInput[side.getIndex()] = GTUtility.getRedstonePower(getWorld(), getPos(), side);
674674
}
@@ -729,6 +729,11 @@ public void updateInputRedstoneSignals() {
729729
}
730730
}
731731

732+
/**
733+
* @deprecated Will be removed in 2.9. Comparators no longer supported for MetaTileEntities, as cover are interactions favored.
734+
*/
735+
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
736+
@Deprecated
732737
public int getActualComparatorValue() {
733738
return 0;
734739
}
@@ -737,24 +742,19 @@ public int getActualLightValue() {
737742
return 0;
738743
}
739744

745+
/**
746+
* @deprecated Will be removed in 2.9.
747+
*/
748+
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
749+
@Deprecated
740750
public final int getComparatorValue() {
741-
return cachedComparatorValue;
751+
return 0;
742752
}
743753

744754
public final int getLightValue() {
745755
return cachedLightValue;
746756
}
747757

748-
private void updateComparatorValue() {
749-
int newComparatorValue = getActualComparatorValue();
750-
if (cachedComparatorValue != newComparatorValue) {
751-
this.cachedComparatorValue = newComparatorValue;
752-
if (getWorld() != null && !getWorld().isRemote) {
753-
notifyBlockUpdate();
754-
}
755-
}
756-
}
757-
758758
private void updateLightValue() {
759759
int newLightValue = getActualLightValue();
760760
if (cachedLightValue != newLightValue) {
@@ -777,9 +777,6 @@ public void update() {
777777
((ITickable) coverBehavior).update();
778778
}
779779
}
780-
if (getOffsetTimer() % 5 == 0L) {
781-
updateComparatorValue();
782-
}
783780
} else {
784781
updateSound();
785782
}
@@ -1130,7 +1127,6 @@ public final void setOutputRedstoneSignal(EnumFacing side, int strength) {
11301127
this.sidedRedstoneOutput[side.getIndex()] = strength;
11311128
if (getWorld() != null && !getWorld().isRemote && getCoverAtSide(side) == null) {
11321129
notifyBlockUpdate();
1133-
markDirty();
11341130
}
11351131
}
11361132

src/main/java/gregtech/api/metatileentity/MetaTileEntityHolder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,12 @@ public BlockPos pos() {
335335
return getPos();
336336
}
337337

338+
@SuppressWarnings("ConstantConditions") // yes this CAN actually be null
338339
@Override
339340
public void markAsDirty() {
340-
markDirty();
341+
if (getWorld() != null && getPos() != null) {
342+
getWorld().markChunkDirty(getPos(), this);
343+
}
341344
}
342345

343346
@Override

src/main/java/gregtech/api/metatileentity/TieredMetaTileEntity.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.minecraft.client.resources.I18n;
1717
import net.minecraft.item.ItemStack;
1818
import net.minecraft.util.ResourceLocation;
19-
import net.minecraft.util.math.MathHelper;
2019
import net.minecraft.world.World;
2120
import net.minecraftforge.fml.relauncher.Side;
2221
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -47,14 +46,6 @@ protected void reinitializeEnergyContainer() {
4746
tierVoltage * 64L, tierVoltage, getMaxInputOutputAmperage());
4847
}
4948

50-
@Override
51-
public int getActualComparatorValue() {
52-
long energyStored = energyContainer.getEnergyStored();
53-
long energyCapacity = energyContainer.getEnergyCapacity();
54-
float f = energyCapacity == 0L ? 0.0f : energyStored / (energyCapacity * 1.0f);
55-
return MathHelper.floor(f * 14.0f) + (energyStored > 0 ? 1 : 0);
56-
}
57-
5849
@Override
5950
public void onEnergyChanged(IEnergyContainer container, boolean isInitialChange) {
6051
}

src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ public BlockPos getPipePos() {
9898
return getPos();
9999
}
100100

101+
@SuppressWarnings("ConstantConditions") // yes this CAN actually be null
102+
@Override
103+
public void markDirty() {
104+
if (getWorld() != null && getPos() != null) {
105+
getWorld().markChunkDirty(getPos(), this);
106+
}
107+
}
108+
101109
@Override
102110
public PipeCoverableImplementation getCoverableImplementation() {
103111
return coverableImplementation;

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.minecraft.util.EnumFacing;
2525
import net.minecraft.util.EnumHand;
2626
import net.minecraft.util.ResourceLocation;
27-
import net.minecraft.util.math.MathHelper;
2827
import net.minecraft.util.text.TextComponentTranslation;
2928
import net.minecraft.world.World;
3029

@@ -53,14 +52,6 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
5352
return new MetaTileEntityDiode(metaTileEntityId, getTier());
5453
}
5554

56-
@Override
57-
public int getActualComparatorValue() {
58-
long energyStored = energyContainer.getEnergyStored();
59-
long energyCapacity = energyContainer.getEnergyCapacity();
60-
float f = energyCapacity == 0L ? 0.0f : energyStored / (energyCapacity * 1.0f);
61-
return MathHelper.floor(f * 14.0f) + (energyStored > 0 ? 1 : 0);
62-
}
63-
6455
@Override
6556
public NBTTagCompound writeToNBT(NBTTagCompound data) {
6657
super.writeToNBT(data);

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import appeng.api.util.AECableType;
44
import appeng.api.util.AEPartLocation;
55
import appeng.me.helpers.AENetworkProxy;
6-
import codechicken.lib.raytracer.CuboidRayTraceResult;
76
import codechicken.lib.render.CCRenderState;
87
import codechicken.lib.render.pipeline.IVertexOperation;
98
import codechicken.lib.vec.Matrix4;
@@ -23,9 +22,7 @@
2322
import net.minecraft.entity.player.EntityPlayer;
2423
import net.minecraft.item.ItemStack;
2524
import net.minecraft.util.EnumFacing;
26-
import net.minecraft.util.EnumHand;
2725
import net.minecraft.util.ResourceLocation;
28-
import net.minecraft.util.math.MathHelper;
2926
import net.minecraft.world.World;
3027
import net.minecraftforge.fml.common.Loader;
3128
import net.minecraftforge.fml.common.Optional;
@@ -55,14 +52,6 @@ protected void reinitializeEnergyContainer() {
5552
((EnergyContainerHandler) this.energyContainer).setSideOutputCondition(s -> s == getFrontFacing());
5653
}
5754

58-
@Override
59-
public int getActualComparatorValue() {
60-
long energyStored = energyContainer.getEnergyStored();
61-
long energyCapacity = energyContainer.getEnergyCapacity();
62-
float f = energyCapacity == 0L ? 0.0f : energyStored / (energyCapacity * 1.0f);
63-
return MathHelper.floor(f * 14.0f) + (energyStored > 0 ? 1 : 0);
64-
}
65-
6655
@Override
6756
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
6857
super.renderMetaTileEntity(renderState, translation, pipeline);

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCrate.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.minecraft.world.World;
2525
import net.minecraftforge.fml.relauncher.Side;
2626
import net.minecraftforge.fml.relauncher.SideOnly;
27-
import net.minecraftforge.items.ItemHandlerHelper;
2827
import net.minecraftforge.items.ItemStackHandler;
2928
import org.apache.commons.lang3.tuple.Pair;
3029

@@ -71,11 +70,6 @@ protected void initializeInventory() {
7170
this.itemInventory = inventory;
7271
}
7372

74-
@Override
75-
public int getActualComparatorValue() {
76-
return ItemHandlerHelper.calcRedstoneFromInventory(inventory);
77-
}
78-
7973
@Override
8074
public void clearMachineInventory(NonNullList<ItemStack> itemBuffer) {
8175
clearInventory(itemBuffer, inventory);

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityDrum.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import net.minecraft.util.EnumFacing;
3030
import net.minecraft.util.EnumHand;
3131
import net.minecraft.util.ResourceLocation;
32-
import net.minecraft.util.math.MathHelper;
3332
import net.minecraft.util.text.TextComponentTranslation;
3433
import net.minecraft.world.World;
3534
import net.minecraftforge.common.capabilities.ICapabilityProvider;
@@ -74,15 +73,6 @@ public int getLightOpacity() {
7473
return 1;
7574
}
7675

77-
@Override
78-
public int getActualComparatorValue() {
79-
FluidTank fluidTank = this.fluidTank;
80-
int fluidAmount = fluidTank.getFluidAmount();
81-
int maxCapacity = fluidTank.getCapacity();
82-
float f = fluidAmount / (maxCapacity * 1.0f);
83-
return MathHelper.floor(f * 14.0f) + (fluidAmount > 0 ? 1 : 0);
84-
}
85-
8676
@Override
8777
public boolean isOpaqueCube() {
8878
return false;

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import net.minecraft.util.NonNullList;
3636
import net.minecraft.util.ResourceLocation;
3737
import net.minecraft.util.math.AxisAlignedBB;
38-
import net.minecraft.util.math.MathHelper;
3938
import net.minecraft.util.text.ITextComponent;
4039
import net.minecraft.util.text.TextComponentString;
4140
import net.minecraft.util.text.TextComponentTranslation;
@@ -116,12 +115,6 @@ public Pair<TextureAtlasSprite, Integer> getParticleTexture() {
116115
return Pair.of(Textures.VOLTAGE_CASINGS[tier].getParticleSprite(), getPaintingColorForRendering());
117116
}
118117

119-
@Override
120-
public int getActualComparatorValue() {
121-
float f = itemsStoredInside / (maxStoredItems * 1.0f);
122-
return MathHelper.floor(f * 14.0f) + (itemsStoredInside > 0 ? 1 : 0);
123-
}
124-
125118
@Override
126119
public void update() {
127120
super.update();

0 commit comments

Comments
 (0)