forked from CaffeineMC/lithium
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/me/jellysquid/mods/lithium/common/entity/PassengerCachingEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package me.jellysquid.mods.lithium.common.entity; | ||
|
||
public interface PassengerCachingEntity { | ||
|
||
boolean lithium$isPassengerListDirty(); | ||
|
||
void lithium$setPassengerListDirty(boolean dirty); | ||
|
||
void lithium$setPassengerListDirtyRecursive(boolean dirty); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...in/java/me/jellysquid/mods/lithium/mixin/entity/cache_max_track_distance/EntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.jellysquid.mods.lithium.mixin.entity.cache_max_track_distance; | ||
|
||
import me.jellysquid.mods.lithium.common.entity.PassengerCachingEntity; | ||
import net.minecraft.entity.Entity; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Entity.class) | ||
public abstract class EntityMixin implements PassengerCachingEntity { | ||
@Shadow | ||
private @Nullable Entity vehicle; | ||
@Unique | ||
private boolean isPassengerListDirty = true; | ||
|
||
@Override | ||
public boolean lithium$isPassengerListDirty() { | ||
return this.isPassengerListDirty; | ||
} | ||
|
||
@Override | ||
public void lithium$setPassengerListDirty(boolean dirty) { | ||
this.isPassengerListDirty = dirty; | ||
} | ||
|
||
@Override | ||
public void lithium$setPassengerListDirtyRecursive(boolean dirty) { | ||
this.isPassengerListDirty = true; | ||
if (this.vehicle != null) { | ||
((PassengerCachingEntity) this.vehicle).lithium$setPassengerListDirtyRecursive(dirty); | ||
} | ||
} | ||
|
||
@Inject(method = {"addPassenger", "removePassenger"}, at = @At("TAIL")) | ||
private void lithium$markPassengerListDirty(Entity passenger, CallbackInfo ci) { | ||
lithium$setPassengerListDirtyRecursive(true); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...m/mixin/entity/cache_max_track_distance/ServerChunkLoadingManager$EntityTrackerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package me.jellysquid.mods.lithium.mixin.entity.cache_max_track_distance; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import me.jellysquid.mods.lithium.common.entity.PassengerCachingEntity; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.server.world.ServerChunkLoadingManager; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(ServerChunkLoadingManager.EntityTracker.class) | ||
public abstract class ServerChunkLoadingManager$EntityTrackerMixin { | ||
|
||
@Shadow | ||
@Final | ||
public Entity entity; | ||
|
||
@Unique | ||
private int cachedMaxTrackingDistance; | ||
|
||
@WrapOperation(method = "updateTrackedStatus(Lnet/minecraft/server/network/ServerPlayerEntity;)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/server/world/ServerChunkLoadingManager$EntityTracker;getMaxTrackDistance()I" | ||
) | ||
) | ||
private int cacheMaxTrackDistance(ServerChunkLoadingManager.EntityTracker instance, Operation<Integer> original) { | ||
if (((PassengerCachingEntity) this.entity).lithium$isPassengerListDirty()) { | ||
this.cachedMaxTrackingDistance = original.call(instance); | ||
((PassengerCachingEntity) this.entity).lithium$setPassengerListDirty(false); | ||
} | ||
return this.cachedMaxTrackingDistance; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...n/java/me/jellysquid/mods/lithium/mixin/entity/cache_max_track_distance/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@MixinConfigOption(description = "Caches the max tracking distance of entities with their passengers") | ||
package me.jellysquid.mods.lithium.mixin.entity.cache_max_track_distance; | ||
|
||
import net.caffeinemc.gradle.MixinConfigOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters