From 05aec3482afe32d4844f66b35929afbc429ee5d1 Mon Sep 17 00:00:00 2001 From: Angeline Date: Tue, 5 May 2020 00:24:15 -0500 Subject: [PATCH] Update to Minecraft Snapshot 20w18a --- gradle.properties | 14 ++--- .../tracker/nearby/NearbyEntityTracker.java | 3 +- .../mods/lithium/common/util/LithiumMath.java | 7 +++ .../ai/nearby_entity_tracking/MixinWorld.java | 4 +- .../task/MixinFindInteractionTargetTask.java | 2 +- .../enum_values/MixinServerChunkManager.java | 20 ------ .../biome/MixinVoronoiBiomeAccessType.java | 10 +-- .../MixinPackedIntegerArray.java | 62 ++++++------------- .../entity/fluid_checks/MixinEntity.java | 5 +- src/main/resources/fabric.mod.json | 2 +- src/main/resources/lithium.mixins.json | 1 - 11 files changed, 44 insertions(+), 86 deletions(-) create mode 100644 src/main/java/me/jellysquid/mods/lithium/common/util/LithiumMath.java delete mode 100644 src/main/java/me/jellysquid/mods/lithium/mixin/alloc/enum_values/MixinServerChunkManager.java diff --git a/gradle.properties b/gradle.properties index 8e40247d0..e975066a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,14 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G - # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=20w15a -yarn_mappings=20w15a+build.4 +minecraft_version=20w18a +yarn_mappings=20w18a+build.14 loader_version=0.8.2+build.194 - # Mod Properties -fabric_asm_version=v2.0 -mod_version = 0.5.0 -maven_group = me.jellysquid.mods -archives_base_name = lithium-fabric - +mod_version=0.5.0 +maven_group=me.jellysquid.mods +archives_base_name=lithium-fabric cf_project_id=360438 cf_project_name=Lithium cf_game_version=1.16-Snapshot diff --git a/src/main/java/me/jellysquid/mods/lithium/common/entity/tracker/nearby/NearbyEntityTracker.java b/src/main/java/me/jellysquid/mods/lithium/common/entity/tracker/nearby/NearbyEntityTracker.java index cbdd3ceae..a31bbb8f0 100644 --- a/src/main/java/me/jellysquid/mods/lithium/common/entity/tracker/nearby/NearbyEntityTracker.java +++ b/src/main/java/me/jellysquid/mods/lithium/common/entity/tracker/nearby/NearbyEntityTracker.java @@ -1,5 +1,6 @@ package me.jellysquid.mods.lithium.common.entity.tracker.nearby; +import me.jellysquid.mods.lithium.common.util.LithiumMath; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.TargetPredicate; import net.minecraft.util.math.Box; @@ -25,7 +26,7 @@ public NearbyEntityTracker(Class clazz, LivingEntity self, float range) { this.clazz = clazz; this.self = self; this.rangeSq = range * range; - this.rangeC = MathHelper.roundUp(MathHelper.ceil(range), 16) >> 4; + this.rangeC = LithiumMath.roundUp(MathHelper.ceil(range), 16) >> 4; } @Override diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/LithiumMath.java b/src/main/java/me/jellysquid/mods/lithium/common/util/LithiumMath.java new file mode 100644 index 000000000..2ea3af711 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/lithium/common/util/LithiumMath.java @@ -0,0 +1,7 @@ +package me.jellysquid.mods.lithium.common.util; + +public class LithiumMath { + public static int roundUp(int num, int interval) { + return ((num + (interval - 1)) / interval) * interval; + } +} diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/MixinWorld.java b/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/MixinWorld.java index f60f4d4f9..12d648de2 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/MixinWorld.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/MixinWorld.java @@ -2,12 +2,12 @@ import me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerEngine; import me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerEngineProvider; +import net.minecraft.class_5269; import net.minecraft.util.profiler.Profiler; import net.minecraft.world.World; import net.minecraft.world.chunk.ChunkManager; import net.minecraft.world.dimension.Dimension; import net.minecraft.world.dimension.DimensionType; -import net.minecraft.world.level.LevelProperties; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -27,7 +27,7 @@ public class MixinWorld implements EntityTrackerEngineProvider { * Initialize the {@link EntityTrackerEngine} which all entities of the world will interact with. */ @Inject(method = "", at = @At("RETURN")) - private void init(LevelProperties levelProperties, DimensionType dimensionType, BiFunction chunkManagerProvider, Supplier profiler, boolean isClient, CallbackInfo ci) { + private void init(class_5269 levelProperties, DimensionType dimensionType, BiFunction chunkManagerProvider, Supplier profiler, boolean isClient, CallbackInfo ci) { this.tracker = new EntityTrackerEngine(); } diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/ai/task/MixinFindInteractionTargetTask.java b/src/main/java/me/jellysquid/mods/lithium/mixin/ai/task/MixinFindInteractionTargetTask.java index 709dada95..e39211672 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/ai/task/MixinFindInteractionTargetTask.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/ai/task/MixinFindInteractionTargetTask.java @@ -79,7 +79,7 @@ public void run(ServerWorld world, LivingEntity self, long time) { if (this.test(entity)) { brain.remember(MemoryModuleType.INTERACTION_TARGET, entity); - brain.remember(MemoryModuleType.LOOK_TARGET, new EntityLookTarget(entity)); + brain.remember(MemoryModuleType.LOOK_TARGET, new EntityLookTarget(entity, true)); break; } diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/alloc/enum_values/MixinServerChunkManager.java b/src/main/java/me/jellysquid/mods/lithium/mixin/alloc/enum_values/MixinServerChunkManager.java deleted file mode 100644 index 1a6733089..000000000 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/alloc/enum_values/MixinServerChunkManager.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.jellysquid.mods.lithium.mixin.alloc.enum_values; - -import net.minecraft.entity.EntityCategory; -import net.minecraft.server.world.ServerChunkManager; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ServerChunkManager.class) -public abstract class MixinServerChunkManager { - private static final EntityCategory[] ENTITY_CATEGORIES = EntityCategory.values(); - - /** - * @reason Avoid cloning enum values - */ - @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityCategory;values()[Lnet/minecraft/entity/EntityCategory;")) - private EntityCategory[] redirectEntityCategoryValues() { - return ENTITY_CATEGORIES; - } -} diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/biome/MixinVoronoiBiomeAccessType.java b/src/main/java/me/jellysquid/mods/lithium/mixin/biome/MixinVoronoiBiomeAccessType.java index 9c7eef015..1581772e2 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/biome/MixinVoronoiBiomeAccessType.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/biome/MixinVoronoiBiomeAccessType.java @@ -35,7 +35,7 @@ public Biome getBiome(long seed, int x, int y, int z, BiomeAccess.Storage storag // This code would normally allocate an array to store each iteration's results, then scan back over it // to determine the closest one. We can avoid the unnecessary step and simply keep track of the nearest one. - double min = Double.POSITIVE_INFINITY; + double minDist = Double.POSITIVE_INFINITY; for (int i = 0; i < 8; i++) { // Block sample positions @@ -72,10 +72,10 @@ public Biome getBiome(long seed, int x, int y, int z, BiomeAccess.Storage storag sZ = z3 - 1.0D; } - double result = calcChance(seed, bX, bY, bZ, sX, sY, sZ); + double dist = calcSquaredDistance(seed, bX, bY, bZ, sX, sY, sZ); - if (min > result) { - min = result; + if (minDist > dist) { + minDist = dist; retX = bX; retY = bY; @@ -96,7 +96,7 @@ private static double distribute(long seed) { } @Shadow - private static double calcChance(long seed, int x, int y, int z, double xFraction, double yFraction, double zFraction) { + private static double calcSquaredDistance(long seed, int x, int y, int z, double xFraction, double yFraction, double zFraction) { throw new UnsupportedOperationException(); } } diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/chunk/serialization/MixinPackedIntegerArray.java b/src/main/java/me/jellysquid/mods/lithium/mixin/chunk/serialization/MixinPackedIntegerArray.java index 4a96ec650..0a5a2f1d0 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/chunk/serialization/MixinPackedIntegerArray.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/chunk/serialization/MixinPackedIntegerArray.java @@ -7,8 +7,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import java.util.Arrays; - /** * Extends {@link PackedIntegerArray} with a special compaction method defined in {@link CompactingPackedIntegerArray}. */ @@ -30,6 +28,10 @@ public class MixinPackedIntegerArray implements CompactingPackedIntegerArray { @Final private long maxValue; + @Shadow + @Final + private int field_24079; + @Override public void compact(Palette srcPalette, Palette dstPalette, short[] out) { if (this.size >= Short.MAX_VALUE) { @@ -42,57 +44,29 @@ public void compact(Palette srcPalette, Palette dstPalette, short[] ou short[] mappings = new short[(int) (this.maxValue + 1)]; - long[] storage = this.storage; - int size = this.size; - int elementBits = this.elementBits; - - int arrayLen = storage.length; - int prevWordIdx = 0; - - long word = storage[0]; - long nextWord = (arrayLen > 1) ? storage[1] : 0L; - - int bits = 0; int idx = 0; - while (idx < size) { - int wordIdx = bits >> 6; - int nextWordIdx = ((bits + elementBits) - 1) >> 6; - - int bitIdx = bits ^ (wordIdx << 6); + for (long word : this.storage) { + long bits = word; - if (wordIdx != prevWordIdx) { - word = nextWord; + for (int elementIdx = 0; elementIdx < this.field_24079; ++elementIdx) { + int value = (int) (bits & this.maxValue); + int remappedId = mappings[value]; - if ((wordIdx + 1) < arrayLen) { - nextWord = storage[wordIdx + 1]; - } else { - nextWord = 0L; + if (remappedId == 0) { + remappedId = dstPalette.getIndex(srcPalette.getByIndex(value)) + 1; + mappings[value] = (short) remappedId; } - prevWordIdx = wordIdx; - } - - int value; - - if (wordIdx == nextWordIdx) { - value = (int) ((word >>> bitIdx) & this.maxValue); - } else { - value = (int) (((word >>> bitIdx) | (nextWord << (64 - bitIdx))) & this.maxValue); - } + out[idx] = (short) (remappedId - 1); + bits >>= this.elementBits; - int remappedId = mappings[value]; + ++idx; - if (remappedId == 0) { - remappedId = dstPalette.getIndex(srcPalette.getByIndex(value)) + 1; - - mappings[value] = (short) remappedId; + if (idx >= this.size) { + return; + } } - - out[idx] = (short) (remappedId - 1); - - bits += elementBits; - idx++; } } } diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/entity/fluid_checks/MixinEntity.java b/src/main/java/me/jellysquid/mods/lithium/mixin/entity/fluid_checks/MixinEntity.java index 15dd86470..b677a9005 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/entity/fluid_checks/MixinEntity.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/entity/fluid_checks/MixinEntity.java @@ -1,5 +1,6 @@ package me.jellysquid.mods.lithium.mixin.entity.fluid_checks; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; @@ -50,7 +51,7 @@ public abstract class MixinEntity { public abstract void setVelocity(Vec3d velocity); @Shadow - protected double waterHeight; + protected Object2DoubleMap> fluidHeight; private static final ObjectArrayList> DEFAULT_FLUID_TAGS = new ObjectArrayList<>(); @@ -107,7 +108,7 @@ private void preUpdateMovementInFluid(Tag tag, double d, CallbackInfoRetu // [VanillaCopy] // The value of the waterHeight field is *always* that of the last movement check through fluid. This is a // bug from vanilla and must be maintained. - this.waterHeight = info.height; + this.fluidHeight.put(tag, info.height); // Regardless of the entity actually being pushed by the fluid, we must indicate that it did collide with it cir.setReturnValue(true); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6418d7f20..72c0b13d2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,6 +25,6 @@ "accessWidener": "lithium.accesswidener", "depends": { "fabricloader": ">=0.8.0", - "minecraft": "1.16-alpha.20.15.a" + "minecraft": "1.16-alpha.20.18.a" } } diff --git a/src/main/resources/lithium.mixins.json b/src/main/resources/lithium.mixins.json index e1fe0a3ab..e969125f1 100644 --- a/src/main/resources/lithium.mixins.json +++ b/src/main/resources/lithium.mixins.json @@ -32,7 +32,6 @@ "alloc.enum_values.MixinLivingEntity", "alloc.enum_values.MixinPistonBlock", "alloc.enum_values.MixinPistonHandler", - "alloc.enum_values.MixinServerChunkManager", "biome.MixinVoronoiBiomeAccessType", "block.flatten_states.MixinAbstractBlockState", "block.flatten_states.MixinFluidStateImpl",