Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Villager RNG Manipulation #642

Open
wants to merge 98 commits into
base: fabric
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
3e36064
temp changes
RealRTTV May 29, 2024
1cca6b4
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV May 29, 2024
5552602
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV May 30, 2024
b935782
finally i can hold on to a villager's rng state
RealRTTV May 31, 2024
fe4133a
ok, now that it's been held on to, i can try to predict it, but for s…
RealRTTV May 31, 2024
800fd92
ok now i can crack it, gotta figure out how to
RealRTTV Jun 1, 2024
5fcbf15
ok, now it works
RealRTTV Jun 2, 2024
b5fe87c
whoopsie
RealRTTV Jun 2, 2024
fa0fde5
need to check the ping checking
RealRTTV Jun 2, 2024
406d55a
ping checking might work, idk
RealRTTV Jun 11, 2024
f416f2b
Merge remote-tracking branch 'refs/remotes/upstream/fabric' into vill…
RealRTTV Jun 17, 2024
70aaf2a
yo, check out this broken code
RealRTTV Jun 19, 2024
f047024
Fixes to villager cracking
Earthcomputer Jun 19, 2024
c419414
IT WORKS!! btw i still have villager adjustment shenanigans
RealRTTV Jun 19, 2024
48bf868
Fix two pitch cracking and add three pitch cracking
Gaider10 Jun 19, 2024
2734f64
Add simulation for unhappy no and water splashing sounds
Gaider10 Jun 20, 2024
bff08d1
Merge pull request #1 from Gaider10/villager_rng_cracking
RealRTTV Jun 20, 2024
47e53f2
Add simulation for more actions and add trade cracking for levels abo…
Gaider10 Jun 20, 2024
4910518
Handle ambient sound inside trading gui correctly
Gaider10 Jun 20, 2024
e92307e
Merge pull request #2 from Gaider10/villager_rng_cracking
RealRTTV Jun 20, 2024
5e8f1f2
ok changed some stuff lol i think this might be good
RealRTTV Jun 20, 2024
4642e34
removed latticg code
RealRTTV Jun 20, 2024
0bc4167
removed unused diff
RealRTTV Jun 20, 2024
4e65243
added help dialog for failed clock, no clock set, cracking during the…
RealRTTV Jun 21, 2024
a6f6ed5
shit
RealRTTV Jun 21, 2024
deeb1e6
Use the ambient sound that detected the desync for recracking
Gaider10 Jun 21, 2024
e4732b9
Fix nighttime check
Gaider10 Jun 21, 2024
badfe97
Merge pull request #3 from Gaider10/villager_rng_cracking
RealRTTV Jun 21, 2024
5c304e4
- added custom out of sync messages
RealRTTV Jun 22, 2024
38b8d69
- added nicer display to goals using ItemParser
RealRTTV Jun 23, 2024
3813d7b
added toString
RealRTTV Jun 23, 2024
7c2fe74
??
RealRTTV Jun 29, 2024
9519911
changes in response to review
RealRTTV Jul 1, 2024
42e3a20
added three-item-goal and two-item-enchanted-goal
RealRTTV Jul 2, 2024
6ecb586
whoop
RealRTTV Jul 3, 2024
d6894f8
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Jul 9, 2024
c453a39
updated and some minor, minor stuff
RealRTTV Jul 9, 2024
6293252
Update clientcommands.aw
RealRTTV Jul 12, 2024
b4a94ef
removed wildcard import
RealRTTV Jul 13, 2024
75bd52e
Update DebugRandom.java
RealRTTV Jul 13, 2024
c170054
Update DebugRandom.java
RealRTTV Jul 13, 2024
c3e4090
Update DebugRandom.java
RealRTTV Jul 13, 2024
7ac0113
Update ItemAndEnchantmentsPredicateArgument.java
RealRTTV Jul 13, 2024
210dbf4
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Aug 9, 2024
d2fb531
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Sep 28, 2024
02ee3c7
fixed some todo items
RealRTTV Sep 28, 2024
295840b
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Oct 5, 2024
a2757cc
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Nov 21, 2024
ee61233
added error calculation and updated to 1.21.3
RealRTTV Nov 21, 2024
ed97934
made it auto-readjust
RealRTTV Nov 21, 2024
fa04bfd
i can negate this and make it easier to understand
RealRTTV Nov 21, 2024
43a46df
fixed string literal translations
RealRTTV Nov 21, 2024
15803a5
stuff idk
RealRTTV Nov 22, 2024
dd5c552
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Nov 22, 2024
623fee1
whoops
RealRTTV Nov 22, 2024
1b5a836
Merge branch 'fabric' into fork/RealRTTV/villager_rng_cracking
Earthcomputer Nov 26, 2024
2f6eff6
whoopsie
RealRTTV Nov 26, 2024
6d250ba
Merge remote-tracking branch 'origin/villager_rng_cracking' into vill…
RealRTTV Nov 26, 2024
e534d05
whoopsie
RealRTTV Nov 26, 2024
0ea73a9
beruh
RealRTTV Nov 26, 2024
69e04fd
dw i moved it for ya
RealRTTV Nov 26, 2024
12b4039
bruh
RealRTTV Nov 26, 2024
e50cc27
Cleanup and fixes, extract stuff out of fishing cracker to use for vi…
Earthcomputer Nov 27, 2024
5548e61
Changed failure message for villager cracking
RealRTTV Nov 27, 2024
9054d8d
Move stuff around to be in more appropriate places
Earthcomputer Nov 27, 2024
40cec5b
Fix compile
Earthcomputer Nov 27, 2024
8daca5b
Improvements to cvillager command
Earthcomputer Nov 27, 2024
31837d4
Add fishingManipulation config
Earthcomputer Nov 27, 2024
0119a52
added faux task for villager cracking
RealRTTV Nov 28, 2024
b3345f0
fine then earth
RealRTTV Nov 28, 2024
94e2b5d
safer choice
RealRTTV Nov 28, 2024
abcb7bd
oh thats handy
RealRTTV Nov 28, 2024
76f01e3
Merge branch 'Earthcomputer:fabric' into villager_rng_cracking
RealRTTV Nov 28, 2024
8277f6f
removed usages of the term brute force where it wasn't applicable
RealRTTV Nov 28, 2024
a62b7d0
fixed null pointer exception
RealRTTV Nov 28, 2024
d6e2841
wiser choice in case `setTargetVillager(null)` is called
RealRTTV Nov 28, 2024
4f3aa4f
Merge branch 'refs/heads/fabric' into fork/RealRTTV/villager_rng_crac…
Earthcomputer Nov 29, 2024
f9a4530
Add villager random hierarchy regression test
Earthcomputer Nov 29, 2024
51a47ac
changed some names
RealRTTV Nov 29, 2024
a855766
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Nov 30, 2024
06c31b9
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Nov 30, 2024
612b84b
added error messages for breaking villager manipulation
RealRTTV Nov 30, 2024
00a3921
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Nov 30, 2024
11fcc1f
fixed failure of tests
RealRTTV Dec 1, 2024
e9fd0b7
added checks to spawn area
RealRTTV Dec 1, 2024
69ea5f2
moved code to a fn
RealRTTV Dec 1, 2024
7e02d21
oh yeah no that should be there
RealRTTV Dec 1, 2024
d1d8ce3
removed useless fn
RealRTTV Dec 1, 2024
d5bbb5a
me when wildcard imports
RealRTTV Dec 1, 2024
fdb5e7b
it works, hooray
RealRTTV Dec 1, 2024
6923b87
and that removes the stupid " from" at the end
RealRTTV Dec 1, 2024
29a4a0a
made changes from review
RealRTTV Dec 2, 2024
cd6cfc9
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Dec 3, 2024
29a0e5b
push
RealRTTV Dec 3, 2024
f75ae00
mister taxi driver, i don't want your weird math!
RealRTTV Dec 3, 2024
d1054fa
Include commit hash in clientcommands build and use it in github link…
Earthcomputer Dec 3, 2024
8231449
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Dec 4, 2024
cc85f30
forgor
RealRTTV Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/villager_rng_setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions regressionTests/villagerRandomHierarchy.regressiontest

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public static void main(String[] args) throws IOException {
}

