Merge 1.20 into 1.20.4

This commit is contained in:
embeddedt 2024-03-30 18:12:30 -04:00
commit 73f706164f
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 36 additions and 26 deletions

View File

@ -0,0 +1,36 @@
package org.embeddedt.modernfix.common.mixin.perf.ticking_chunk_alloc;
import net.minecraft.world.level.chunk.ChunkAccess;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Collections;
import java.util.Map;
@Mixin(value = ChunkAccess.class, priority = 800)
public class ChunkAccessMixin {
@Shadow @Final private Map<?, ?> structuresRefences;
private Map<?, ?> mfix$structureRefsView;
/**
* @author embeddedt
* @reason Cache returned map view to avoid allocations, return empty map when possible
* so that iterator() calls don't allocate
* <p></p>
* Note: technically, this introduces an API change, as the return value may no longer be a live view
* of the structure references of the chunk. It's unlikely this will affect anything in practice.
*/
@Overwrite
public Map<?, ?> getAllReferences() {
if(this.structuresRefences.isEmpty()) {
return Collections.emptyMap();
}
Map<?, ?> view = this.mfix$structureRefsView;
if(view == null) {
this.mfix$structureRefsView = view = Collections.unmodifiableMap(this.structuresRefences);
}
return view;
}
}

View File

@ -1,26 +0,0 @@
package org.embeddedt.modernfix.common.mixin.perf.ticking_chunk_alloc;
import net.minecraft.world.level.chunk.ChunkGenerator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
@Mixin(ChunkGenerator.class)
public class ChunkGeneratorMixin {
/**
* @author embeddedt
* @reason Avoid allocation if the chunk contains no structures
*/
@Redirect(method = "getMobsAt", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;"), require = 0)
private Set<?> avoidSetAllocation(Map<?, ?> instance) {
if(instance.isEmpty()) {
return Collections.emptySet();
} else {
return instance.entrySet();
}
}
}