-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backported tag error patch from 1.20
- Loading branch information
1 parent
414f412
commit 6394542
Showing
4 changed files
with
124 additions
and
3 deletions.
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
84 changes: 84 additions & 0 deletions
84
common/src/main/java/dev/latvian/mods/kubejs/server/FakeTagEventJS.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,84 @@ | ||
package dev.latvian.mods.kubejs.server; | ||
|
||
import dev.latvian.mods.kubejs.event.EventJS; | ||
import dev.latvian.mods.kubejs.registry.RegistryInfo; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Consumer; | ||
|
||
public class FakeTagEventJS extends EventJS { | ||
public class FakeTagWrapper { | ||
public final ResourceLocation id; | ||
|
||
private FakeTagWrapper(ResourceLocation i) { | ||
id = i; | ||
invalid = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "<%s / %s>".formatted(getType(), id); | ||
} | ||
|
||
public FakeTagWrapper add(String... ids) { | ||
actions.add(e -> e.get(id).add(ids)); | ||
return this; | ||
} | ||
|
||
public FakeTagWrapper remove(String... ids) { | ||
actions.add(e -> e.remove(id).add(ids)); | ||
return this; | ||
} | ||
|
||
public FakeTagWrapper removeAll() { | ||
actions.add(e -> e.get(id).removeAll()); | ||
return this; | ||
} | ||
|
||
public Collection<ResourceLocation> getObjectIds() { | ||
invalid = true; | ||
return Set.of(); | ||
} | ||
} | ||
|
||
public final RegistryInfo registry; | ||
public final Map<ResourceLocation, FakeTagWrapper> tags; | ||
public final List<Consumer<TagEventJS<?>>> actions; | ||
public boolean invalid; | ||
|
||
public FakeTagEventJS(RegistryInfo registry) { | ||
this.registry = registry; | ||
this.tags = new ConcurrentHashMap<>(); | ||
this.actions = new ArrayList<>(); | ||
} | ||
|
||
public ResourceLocation getType() { | ||
return registry.key.location(); | ||
} | ||
|
||
public FakeTagWrapper get(ResourceLocation id) { | ||
return tags.computeIfAbsent(id, FakeTagWrapper::new); | ||
} | ||
|
||
public FakeTagWrapper add(ResourceLocation tag, String... ids) { | ||
return get(tag).add(ids); | ||
} | ||
|
||
public FakeTagWrapper remove(ResourceLocation tag, String... ids) { | ||
return get(tag).remove(ids); | ||
} | ||
|
||
public FakeTagWrapper removeAll(ResourceLocation tag) { | ||
return get(tag).removeAll(); | ||
} | ||
|
||
public void removeAllTagsFrom(String... ignored) { | ||
actions.add(e -> e.removeAllTagsFrom(ignored)); | ||
} | ||
} |
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