Skip to content

Commit c425c71

Browse files
committed
Player RNG simulation improvements
1 parent fb55af0 commit c425c71

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

src/main/java/net/earthcomputer/clientcommands/TempRules.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public static void setEnchantingPrediction(boolean enchantingPrediction) {
3131
EnchantmentCracker.resetCracker();
3232
}
3333

34+
@Rule
35+
public static boolean playerRNGMaintenance = true;
36+
3437
public static Object get(String name) {
3538
Field field = rules.get(name);
3639
if (field == null)

src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.minecraft.enchantment.InfoEnchantment;
2828
import net.minecraft.entity.LivingEntity;
2929
import net.minecraft.entity.player.PlayerEntity;
30+
import net.minecraft.item.ArmorItem;
3031
import net.minecraft.item.Items;
3132
import net.minecraft.server.network.ServerPlayerEntity;
3233
import net.minecraft.server.network.packet.PlayerMoveC2SPacket;
@@ -117,6 +118,9 @@ public static void resetCracker(String reason) {
117118
public static void onDropItem() {
118119
if (expectedThrows > 0)
119120
expectedThrows--;
121+
else if (canMaintainPlayerRNG())
122+
for (int i = 0; i < 4; i++)
123+
playerRand.nextInt();
120124
else
121125
resetCracker("dropItem");
122126
}
@@ -162,22 +166,37 @@ public static void onGiveCommand() {
162166
}
163167

164168
public static void onAnvilUse() {
165-
resetCracker("anvil");
169+
if (canMaintainPlayerRNG())
170+
playerRand.nextInt();
171+
else
172+
resetCracker("anvil");
166173
}
167174

168175
public static void onFrostWalker() {
169176
resetCracker("frostWalker");
170177
}
171178

172-
public static void onBaseOfArthropods() {
173-
resetCracker("baneOfArthropods");
179+
public static void onBaneOfArthropods() {
180+
if (canMaintainPlayerRNG())
181+
playerRand.nextInt();
182+
else
183+
resetCracker("baneOfArthropods");
174184
}
175185

176-
public static void onUnbreaking(int amount, int unbreakingLevel) {
177-
resetCracker("unbreaking");
186+
public static void onRecreatePlayer() {
187+
resetCracker("recreated");
178188
}
179189

180-
public static void onUnbreakingUncertain(int minAmount, int maxAmount, int unbreakingLevel) {
190+
public static void onUnbreaking(ItemStack stack, int amount, int unbreakingLevel) {
191+
if (canMaintainPlayerRNG())
192+
for (int i = 0; i < amount; i++)
193+
if (!(stack.getItem() instanceof ArmorItem) || playerRand.nextFloat() >= 0.6)
194+
playerRand.nextInt(unbreakingLevel + 1);
195+
else
196+
resetCracker("unbreaking");
197+
}
198+
199+
public static void onUnbreakingUncertain(ItemStack stack, int minAmount, int maxAmount, int unbreakingLevel) {
181200
resetCracker("unbreaking");
182201
}
183202

@@ -187,7 +206,7 @@ public static void onItemDamage(int amount, LivingEntity holder, ItemStack stack
187206
if (amount > 0) {
188207
int unbreakingLevel = EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack);
189208
if (unbreakingLevel > 0)
190-
onUnbreaking(amount, unbreakingLevel);
209+
onUnbreaking(stack, amount, unbreakingLevel);
191210
}
192211
}
193212
}
@@ -199,12 +218,16 @@ public static void onItemDamageUncertain(int minAmount, int maxAmount, LivingEnt
199218
if (maxAmount > 0) {
200219
int unbreakingLevel = EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack);
201220
if (unbreakingLevel > 0)
202-
onUnbreakingUncertain(minAmount, maxAmount, unbreakingLevel);
221+
onUnbreakingUncertain(stack, minAmount, maxAmount, unbreakingLevel);
203222
}
204223
}
205224
}
206225
}
207226

227+
private static boolean canMaintainPlayerRNG() {
228+
return TempRules.playerRNGMaintenance && TempRules.enchCrackState == EnumCrackState.CRACKED;
229+
}
230+
208231
// RENDERING
209232
/*
210233
* This section is in charge of rendering the overlay on the enchantment GUI

src/main/java/net/earthcomputer/clientcommands/mixin/MixinDamageEnchantment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class MixinDamageEnchantment {
1616
@Inject(method = "onTargetDamaged", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I", remap = false))
1717
public void onAttackArthropod(LivingEntity attacker, Entity attacked, int level, CallbackInfo ci) {
1818
if (attacker instanceof ClientPlayerEntity) {
19-
EnchantmentCracker.onBaseOfArthropods();
19+
EnchantmentCracker.onBaneOfArthropods();
2020
}
2121
}
2222

src/main/java/net/earthcomputer/clientcommands/mixin/MixinMinecraftClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.earthcomputer.clientcommands.mixin;
22

33
import net.earthcomputer.clientcommands.GuiBlocker;
4+
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
45
import net.earthcomputer.clientcommands.features.RenderSettings;
56
import net.earthcomputer.clientcommands.TempRules;
67
import net.earthcomputer.clientcommands.task.TaskManager;
@@ -22,6 +23,7 @@ public void onHandleInputEvents(CallbackInfo ci) {
2223

2324
@Inject(method = "setWorld", at = @At("HEAD"))
2425
public void onSetWorld(CallbackInfo ci) {
26+
EnchantmentCracker.onRecreatePlayer();
2527
TaskManager.onWorldUnload();
2628
}
2729

src/main/resources/assets/clientcommands/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"enchCrack.reset.frostWalker": "Frost Walker Used",
7575
"enchCrack.reset.entityCramming": "Entity Cramming",
7676
"enchCrack.reset.enchanting": "Enchanted Item",
77+
"enchCrack.reset.recreated": "Player Recreated",
7778

7879
"enchCrack.xpSeed.one": "XP Seed: %08X",
7980
"enchCrack.xpSeed.many": "Possible XP seeds: %d",

0 commit comments

Comments
 (0)