Skip to content

Commit 36142c0

Browse files
committed
Fix optimizeEntityTicking
* allow entity despawns * don't optimize any ticking on client
1 parent 575e790 commit 36142c0

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

dependencies.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Add your dependencies here
22

33
dependencies {
4-
compileOnly("it.unimi.dsi:fastutil:8.5.8")
4+
compile("it.unimi.dsi:fastutil:8.5.8")
55
// Provides deobf support like in FG2
66
compileOnly('com.github.GTNewHorizons:CodeChickenLib:1.1.5.3:dev')
77
compileOnly('com.github.GTNewHorizons:CodeChickenCore:1.1.3:dev')
@@ -38,4 +38,5 @@ dependencies {
3838
compileOnly(deobfMaven(curseMaven, "curse.maven:extrautils-225561:2264383"))
3939
compileOnly(deobfMaven(curseMaven, "curse.maven:dynamiclights-227874:2337326"))
4040
compileOnly(deobfMaven(curseMaven, "curse.maven:divinerpg-363543:2918948"))
41+
runtimeOnly(deobfMaven(curseMaven, "curse.maven:xaerosminimap-263420:3876755"))
4142
}

src/main/java/org/embeddedt/archaicfix/asm/Mixin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public enum Mixin implements IMixin {
1616
// COMMON MIXINS
1717
common_chickenchunks_MixinPlayerChunkViewerManager(Side.COMMON, require(TargetedMod.CHICKENCHUNKS), "chickenchunks.MixinPlayerChunkViewerManager"),
18+
common_core_AccessorEntityLiving(Side.COMMON, always(), "core.AccessorEntityLiving"),
1819
common_core_MixinEntityPlayerMP(Side.COMMON, always(), "core.MixinEntityPlayerMP"),
1920
common_core_MixinWorldServer(Side.COMMON, always(), "core.MixinWorldServer"),
2021
common_core_MixinMapGenStructure(Side.COMMON, always(), "core.MixinMapGenStructure"),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.embeddedt.archaicfix.mixins.common.core;
2+
3+
import net.minecraft.entity.EntityLiving;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Invoker;
6+
7+
@Mixin(EntityLiving.class)
8+
public interface AccessorEntityLiving {
9+
@Invoker
10+
public boolean invokeCanDespawn();
11+
@Invoker
12+
public void invokeDespawnEntity();
13+
}

src/main/java/org/embeddedt/archaicfix/mixins/common/core/MixinWorld.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.google.common.collect.ImmutableSet;
44
import cpw.mods.fml.common.FMLCommonHandler;
5+
import cpw.mods.fml.common.ObfuscationReflectionHelper;
56
import it.unimi.dsi.fastutil.longs.LongCollection;
67
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
78
import net.minecraft.entity.Entity;
89
import net.minecraft.entity.EntityList;
10+
import net.minecraft.entity.EntityLiving;
911
import net.minecraft.entity.EntityLivingBase;
1012
import net.minecraft.entity.player.EntityPlayer;
1113
import net.minecraft.tileentity.TileEntity;
@@ -98,20 +100,24 @@ else if (difficulty == EnumDifficulty.HARD)
98100
private void skipUpdateIfOptimizing(Entity entity, boolean force, CallbackInfo ci, int chunkX, int chunkZ, boolean isInForcedChunk) {
99101
if(!ArchaicConfig.optimizeEntityTicking)
100102
return;
103+
if (isRemote || isInForcedChunk || !(entity instanceof EntityLivingBase) || entity instanceof EntityPlayer || !entity.addedToChunk) {
104+
return;
105+
}
101106
if(entityOptimizationIgnoreSet == null)
102107
entityOptimizationIgnoreSet = ImmutableSet.copyOf(ArchaicConfig.optimizeEntityTickingIgnoreList);
103108
if(entityOptimizationIgnoreSet.contains(EntityList.getEntityString(entity)))
104109
return;
105-
if (isInForcedChunk || !(entity instanceof EntityLivingBase) || entity instanceof EntityPlayer) {
106-
return;
107-
}
108110
double finalDist = Double.MAX_VALUE;
109111
for(EntityPlayer player : (List<EntityPlayer>)entity.worldObj.playerEntities) {
110112
finalDist = Math.min(finalDist, player.getDistanceSq(entity.posX, entity.posY, entity.posZ));
111113
if(finalDist <= ArchaicConfig.optimizeEntityTickingDistance)
112114
break;
113115
}
114116
if(((EntityLivingBase)entity).deathTime <= 0 && finalDist > ArchaicConfig.optimizeEntityTickingDistance) {
117+
if(entity instanceof EntityLiving && ((AccessorEntityLiving)entity).invokeCanDespawn()) {
118+
/* Despawn even if outside the ticking range */
119+
((AccessorEntityLiving)entity).invokeDespawnEntity();
120+
}
115121
ci.cancel();
116122
}
117123
}

0 commit comments

Comments
 (0)