Skip to content

Commit 9d874d6

Browse files
committed
[KillTheRNG] Finish MathRandomness
1 parent 8046ff0 commit 9d874d6

7 files changed

Lines changed: 84 additions & 14 deletions

File tree

src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1414
import com.minecrafttas.tasmod.TASmod;
1515
import com.minecrafttas.tasmod.events.EventServer.EventServerTickPost;
16+
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer.SavestateState;
1617

1718
import net.fabricmc.api.EnvType;
1819
import net.fabricmc.api.Environment;
@@ -109,18 +110,18 @@ public void redirectThreadSleep(long msToTick) {
109110

110111
TASmod.gameLoopSchedulerServer.runAllTasks();
111112

112-
// boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.getState() == SavestateState.LOADING;
113-
// if (!stopTaskQueue) {
114-
// synchronized (this.futureTaskQueue) {
115-
// while (!this.futureTaskQueue.isEmpty()) {
116-
// try {
117-
// ((FutureTask<?>) this.futureTaskQueue.poll()).run();
118-
// } catch (Throwable var9) {
119-
// var9.printStackTrace();
120-
// }
121-
// }
122-
// }
123-
// }
113+
boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.getState() == SavestateState.LOADING;
114+
if (!stopTaskQueue) {
115+
synchronized (this.futureTaskQueue) {
116+
while (!this.futureTaskQueue.isEmpty()) {
117+
try {
118+
((FutureTask<?>) this.futureTaskQueue.poll()).run();
119+
} catch (Throwable var9) {
120+
var9.printStackTrace();
121+
}
122+
}
123+
}
124+
}
124125
}
125126

126127
@Environment(EnvType.SERVER)

src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class MixinEntityItem {
1515

1616
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D"))
1717
private double wrap_entityItemInit(Operation<Double> original, World world, double d, double e, double f) {
18-
System.out.println("Test");
1918
return TASmod.mathRandomness.nextDouble();
2019
}
2120
}

src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
import com.minecrafttas.tasmod.TASmod;
99

1010
import net.minecraft.entity.EntityLivingBase;
11+
import net.minecraft.world.World;
1112

1213
@Mixin(EntityLivingBase.class)
1314
public class MixinEntityLivingBase {
1415

16+
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D"))
17+
private double wrap_entityLivingBase(Operation<Double> original, World world) {
18+
return TASmod.mathRandomness.nextDouble();
19+
}
20+
1521
@WrapOperation(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D"))
1622
private double wrap_attackEntityFrom(Operation<Double> original) {
1723
return TASmod.mathRandomness.nextDouble();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.minecrafttas.tasmod.mixin.killtherng.mathrand;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.injection.At;
5+
6+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
7+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
8+
import com.minecrafttas.tasmod.TASmod;
9+
10+
import net.minecraft.entity.EntityLivingBase;
11+
import net.minecraft.entity.item.EntityTNTPrimed;
12+
import net.minecraft.world.World;
13+
14+
@Mixin(EntityTNTPrimed.class)
15+
public class MixinEntityTNTPrimed {
16+
17+
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D"))
18+
private double wrap_entityTNTPrimedInit(Operation<Double> original, World world, double d, double e, double f, EntityLivingBase entityLivingBase) {
19+
return TASmod.mathRandomness.nextDouble();
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.minecrafttas.tasmod.mixin.killtherng.mathrand;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.injection.At;
5+
6+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
7+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
8+
import com.minecrafttas.tasmod.TASmod;
9+
10+
import net.minecraft.entity.item.EntityXPOrb;
11+
import net.minecraft.world.World;
12+
13+
@Mixin(EntityXPOrb.class)
14+
public class MixinEntityXPOrb {
15+
16+
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D"))
17+
private double wrap_entityXPOrb(Operation<Double> original, World world, double d, double e, double f, int i) {
18+
return TASmod.mathRandomness.nextDouble();
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.minecrafttas.tasmod.mixin.killtherng.mathrand;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.injection.At;
5+
6+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
7+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
8+
import com.minecrafttas.tasmod.TASmod;
9+
10+
import net.minecraft.world.WorldEntitySpawner;
11+
import net.minecraft.world.WorldServer;
12+
13+
@Mixin(WorldEntitySpawner.class)
14+
public class MixinWorldEntitySpawner {
15+
16+
@WrapOperation(method = "findChunksForSpawning", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D"))
17+
private double wrap_worldEntitySpawnerFindChunks(Operation<Double> original, WorldServer worldServer, boolean bl, boolean bl2, boolean bl3) {
18+
return TASmod.mathRandomness.nextDouble();
19+
}
20+
}

src/main/resources/tasmod.mixin.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
"killtherng.MixinEntity",
2727
"killtherng.MixinWorld",
2828
"killtherng.mathrand.MixinEntityLivingBase",
29-
"killtherng.mathrand.MixinEntityItem"
29+
"killtherng.mathrand.MixinEntityItem",
30+
"killtherng.mathrand.MixinEntityXPOrb",
31+
"killtherng.mathrand.MixinEntityTNTPrimed",
32+
"killtherng.mathrand.MixinWorldEntitySpawner"
3033

3134
],
3235
"client": [

0 commit comments

Comments
 (0)