Skip to content

Commit

Permalink
Some bug fixes
Browse files Browse the repository at this point in the history
- Fixed shields not working
- Fixed crashes when lithium was not present
- Improved compatibility with Vulkanmod
- Merged some Random optimizations
- Removed useless Random optimizations
  • Loading branch information
QPCrummer committed Jul 7, 2024
1 parent bb4beea commit 6ed59b5
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 84 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.15.11

# Mod Properties
mod_version = 0.0.1-dev.3
mod_version = 0.0.1-dev.4
maven_group = com.github.tatercertified
archives_base_name = potatoptimize

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.github.tatercertified.potatoptimize.mixin.fastmath.rounding;

import com.github.tatercertified.potatoptimize.utils.math.FasterMathUtil;
import com.moulberry.mixinconstraints.annotations.IfModAbsent;
import net.minecraft.client.render.model.BakedQuadFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@IfModAbsent(value = "vulkanmod")
@Mixin(BakedQuadFactory.class)
public class FastRoundingQuadsMixin {
@Redirect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Vec3d.class)
public class FastMathVec3DMixin {
Expand Down Expand Up @@ -37,12 +34,4 @@ public Vec3d normalize() {
}
return cachedNormalized;
}

// TODO Figure out why I did this...
@Inject(method = "relativize", at = @At("HEAD"))
private void optimizedRelativize(Vec3d vec, CallbackInfoReturnable<Vec3d> cir) {
this.x -= vec.x;
this.y -= vec.y;
this.z -= vec.z;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.tatercertified.potatoptimize.mixin.random.generators;

import com.github.tatercertified.potatoptimize.Potatoptimize;
import com.github.tatercertified.potatoptimize.utils.random.SplittableRandomImpl;
import com.github.tatercertified.potatoptimize.utils.random.ThreadLocalRandomImpl;
import com.github.tatercertified.potatoptimize.utils.random.XorShiftRandomImpl;
import com.moulberry.mixinconstraints.annotations.IfModAbsent;
import net.minecraft.util.math.random.ChunkRandom;
import net.minecraft.util.math.random.Random;
Expand All @@ -25,7 +25,7 @@ private void changeRandom(Random baseRandom, CallbackInfo ci) {
if (!Potatoptimize.isUnsafeRandomEnabled) {
this.baseRandom = new ThreadLocalRandomImpl();
} else {
this.baseRandom = new SplittableRandomImpl();
this.baseRandom = new XorShiftRandomImpl();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package com.github.tatercertified.potatoptimize.mixin.random.generators;

import com.github.tatercertified.potatoptimize.utils.random.ThreadLocalRandomImpl;
import com.github.tatercertified.potatoptimize.utils.random.XorShiftRandomImpl;
import com.moulberry.mixinconstraints.annotations.IfModAbsent;
import net.minecraft.util.math.random.GaussianGenerator;
import net.minecraft.util.math.random.Random;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;

@IfModAbsent(value = "faster-random")
@Mixin(GaussianGenerator.class)
public class GaussianGeneratorMixin {
@Final @Shadow @Mutable
public final Random baseRandom = new ThreadLocalRandomImpl();

@Shadow private boolean hasNextGaussian;

@Shadow private double nextNextGaussian;

@Mutable @Shadow @Final public Random baseRandom;

@Redirect(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/util/math/random/GaussianGenerator;baseRandom:Lnet/minecraft/util/math/random/Random;"))
private void redirectRandomAssignment(GaussianGenerator instance, Random value) {
this.baseRandom = new XorShiftRandomImpl();
}

/**
* @author QPCrummer
* @reason Faster Gaussian Implementation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tatercertified.potatoptimize.mixin.random.generators;

import com.github.tatercertified.potatoptimize.utils.random.ThreadLocalRandomImpl;
import com.github.tatercertified.potatoptimize.utils.random.XorShiftRandomImpl;
import io.netty.util.internal.ThreadLocalRandom;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.math.random.RandomSeed;
Expand Down Expand Up @@ -30,13 +31,11 @@ static Random createLocal() {

/**
* @author QPCrummer
* @reason Use my implementation of ThreadLocalRandom
*
* This has been removed for now as it causes issues with chunk rebuilding!
*
* @reason Use my implementation of XorShift
*/
@Overwrite
static Random create(long seed) {
return new ThreadLocalRandomImpl(seed);
return new XorShiftRandomImpl((int) seed);
}
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.spongepowered.asm.mixin.*;
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.CallbackInfoReturnable;

import java.util.UUID;
Expand All @@ -16,9 +15,7 @@
@Mixin(MathHelper.class)
public class RandomMathHelperMixin {

//TODO Determine the impact of having RANDOM Shadowed and not final
@Unique
private static Random RANDOM = new ThreadLocalRandomImpl();
@Shadow @Final private static Random RANDOM;

@Inject(method = "nextGaussian", at = @At("HEAD"), cancellable = true)
private static void optimizedGaussian(Random random, float mean, float deviation, CallbackInfoReturnable<Float> cir) {
Expand Down Expand Up @@ -54,9 +51,4 @@ private static void optimizedNextFloat(Random random, float min, float max, Call
private static void optimizedNextDouble(Random random, double min, double max, CallbackInfoReturnable<Double> cir) {
cir.setReturnValue(((ThreadLocalRandomImpl)RANDOM).nextDouble(min, max));
}

@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;createThreadSafe()Lnet/minecraft/util/math/random/Random;", shift = At.Shift.AFTER))
private static void reassignRandom(CallbackInfo ci) {
RANDOM = new ThreadLocalRandomImpl();
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
package com.github.tatercertified.potatoptimize.mixin.random.world;

import com.github.tatercertified.potatoptimize.utils.random.ThreadLocalRandomImpl;
import com.github.tatercertified.potatoptimize.utils.random.XorShiftRandomImpl;
import com.moulberry.mixinconstraints.annotations.IfModAbsent;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@IfModAbsent(value = "faster-random", aliases = {"c2me-fixes-worldgen-threading-issues"})
@Mixin(value = World.class)
public class RandomWorldMixin {
@Shadow @Final public Random random;

@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;create()Lnet/minecraft/util/math/random/Random;"))
private Random redirectRandomCreation() {
return new XorShiftRandomImpl();
}

@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;createThreadSafe()Lnet/minecraft/util/math/random/Random;"))
private Random redirectThreadSafeRandomCreation() {
return new ThreadLocalRandomImpl();
}

@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt()I"))
private int redirectRandomNextInt(Random instance) {
return this.random.nextInt();
return ThreadLocalRandomImpl.INSTANCE.nextInt();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ mixin.memory.memory_reserve = false
mixin.memory.reduce_alloc = true
mixin.networking.block_breaking = true
mixin.random.creation = true
mixin.random.entity = true
mixin.random.generators = true
mixin.random.math = true
mixin.random.unsafe = false
Expand All @@ -50,7 +49,6 @@ mixin.threading.explosions = false
mixin.unstable.entity_ticking = false
mixin.unstable.explosion_packets = false
mixin.unstable.explosion_throttle = false
mixin.unstable.reduce_random = false
mixin.unstable.sound = false
mixin.unstream.nearest_item = true
mixin.unstream.pathfinding = true
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/potatoptimize.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"networking.block_breaking.CacheBlockBreakPacketMixin",
"random.creation.QueryResponseHandlerMixin",
"random.creation.ServerPlayerEntityRandomMixin",
"random.entity.RandomEntityMixin",
"random.generators.ChunkRandomMixin",
"random.generators.GaussianGeneratorMixin",
"random.generators.RandomMixin",
Expand All @@ -96,7 +95,6 @@
"unstable.entity_ticking.EntityServerThreadingMixin",
"unstable.explosion_packets.ExplosionNetworkingMixin",
"unstable.explosion_throttle.TntEntityThrottleMixin",
"unstable.reduce_random.RandomCreationMixin",
"unstable.sound.SoundMixin",
"unstream.nearest_item.NearestItemSensorMixin",
"unstream.nearest_item.NearestPlayersSensorMixin",
Expand Down

0 comments on commit 6ed59b5

Please sign in to comment.