diff --git a/src/main/java/carpetfixes/mixins/optimizations/ChunkTicketManager_optimizationMixin.java b/src/main/java/carpetfixes/mixins/optimizations/ChunkTicketManager_optimizationMixin.java deleted file mode 100644 index 6dba435..0000000 --- a/src/main/java/carpetfixes/mixins/optimizations/ChunkTicketManager_optimizationMixin.java +++ /dev/null @@ -1,141 +0,0 @@ -package carpetfixes.mixins.optimizations; - -import carpetfixes.CFSettings; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectIterator; -import net.minecraft.server.world.ChunkTicket; -import net.minecraft.server.world.ChunkTicketManager; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; -import net.minecraft.util.collection.SortedArraySet; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.function.Predicate; - -/** - * Optimization that did not make it into Lithium, to change the way chunk tickets are handled - */ - -@Mixin(ChunkTicketManager.class) -public abstract class ChunkTicketManager_optimizationMixin { - - @Shadow - private long age; - - @Shadow - @Final - Long2ObjectOpenHashMap>> ticketsByPosition; - - @Shadow - @Final - private ChunkTicketManager.TicketDistanceLevelPropagator distanceFromTicketTracker; - - @Shadow - private static int getLevel(SortedArraySet> sortedArraySet) { - throw new UnsupportedOperationException(); - } - - private final Long2ObjectOpenHashMap>> positionWithExpiringTicket = - new Long2ObjectOpenHashMap<>(); - - private static boolean canAnyExpire(SortedArraySet> tickets) { - for (ChunkTicket ticket : tickets) { - if (canExpire(ticket)) return true; - } - return false; - } - - private static boolean canExpire(ChunkTicket ticket) { - return ticket.getType().getExpiryTicks() != 0; - } - - @Shadow - public abstract boolean tick(ThreadedAnvilChunkStorage threadedAnvilChunkStorage); - - /** - * @reason Remove lambda allocation in every iteration - * @author JellySquid - * Mark all locations that have tickets that can expire as such. Allows iterating only over locations with - * tickets that can expire when purging expired tickets. - */ - @SuppressWarnings("all") - @Inject( - method = "addTicket(JLnet/minecraft/server/world/ChunkTicket;)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/util/collection/SortedArraySet;" + - "addAndGet(Ljava/lang/Object;)Ljava/lang/Object;" - ), - locals = LocalCapture.CAPTURE_FAILHARD - ) - private void registerExpiringTicket(long position, ChunkTicket ticket, CallbackInfo ci, - SortedArraySet> ticketsAtPos, int i) { - if (CFSettings.optimizedTicketManager && canExpire(ticket)) { - this.positionWithExpiringTicket.put(position, ticketsAtPos); - } - } - - @Inject( - method = "removeTicket(JLnet/minecraft/server/world/ChunkTicket;)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/server/world/ChunkTicketManager$TicketDistanceLevelPropagator;" + - "updateLevel(JIZ)V" - ) - ) - private void unregisterExpiringTicket(long pos, ChunkTicket ticket, CallbackInfo ci) { - if (CFSettings.optimizedTicketManager && canExpire(ticket)) { - SortedArraySet> ticketsAtPos = this.positionWithExpiringTicket.get(pos); - if (!canAnyExpire(ticketsAtPos)) this.positionWithExpiringTicket.remove(pos); - } - } - - /** - * @reason Remove lambda allocation in every iteration, only iterate over ticks that can expire - * @author JellySquid, 2No2Name - */ - @Inject( - method = "purge()V", - at = @At("HEAD"), - cancellable = true - ) - public void purge(CallbackInfo ci) { - if (CFSettings.optimizedTicketManager) { - ++this.age; - - ObjectIterator>>> iterator = - this.ticketsByPosition.long2ObjectEntrySet().fastIterator(); - Predicate> predicate = (chunkTicket) -> chunkTicket.isExpired(this.age); - this.positionWithExpiringTicket.long2ObjectEntrySet().fastIterator(); - Predicate> isExpiredPredicate = (chunkTicket) -> chunkTicket.isExpired(this.age); - - while (iterator.hasNext()) { - Long2ObjectMap.Entry>> entry = iterator.next(); - SortedArraySet> value = entry.getValue(); - SortedArraySet> ticketsAtPos = entry.getValue(); - long pos = entry.getLongKey(); - - if (value.removeIf(predicate)) { - this.distanceFromTicketTracker.updateLevel(entry.getLongKey(), getLevel(entry.getValue()), false); - } - if (ticketsAtPos.removeIf(isExpiredPredicate)) { - assert this.ticketsByPosition.get(pos) == ticketsAtPos; - this.distanceFromTicketTracker.updateLevel(pos, getLevel(ticketsAtPos), false); - - if (value.isEmpty()) { - iterator.remove(); - if (!canAnyExpire(ticketsAtPos)) iterator.remove(); - if (ticketsAtPos.isEmpty()) this.ticketsByPosition.remove(pos, ticketsAtPos); - } - } - } - ci.cancel(); - } - } -} diff --git a/src/main/resources/carpet-fixes.mixins.json b/src/main/resources/carpet-fixes.mixins.json index ec4f7e6..99b4062 100644 --- a/src/main/resources/carpet-fixes.mixins.json +++ b/src/main/resources/carpet-fixes.mixins.json @@ -247,7 +247,6 @@ "itemFixes.MusicDiscItem_worldEventMixin", "itemFixes.PickaxeItem_blackstoneButtonMixin", "optimizations.BiomeAccess_predictionMixin", - "optimizations.ChunkTicketManager_optimizationMixin", "optimizations.PoweredRailBlock_fasterMixin", "optimizations.RecipeManager_fasterMixin", "optimizations.SheepEntity_childColorMixin",