-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More separation of wrap() and of() methods, moved Utils.entitySelecto…
…r(x) to EntitySelector.of(x)
- Loading branch information
1 parent
46420b2
commit c982918
Showing
30 changed files
with
604 additions
and
492 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
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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/dev/latvian/mods/kubejs/bindings/EntitySelectorWrapper.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,52 @@ | ||
package dev.latvian.mods.kubejs.bindings; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import dev.latvian.mods.rhino.util.HideFromJS; | ||
import net.minecraft.advancements.critereon.MinMaxBounds; | ||
import net.minecraft.commands.arguments.selector.EntitySelector; | ||
import net.minecraft.commands.arguments.selector.EntitySelectorParser; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class EntitySelectorWrapper { | ||
private static final Map<String, EntitySelector> ENTITY_SELECTOR_CACHE = new HashMap<>(); | ||
private static final EntitySelector ALL_ENTITIES_SELECTOR = new EntitySelector(EntitySelector.INFINITE, true, false, List.of(), MinMaxBounds.Doubles.ANY, Function.identity(), null, EntitySelectorParser.ORDER_RANDOM, false, null, null, null, true); | ||
|
||
public static EntitySelector of(EntitySelector selector) { | ||
return selector; | ||
} | ||
|
||
@HideFromJS | ||
public static EntitySelector wrap(@Nullable Object o) { | ||
if (o == null) { | ||
return ALL_ENTITIES_SELECTOR; | ||
} else if (o instanceof EntitySelector s) { | ||
return s; | ||
} | ||
|
||
String s = o.toString(); | ||
|
||
if (s.isBlank()) { | ||
return ALL_ENTITIES_SELECTOR; | ||
} | ||
|
||
var sel = ENTITY_SELECTOR_CACHE.get(s); | ||
|
||
if (sel == null) { | ||
sel = ALL_ENTITIES_SELECTOR; | ||
|
||
try { | ||
sel = new EntitySelectorParser(new StringReader(s), true).parse(); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
ENTITY_SELECTOR_CACHE.put(s, sel); | ||
return sel; | ||
} | ||
} |
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
Oops, something went wrong.