Path destDir = Path.of(args[0]);
genLattiCG(destDir);
genPlayerLattiCG(destDir);
}

private static void genLattiCG(Path destDir) throws IOException {
private static void genPlayerLattiCG(Path destDir) throws IOException {
ProgramBuilder program = Program.builder(LCG.JAVA);
program.skip(-CCrackRng.NUM_THROWS * 4);
for (int i = 0; i < CCrackRng.NUM_THROWS; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
UsageTreeCommand.register(dispatcher);
UuidCommand.register(dispatcher);
VarCommand.register(dispatcher);
VillagerCommand.register(dispatcher, context);
WeatherCommand.register(dispatcher);
WhisperEncryptedCommand.register(dispatcher);
WikiCommand.register(dispatcher);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.earthcomputer.clientcommands.features.FishingCracker;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.earthcomputer.clientcommands.features.ServerBrandManager;
import net.earthcomputer.clientcommands.features.VillagerCracker;
import net.earthcomputer.clientcommands.util.MultiVersionCompat;
import net.minecraft.util.Mth;
import net.minecraft.util.StringRepresentable;
Expand Down Expand Up @@ -183,4 +184,24 @@ public enum PacketDumpMethod {
public static void setMinimumReplyDelaySeconds(float minimumReplyDelaySeconds) {
Configs.minimumReplyDelaySeconds = Math.clamp(minimumReplyDelaySeconds, 0.0f, ReplyCommand.MAXIMUM_REPLY_DELAY_SECONDS);
}

@Config(setter = @Config.Setter("setVillagerManipulation"), temporary = true)
private static boolean villagerManipulation = false;
public static boolean getVillagerManipulation() {
return villagerManipulation;
}
public static void setVillagerManipulation(boolean villagerManipulation) {
Configs.villagerManipulation = villagerManipulation;
if (villagerManipulation) {
ServerBrandManager.rngWarning();
} else {
VillagerCracker.reset();
}
}

@Config(setter = @Config.Setter("setMaxVillagerManipulationWaitTicks"), temporary = true)
public static int maxVillagerManipulationWaitTicks = 12000;
public static void setMaxVillagerManipulationWaitTicks(int maxVillagerManipulationWaitTicks) {
Configs.maxVillagerManipulationWaitTicks = Mth.clamp(maxVillagerManipulationWaitTicks, 0, 1_000_000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;

import java.util.HashMap;
Expand Down Expand Up @@ -101,4 +102,18 @@ public static String registerCode(Runnable code) {
runnables.put(randomString, code);
return randomString;
}

public static void updateOverlayProgressBar(int current, int total, int width, int time) {
MutableComponent builder = Component.empty();
int color = Mth.hsvToRgb(current / (total * 3.0f), 1.0f, 1.0f);
builder.append(Component.literal("[").withColor(0xAAAAAA));
builder.append(Component.literal("~" + Math.round(100.0 * current / total) + "%").withColor(color));
builder.append(Component.literal("] ").withColor(0xAAAAAA));
int filledWidth = (int) Math.round((double) width * current / total);
int unfilledWidth = width - filledWidth;
builder.append(Component.literal("|".repeat(filledWidth)).withColor(color));
builder.append(Component.literal("|".repeat(unfilledWidth)).withColor(0xAAAAAA));

addOverlayMessage(builder, time);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class ItemAndEnchantmentsPredicateArgument implements ArgumentType<ItemAndEnchantmentsPredicateArgument.ItemAndEnchantmentsPredicate> {

Expand All @@ -51,6 +52,8 @@ public class ItemAndEnchantmentsPredicateArgument implements ArgumentType<ItemAn
private Predicate<Item> itemPredicate = item -> true;
private BiPredicate<Item, Holder<Enchantment>> enchantmentPredicate = (item, ench) -> true;
private boolean constrainMaxLevel = false;
@Nullable
private String suffix;

private ItemAndEnchantmentsPredicateArgument(HolderLookup.Provider holderLookupProvider) {
this.enchantmentLookup = holderLookupProvider.lookupOrThrow(Registries.ENCHANTMENT);
Expand All @@ -75,6 +78,11 @@ public ItemAndEnchantmentsPredicateArgument constrainMaxLevel() {
return this;
}

public ItemAndEnchantmentsPredicateArgument withSuffix(String suffix) {
this.suffix = suffix;
return this;
}

public static ItemAndEnchantmentsPredicate getItemAndEnchantmentsPredicate(CommandContext<?> context, String name) {
return context.getArgument(name, ItemAndEnchantmentsPredicate.class);
}
Expand Down Expand Up @@ -159,9 +167,10 @@ public boolean test(ItemStack stack) {
if (item != stack.getItem() && (item != Items.BOOK || stack.getItem() != Items.ENCHANTED_BOOK)) {
return false;
}
List<EnchantmentInstance> enchantments = stack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream()
.map(entry -> new EnchantmentInstance(entry.getKey(), entry.getIntValue()))
.toList();
List<EnchantmentInstance> enchantments = Stream.concat(
stack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream(),
stack.getOrDefault(DataComponents.STORED_ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream()
).map(entry -> new EnchantmentInstance(entry.getKey(), entry.getIntValue())).toList();
return predicate.test(enchantments);
}
}
Expand Down Expand Up @@ -220,6 +229,10 @@ private boolean parseEnchantmentInstancePredicate() throws CommandSyntaxExceptio
return false;
}

if (option == Option.SUFFIX) {
return false;
}

boolean suggest = reader.canRead();
if (option == Option.EXACT) {
exact = true;
Expand Down Expand Up @@ -256,6 +269,7 @@ private enum Option {
WITHOUT,
EXACT,
ORDERED,
SUFFIX,
}

@Nullable
Expand All @@ -267,7 +281,7 @@ private Option parseOption() {
case "without" -> Option.WITHOUT;
case "exactly" -> exact ? null : Option.EXACT;
case "ordered" -> ordered || MultiVersionCompat.INSTANCE.getProtocolVersion() >= MultiVersionCompat.V1_21 ? null : Option.ORDERED;
default -> null;
default -> option.equals(suffix) ? Option.SUFFIX : null;
};
}

Expand Down Expand Up @@ -451,6 +465,9 @@ private void suggestOption() {
if (!ordered && MultiVersionCompat.INSTANCE.getProtocolVersion() < MultiVersionCompat.V1_21) {
validOptions.add("ordered");
}
if (suffix != null) {
validOptions.add(suffix);
}
SharedSuggestionProvider.suggest(validOptions, builder);
suggestions.add(builder);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

public class WithStringArgument<T> implements ArgumentType<WithStringArgument.Result<T>> {

Expand Down Expand Up @@ -46,5 +46,9 @@ public Collection<String> getExamples() {
return delegate.getExamples();
}

public record Result<T>(String string, T value) {}
public record Result<T>(String string, T value) {
public <U> Result<U> map(Function<? super T, ? extends U> mapper) {
return new Result<>(string, mapper.apply(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.earthcomputer.clientcommands.Configs;
import net.earthcomputer.clientcommands.command.ClientCommandHelper;
import net.earthcomputer.clientcommands.util.MultiVersionCompat;
import net.earthcomputer.clientcommands.task.ItemThrowTask;
import net.earthcomputer.clientcommands.task.LongTask;
Expand All @@ -29,7 +30,6 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -112,7 +112,6 @@ public class EnchantmentCracker {
*/

public static final Logger LOGGER = LogUtils.getLogger();
private static final int PROGRESS_BAR_WIDTH = 50;

// RENDERING
/*
Expand Down Expand Up @@ -479,17 +478,7 @@ public void onCompleted() {

@Override
protected void onItemThrown(int current, int total) {
MutableComponent builder = Component.empty();
int color = Mth.hsvToRgb(current / (total * 3.0f), 1.0f, 1.0f);
builder.append(Component.literal("[").withColor(0xAAAAAA));
builder.append(Component.literal("~" + Math.round(100.0 * current / total) + "%").withColor(color));
builder.append(Component.literal("] ").withColor(0xAAAAAA));
int filledWidth = (int) Math.round((double) PROGRESS_BAR_WIDTH * current / total);
int unfilledWidth = PROGRESS_BAR_WIDTH - filledWidth;
builder.append(Component.literal("|".repeat(filledWidth)).withColor(color));
builder.append(Component.literal("|".repeat(unfilledWidth)).withColor(0xAAAAAA));

Minecraft.getInstance().gui.setOverlayMessage(builder, false);
ClientCommandHelper.updateOverlayProgressBar(current, total, 50, 60);
}
});
}
Expand Down
Loading