Skip to content

Commit 3a0807b

Browse files
Fishing RNG (#162)
* WIP * Loot * Got it sort of working kinda * Add auto fish catching (doesn't work) * Did some hackfixes, but most importantly, got it working and fixed some mistakes, still not working 100% * Did some hackfixes, but most importantly, got it working and fixed some mistakes, still not working 100% * Detect possible delays and fix several network bugs * Apply magic correction by MC (PseudoGravity) * WIP: more user friendly version * Cleanup and fixes * Use EM even when there's less data Co-authored-by: mcrcortex <[email protected]>
1 parent 5dad50c commit 3a0807b

32 files changed

+1879
-137
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ version = project.mod_version
1111
group = project.maven_group
1212

1313
minecraft {
14+
accessWidener 'src/main/resources/clientcommands.aw'
1415
}
1516

1617
repositories {

fishing_bobber_random.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Constructor:
2+
UUID generation (4 calls)
3+
3x nextGaussian
4+
5+
Doesn't seem to be any calls when bobber is flying outside of water
6+
7+
- DamageSourcePropertiesLootCondition
8+
- EntityPropertiesLootCondition
9+
- LocationCheckLootCondition
10+
- TimeCheckLootCondition
11+
- WeatherCheckLootCondition
12+
- ExplorationMapLootFunction
13+
- FurnaceSmeltLootFunction
14+

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Done to increase the memory available to gradle.
2-
org.gradle.jvmargs=-Xmx1G
2+
org.gradle.jvmargs=-Xmx6G
33

44
# Fabric Properties
55
# check these on https://modmuss50.me/fabric.html

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
4848
GammaCommand.register(dispatcher);
4949
MoteCommand.register(dispatcher);
5050
ChorusCommand.register(dispatcher);
51+
FishCommand.register(dispatcher);
5152

5253
CrackRNGCommand.register(dispatcher);
5354

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

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

33
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
4+
import net.earthcomputer.clientcommands.features.FishingCracker;
45
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
56
import net.minecraft.util.math.MathHelper;
67

@@ -41,6 +42,20 @@ public static void setEnchantingPrediction(boolean enchantingPrediction) {
4142
EnchantmentCracker.resetCracker();
4243
}
4344

45+
@Rule(setter = "setFishingManipulation")
46+
private static boolean fishingManipulation = false;
47+
public static boolean getFishingManipulation() {
48+
return fishingManipulation;
49+
}
50+
public static void setFishingManipulation(boolean fishingManipulation) {
51+
TempRules.fishingManipulation = fishingManipulation;
52+
if (fishingManipulation) {
53+
ServerBrandManager.rngWarning();
54+
} else {
55+
FishingCracker.reset();
56+
}
57+
}
58+
4459
@Rule
4560
public static boolean playerRNGMaintenance = true;
4661

src/main/java/net/earthcomputer/clientcommands/command/CEnchantCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
2727
dispatcher.register(literal("cenchant")
2828
.then(literal("--simulate")
2929
.redirect(cenchant, ctx -> ctx.getSource().withLevel(((IServerCommandSource) ctx.getSource()).getLevel() | FLAG_SIMULATE)))
30-
.then(argument("itemAndEnchantmentsPredicate", itemAndEnchantmentsPredicate())
30+
.then(argument("itemAndEnchantmentsPredicate", itemAndEnchantmentsPredicate().withEnchantmentPredicate(ench -> !ench.isTreasure()))
3131
.executes(ctx -> cenchant(ctx.getSource(), getItemAndEnchantmentsPredicate(ctx, "itemAndEnchantmentsPredicate")))));
3232
}
3333

@@ -36,7 +36,7 @@ private static int cenchant(ServerCommandSource source, ItemAndEnchantmentsPredi
3636
Text text = new TranslatableText("commands.cenchant.needEnchantingPrediction")
3737
.formatted(Formatting.RED)
3838
.append(" ")
39-
.append(getCommandTextComponent("commands.cenchant.needEnchantingPrediction.enable", "/ctemprule set enchantingPrediction true"));
39+
.append(getCommandTextComponent("commands.client.enable", "/ctemprule set enchantingPrediction true"));
4040
sendFeedback(text);
4141
return 0;
4242
}

src/main/java/net/earthcomputer/clientcommands/command/ClientCommandManager.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.mojang.brigadier.StringReader;
44
import com.mojang.brigadier.exceptions.CommandSyntaxException;
5+
import net.earthcomputer.clientcommands.mixin.InGameHudAccessor;
56
import net.minecraft.client.MinecraftClient;
7+
import net.minecraft.client.gui.hud.InGameHud;
68
import net.minecraft.client.network.ClientPlayerEntity;
79
import net.minecraft.command.CommandException;
810
import net.minecraft.text.*;
@@ -32,14 +34,20 @@ public static void sendError(Text error) {
3234
sendFeedback(new LiteralText("").append(error).formatted(Formatting.RED));
3335
}
3436

35-
public static void sendFeedback(String message) {
36-
sendFeedback(new TranslatableText(message));
37+
public static void sendFeedback(String message, Object... args) {
38+
sendFeedback(new TranslatableText(message, args));
3739
}
3840

3941
public static void sendFeedback(Text message) {
4042
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(message);
4143
}
4244

45+
public static void addOverlayMessage(Text message, int time) {
46+
InGameHud inGameHud = MinecraftClient.getInstance().inGameHud;
47+
inGameHud.setOverlayMessage(message, false);
48+
((InGameHudAccessor) inGameHud).setOverlayRemaining(time);
49+
}
50+
4351
public static int executeCommand(StringReader reader, String command) {
4452
ClientPlayerEntity player = MinecraftClient.getInstance().player;
4553
try {
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package net.earthcomputer.clientcommands.command;
2+
3+
import com.google.common.collect.ImmutableSet;
4+
import com.mojang.brigadier.CommandDispatcher;
5+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
6+
import net.earthcomputer.clientcommands.TempRules;
7+
import net.earthcomputer.clientcommands.command.arguments.ClientItemPredicateArgumentType;
8+
import net.earthcomputer.clientcommands.features.FishingCracker;
9+
import net.minecraft.item.Item;
10+
import net.minecraft.item.ItemStack;
11+
import net.minecraft.item.Items;
12+
import net.minecraft.server.command.ServerCommandSource;
13+
import net.minecraft.text.TranslatableText;
14+
import net.minecraft.util.Formatting;
15+
import org.apache.commons.lang3.tuple.Pair;
16+
17+
import java.util.Set;
18+
19+
import static com.mojang.brigadier.arguments.IntegerArgumentType.*;
20+
import static net.earthcomputer.clientcommands.command.arguments.ClientItemPredicateArgumentType.*;
21+
import static net.earthcomputer.clientcommands.command.arguments.ItemAndEnchantmentsPredicateArgumentType.*;
22+
import static net.earthcomputer.clientcommands.command.arguments.WithStringArgumentType.*;
23+
import static net.earthcomputer.clientcommands.command.ClientCommandManager.*;
24+
import static net.minecraft.server.command.CommandManager.*;
25+
26+
public class FishCommand {
27+
private static final Set<Item> ENCHANTABLE_ITEMS = ImmutableSet.of(Items.BOOK, Items.FISHING_ROD, Items.BOW);
28+
29+
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
30+
addClientSideCommand("cfish");
31+
32+
dispatcher.register(literal("cfish")
33+
.then(literal("list-goals")
34+
.executes(ctx -> listGoals()))
35+
.then(literal("add-goal")
36+
.then(argument("goal", clientItemPredicate())
37+
.executes(ctx -> addGoal(getClientItemPredicate(ctx, "goal")))))
38+
.then(literal("add-enchanted-goal")
39+
.then(argument("goal", withString(itemAndEnchantmentsPredicate().withItemPredicate(ENCHANTABLE_ITEMS::contains)))
40+
.executes(ctx -> addEnchantedGoal(getWithString(ctx, "goal", ItemAndEnchantmentsPredicate.class)))))
41+
.then(literal("remove-goal")
42+
.then(argument("index", integer(1))
43+
.executes(ctx -> removeGoal(getInteger(ctx, "index"))))));
44+
}
45+
46+
private static int listGoals() {
47+
if (!checkFishingManipulationEnabled()) {
48+
return 0;
49+
}
50+
51+
if (FishingCracker.goals.isEmpty()) {
52+
sendFeedback(new TranslatableText("commands.cfish.listGoals.noGoals").styled(style -> style.withColor(Formatting.RED)));
53+
} else {
54+
sendFeedback("commands.cfish.listGoals.success", FishingCracker.goals.size());
55+
for (int i = 0; i < FishingCracker.goals.size(); i++) {
56+
sendFeedback((i + 1) + ": " + FishingCracker.goals.get(i).getPrettyString());
57+
}
58+
}
59+
60+
return FishingCracker.goals.size();
61+
}
62+
63+
private static int addGoal(ClientItemPredicateArgumentType.ClientItemPredicate goal) {
64+
if (!checkFishingManipulationEnabled()) {
65+
return 0;
66+
}
67+
68+
FishingCracker.goals.add(goal);
69+
70+
sendFeedback("commands.cfish.addGoal.success", goal.getPrettyString());
71+
72+
return FishingCracker.goals.size();
73+
}
74+
75+
private static int addEnchantedGoal(Pair<String, ItemAndEnchantmentsPredicate> stringAndItemAndEnchantments) {
76+
if (!checkFishingManipulationEnabled()) {
77+
return 0;
78+
}
79+
80+
String string = stringAndItemAndEnchantments.getLeft();
81+
ItemAndEnchantmentsPredicate itemAndEnchantments = stringAndItemAndEnchantments.getRight();
82+
83+
ClientItemPredicate goal = new ClientItemPredicate() {
84+
@Override
85+
public String getPrettyString() {
86+
return string;
87+
}
88+
89+
@Override
90+
public boolean test(ItemStack itemStack) {
91+
return itemAndEnchantments.test(itemStack);
92+
}
93+
};
94+
95+
FishingCracker.goals.add(goal);
96+
97+
sendFeedback("commands.cfish.addGoal.success", string);
98+
99+
return FishingCracker.goals.size();
100+
}
101+
102+
private static int removeGoal(int index) throws CommandSyntaxException {
103+
if (!checkFishingManipulationEnabled()) {
104+
return 0;
105+
}
106+
107+
if (index > FishingCracker.goals.size()) {
108+
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.integerTooHigh().create(index, FishingCracker.goals.size());
109+
}
110+
ClientItemPredicate goal = FishingCracker.goals.remove(index - 1);
111+
112+
sendFeedback("commands.cfish.removeGoal.success", goal.getPrettyString());
113+
114+
return FishingCracker.goals.size();
115+
}
116+
117+
private static boolean checkFishingManipulationEnabled() {
118+
if (!TempRules.getFishingManipulation()) {
119+
sendFeedback(new TranslatableText("commands.cfish.needFishingManipulation")
120+
.styled(style -> style.withColor(Formatting.RED))
121+
.append(" ")
122+
.append(getCommandTextComponent("commands.client.enable", "/ctemprule set fishingManipulation true")));
123+
return false;
124+
} else {
125+
return true;
126+
}
127+
}
128+
}

src/main/java/net/earthcomputer/clientcommands/command/arguments/ClientItemPredicateArgumentType.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.earthcomputer.clientcommands.command.arguments;
22

33
import com.mojang.brigadier.StringReader;
4+
import com.mojang.brigadier.arguments.ArgumentType;
5+
import com.mojang.brigadier.context.CommandContext;
46
import com.mojang.brigadier.exceptions.CommandSyntaxException;
57
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
68
import net.minecraft.client.MinecraftClient;
@@ -10,9 +12,11 @@
1012
import net.minecraft.item.ItemStack;
1113
import net.minecraft.nbt.CompoundTag;
1214
import net.minecraft.nbt.NbtHelper;
15+
import net.minecraft.server.command.ServerCommandSource;
1316
import net.minecraft.tag.Tag;
1417
import net.minecraft.text.TranslatableText;
1518
import net.minecraft.util.Identifier;
19+
import net.minecraft.util.registry.Registry;
1620

1721
import java.util.function.Predicate;
1822

@@ -34,16 +38,20 @@ public static ClientItemPredicateArgumentType clientItemPredicate() {
3438
return new ClientItemPredicateArgumentType();
3539
}
3640

41+
public static ClientItemPredicate getClientItemPredicate(CommandContext<ServerCommandSource> ctx, String name) throws CommandSyntaxException {
42+
return ctx.getArgument(name, ClientItemPredicateArgument.class).create(ctx);
43+
}
44+
3745
@Override
38-
public ItemPredicateArgument parse(StringReader reader) throws CommandSyntaxException {
46+
public ClientItemPredicateArgument parse(StringReader reader) throws CommandSyntaxException {
3947
ItemStringReader itemReader = new ItemStringReader(reader, true).consume();
4048
if (itemReader.getItem() != null) {
4149
ItemPredicate predicate = new ItemPredicate(itemReader.getItem(), itemReader.getTag());
4250
return ctx -> predicate;
4351
} else {
4452
Identifier tagId = itemReader.getId();
4553
return ctx -> {
46-
@SuppressWarnings("ConstantConditions") Tag<Item> tag = MinecraftClient.getInstance().getNetworkHandler().getTagManager().getItems().getTag(tagId);
54+
@SuppressWarnings("ConstantConditions") Tag.Identified<Item> tag = (Tag.Identified<Item>) MinecraftClient.getInstance().getNetworkHandler().getTagManager().getItems().getTag(tagId);
4755
if (tag == null) {
4856
throw UNKNOWN_TAG_EXCEPTION.create(tagId.toString());
4957
} else {
@@ -53,13 +61,22 @@ public ItemPredicateArgument parse(StringReader reader) throws CommandSyntaxExce
5361
}
5462
}
5563

64+
@FunctionalInterface
65+
public interface ClientItemPredicateArgument extends ItemPredicateArgument {
66+
@Override
67+
ClientItemPredicate create(CommandContext<ServerCommandSource> commandContext) throws CommandSyntaxException;
68+
}
69+
70+
public interface ClientItemPredicate extends Predicate<ItemStack> {
71+
String getPrettyString();
72+
}
5673

5774

58-
static class TagPredicate implements Predicate<ItemStack> {
59-
private final Tag<Item> tag;
75+
static class TagPredicate implements ClientItemPredicate {
76+
private final Tag.Identified<Item> tag;
6077
private final CompoundTag compound;
6178

62-
public TagPredicate(Tag<Item> tag, CompoundTag compound) {
79+
public TagPredicate(Tag.Identified<Item> tag, CompoundTag compound) {
6380
this.tag = tag;
6481
this.compound = compound;
6582
}
@@ -68,9 +85,18 @@ public TagPredicate(Tag<Item> tag, CompoundTag compound) {
6885
public boolean test(ItemStack stack) {
6986
return this.tag.contains(stack.getItem()) && NbtHelper.matches(this.compound, stack.getTag(), true);
7087
}
88+
89+
@Override
90+
public String getPrettyString() {
91+
String ret = "#" + tag.getId();
92+
if (compound != null) {
93+
ret += compound;
94+
}
95+
return ret;
96+
}
7197
}
7298

73-
static class ItemPredicate implements Predicate<ItemStack> {
99+
static class ItemPredicate implements ClientItemPredicate {
74100
private final Item item;
75101
private final CompoundTag compound;
76102

@@ -83,5 +109,14 @@ public ItemPredicate(Item item, CompoundTag compound) {
83109
public boolean test(ItemStack stack) {
84110
return stack.getItem() == this.item && NbtHelper.matches(this.compound, stack.getTag(), true);
85111
}
112+
113+
@Override
114+
public String getPrettyString() {
115+
String ret = String.valueOf(Registry.ITEM.getId(item));
116+
if (compound != null) {
117+
ret += compound;
118+
}
119+
return ret;
120+
}
86121
}
87122
}

0 commit comments

Comments
 (0)