-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add chunk save cme debugger Signed-off-by: Glease <[email protected]> * spotless Signed-off-by: Glease <[email protected]> * move away from too new API Signed-off-by: Glease <[email protected]> * dump full tag Signed-off-by: Glease <[email protected]> * fix build Signed-off-by: Glease <[email protected]> --------- Signed-off-by: Glease <[email protected]> Co-authored-by: Glease <[email protected]>
- Loading branch information
Showing
5 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinNBTTagCompound.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.minecraft; | ||
|
||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
import java.util.ConcurrentModificationException; | ||
import java.util.Iterator; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import net.minecraft.nbt.NBTBase; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import com.mitchej123.hodgepodge.util.NBTTagCompoundConcurrentModificationException; | ||
|
||
@Mixin(NBTTagCompound.class) | ||
public abstract class MixinNBTTagCompound { | ||
|
||
@Shadow | ||
protected static void func_150298_a(String name, NBTBase data, DataOutput output) throws IOException {} | ||
|
||
@Shadow | ||
public abstract NBTBase getTag(String key); | ||
|
||
@Redirect(method = "write", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;next()Ljava/lang/Object;")) | ||
private Object hodgepodge$checkCME(Iterator<?> instance) { | ||
if ("File IO Thread".equals(Thread.currentThread().getName())) { | ||
// only do this on chunk save thread | ||
try { | ||
return instance.next(); | ||
} catch (ConcurrentModificationException ex) { | ||
throw new NBTTagCompoundConcurrentModificationException(ex, this); | ||
} | ||
} else { | ||
return instance.next(); | ||
} | ||
} | ||
|
||
@Redirect( | ||
method = "write", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/nbt/NBTTagCompound;func_150298_a(Ljava/lang/String;Lnet/minecraft/nbt/NBTBase;Ljava/io/DataOutput;)V")) | ||
private void hodgepodge$appendKeyPath(String name, NBTBase data, DataOutput output) throws IOException { | ||
if ("File IO Thread".equals(Thread.currentThread().getName())) { | ||
// only do this on chunk save thread | ||
try { | ||
func_150298_a(name, data, output); | ||
} catch (NBTTagCompoundConcurrentModificationException ex) { | ||
String prefix = Stream.of("id", "mID", "x", "y", "z").map(s -> s + "=" + this.getTag(s)) | ||
.collect(Collectors.joining(",", "[", "]")); | ||
if (prefix.length() > 2) { // len(prefix + suffix) == 2 | ||
ex.addKeyPath(String.format("[%s]%s", prefix, name)); | ||
} else { | ||
ex.addKeyPath(name); | ||
} | ||
ex.setFullTag(this); | ||
throw ex; | ||
} | ||
} else { | ||
func_150298_a(name, data, output); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...in/java/com/mitchej123/hodgepodge/util/NBTTagCompoundConcurrentModificationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.mitchej123.hodgepodge.util; | ||
|
||
import java.util.*; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
|
||
import codechicken.nei.util.NBTJson; | ||
|
||
public class NBTTagCompoundConcurrentModificationException extends ConcurrentModificationException { | ||
|
||
private final Deque<String> keyChain = new ArrayDeque<>(); | ||
private final String source; | ||
private Object fullTag; | ||
|
||
public NBTTagCompoundConcurrentModificationException(ConcurrentModificationException cause, Object source) { | ||
super(cause); | ||
this.source = toString(source); | ||
fullTag = source; | ||
} | ||
|
||
public void addKeyPath(String key) { | ||
keyChain.addFirst(key); | ||
} | ||
|
||
public void setFullTag(Object fullTag) { | ||
this.fullTag = fullTag; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format( | ||
"Keys: %s. Source tag: %s. Full tag: %s", | ||
String.join("...", keyChain), | ||
source, | ||
toString(fullTag)); | ||
} | ||
|
||
private static String toString(Object source) { | ||
if (source == null) return "null"; | ||
for (int i = 0; i < 10; i++) { | ||
try { | ||
return source instanceof NBTTagCompound ? NBTJson.toJson((NBTTagCompound) source) : source.toString(); | ||
|
||
} catch (ConcurrentModificationException ignored) {} | ||
} | ||
return "~~failed to serialize~~"; | ||
} | ||
} |