Skip to content

Commit 2276c08

Browse files
committed
Backport changes for version 1.2
The major change is the addition of doInitialFull() to scan the full 2^32 possibilities. With some optimized routines and enhanced threading, this makes it possible (although still slow) to operate without a starting seed. Added a new config param to allow customization of this behavior, although the default should work well. Several minor bug fixes and cleanups that ought to have been in their own commits. Also, added tests.
1 parent 38060e7 commit 2276c08

File tree

8 files changed

+492
-99
lines changed

8 files changed

+492
-99
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ re-logging won't change it.
3838
- The "+X more" values become exact.
3939
- The tooltip changes to show the enchantment effects in white, without percentages (since they're all guaranteed now.)
4040

41+
### V1.2 Feature: Working without a seed hint
42+
Normally, the server sends enough information in a single test-enchant to quickly rule out most possibilities. However, some
43+
custom Minecraft servers mask some of this information, which makes the mod's job much harder. You will know you are in this
44+
situation if, after seeming to narrow in on the seed, the text changes to "Calculating... 0%" and starts counting up
45+
slowly. This means the mod has detected that using the seed isn't working, so it's doing an exhaustive search of all possibilities,
46+
by replaying the objects you've already test-enchanted.
47+
48+
If this happens, you can go do something else for a while - the process will take a minute or two. Leaving the
49+
enchanting altar (or even destroying it) won't lose your progress, although logging out will. You may need to try a slightly
50+
wider variety of items to pinpoint an exact seed, although usually the combo of "book, pants, boots, helmet, chest, sword, bow"
51+
is enough. (Another possibility if this happens is that the mod has a bug, or the server is using different mechanics for
52+
enchanting than the client is aware of. You'll know the difference because after the long calculation, you'll get an error message.)
53+
4154
## How it works
4255
Internally, Minecraft uses a [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) (RNG for short)
4356
to determine which enchantments will be applied to an item. The state of this RNG is completely determined by a single 32-bit number,

java/io/github/d0sboots/enchantmentrevealer/ContainerEnchantmentWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected Slot addSlotToContainer(Slot slot) {
6262
@Override
6363
public boolean enchantItem(EntityPlayer playerIn, int id) {
6464
boolean val = super.enchantItem(playerIn, id);
65-
if (val) {
65+
if (val && lastObservation != null) {
6666
Observation observation = new Observation();
6767
System.arraycopy(lastObservation.levels, 0, observation.levels, 0, 3);
6868
observation.truncatedSeed = (short) id;

java/io/github/d0sboots/enchantmentrevealer/EnchantmentRevealer.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
public class EnchantmentRevealer
3131
{
3232
public static final String MODID = "EnchantmentRevealer";
33-
public static final String VERSION = "1.1";
33+
public static final String VERSION = "1.2";
3434
public static boolean verbose = false;
3535

3636
// Replacement for System.out that doesn't do anything. This is replaced by System.out if verbose is true.
@@ -40,7 +40,7 @@ public class EnchantmentRevealer
4040
@Override public void write(byte[] unused1, int unused2, int unused3) {}
4141
});
4242

43-
private final Events events = new Events();
43+
private Events events;
4444
private boolean enableCommand = false;
4545

4646
@EventHandler
@@ -59,6 +59,13 @@ public void init(FMLPreInitializationEvent event)
5959
"If true, the /xpseed command will be enabled, allowing you to retrieve "
6060
+ "and set players' enchantment seeds directly.");
6161
enableCommand = prop.getBoolean();
62+
prop = config.get(Configuration.CATEGORY_CLIENT, "useSeedHint", "sometimes",
63+
"How to handle seed \"hint\" values from the server. On a vanilla server, these provide "
64+
+ "useful information that greatly speeds up the deduction process, but other servers "
65+
+ "may send garbage data instead. Setting this to \"always\" says to always trust the "
66+
+ "server provided value, while \"never\" means to ignore it. The default is \"sometimes\", "
67+
+ "which means try to use the seed, but recalculate as if \"never\" if it doesn't work.");
68+
events = new Events(prop.getString());
6269

6370
if (config.hasChanged()) {
6471
config.save();

0 commit comments

Comments
 (0)