-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac46e02
commit 96a9818
Showing
7 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
cardinal-ui/src/main/java/folk/sisby/switchy/client/api/AllValueElementNode.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,69 @@ | ||
package folk.sisby.switchy.client.api; | ||
|
||
import net.minecraft.command.argument.NbtPathArgumentType; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class AllValueElementNode implements NbtPathArgumentType.PathNode { | ||
public static final AllValueElementNode INSTANCE = new AllValueElementNode(); | ||
|
||
private AllValueElementNode() { | ||
} | ||
|
||
@Override | ||
public void get(NbtElement nbt, List<NbtElement> results) { | ||
if (nbt instanceof NbtCompound compound) { | ||
compound.getKeys().stream().map(compound::get).forEach(results::add); | ||
} | ||
} | ||
|
||
@Override | ||
public void getOrInit(NbtElement nbt, Supplier<NbtElement> source, List<NbtElement> results) { | ||
if (nbt instanceof NbtCompound compound) { | ||
if (compound.isEmpty()) { | ||
results.add(source.get()); | ||
} else { | ||
get(nbt, results); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public NbtElement init() { | ||
return new NbtCompound(); | ||
} | ||
|
||
@Override | ||
public int set(NbtElement nbt, Supplier<NbtElement> source) { | ||
if (nbt instanceof NbtCompound compound) { | ||
if (compound.isEmpty()) { | ||
compound.put("default", source.get()); | ||
return 1; | ||
} else { | ||
NbtElement nbtElement = source.get(); | ||
int unequal_count = (int) compound.getKeys().stream().map(compound::get).filter(nbtElement::equals).count(); | ||
if (unequal_count > 0) { | ||
compound.getKeys().forEach(k -> compound.put(k, source.get())); | ||
} | ||
return unequal_count; | ||
} | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
@Override | ||
public int clear(NbtElement nbt) { | ||
if (nbt instanceof NbtCompound compound) { | ||
int i = compound.getKeys().size(); | ||
if (i > 0) { | ||
compound.getKeys().forEach(compound::remove); | ||
return i; | ||
} | ||
} | ||
return 0; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
cardinal-ui/src/main/java/folk/sisby/switchy/client/mixin/NbtPathArgumentTypeMixin.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,21 @@ | ||
package folk.sisby.switchy.client.mixin; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import folk.sisby.switchy.client.api.AllValueElementNode; | ||
import net.minecraft.command.argument.NbtPathArgumentType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(NbtPathArgumentType.class) | ||
public class NbtPathArgumentTypeMixin { | ||
@Inject(method = "parseNode", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/argument/NbtPathArgumentType;readName(Lcom/mojang/brigadier/StringReader;)Ljava/lang/String;"), cancellable = true) | ||
private static void AddAllValueElementNode(StringReader reader, boolean root, CallbackInfoReturnable<NbtPathArgumentType.PathNode> cir) { | ||
if (reader.peek() == '*') { | ||
reader.skip(); | ||
cir.setReturnValue(AllValueElementNode.INSTANCE); | ||
cir.cancel(); | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
cardinal-ui/src/main/resources/switchy-cardinal-ui.accesswidener
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
accessWidener v1 named | ||
|
||
accessible field net/minecraft/nbt/visitor/NbtTextFormatter result Lnet/minecraft/text/Text; | ||
accessible class net/minecraft/command/argument/NbtPathArgumentType$PathNode |
12 changes: 12 additions & 0 deletions
12
cardinal-ui/src/main/resources/switchy-cardinal-ui.mixins.json
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,12 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "folk.sisby.switchy.client.mixin", | ||
"compatibilityLevel": "JAVA_17", | ||
"client": [ | ||
"NbtPathArgumentTypeMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
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