-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
6 changed files
with
161 additions
and
25 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
18 changes: 7 additions & 11 deletions
18
src/main/java/com/denizenscript/clientizen/objects/ClientizenObjectRegistry.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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
package com.denizenscript.clientizen.objects; | ||
|
||
public class ClientizenObjectRegistry { | ||
|
||
public static void registerTagHandlers() { | ||
import com.denizenscript.denizencore.objects.ObjectFetcher; | ||
import com.denizenscript.denizencore.objects.ObjectType; | ||
|
||
} | ||
|
||
public static void registerObjects() { | ||
registerObjectTypes(); | ||
registerTagHandlers(); | ||
} | ||
public class ClientizenObjectRegistry { | ||
|
||
public static void registerObjectTypes() { | ||
public static ObjectType<EntityTag> TYPE_ENTITY; | ||
|
||
} | ||
public static void registerObjects() { | ||
TYPE_ENTITY = ObjectFetcher.registerWithObjectFetcher(EntityTag.class, EntityTag.tagProcessor).setAsNOtherCode().generateBaseTag(); | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/main/java/com/denizenscript/clientizen/objects/EntityTag.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,129 @@ | ||
package com.denizenscript.clientizen.objects; | ||
|
||
import com.denizenscript.denizencore.objects.Fetchable; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.tags.Attribute; | ||
import com.denizenscript.denizencore.tags.ObjectTagProcessor; | ||
import com.denizenscript.denizencore.tags.TagContext; | ||
import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
import com.denizenscript.denizencore.utilities.debugging.Debug; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.LivingEntity; | ||
|
||
import java.util.UUID; | ||
|
||
public class EntityTag implements ObjectTag { | ||
|
||
public UUID uuid; | ||
public Entity entity; | ||
|
||
public EntityTag(Entity entity) { | ||
this.entity = entity; | ||
this.uuid = entity.getUuid(); | ||
} | ||
|
||
@Fetchable("e") | ||
public static EntityTag valueOf(String string, TagContext context) { | ||
if (string == null) { | ||
return null; | ||
} | ||
if (string.startsWith("e@")) { | ||
string = string.substring("e@".length()); | ||
} | ||
try { | ||
Entity found = MinecraftClient.getInstance().world.getEntityLookup().get(UUID.fromString(string)); | ||
if (found != null) { | ||
return new EntityTag(found); | ||
} | ||
} | ||
catch (Exception ignored) {} | ||
if (context == null || context.showErrors()) { | ||
Debug.echoError("valueOf EntityTag returning null: " + string); | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean matches(String string) { | ||
if (string.startsWith("e@")) { | ||
return true; | ||
} | ||
return valueOf(string, CoreUtilities.noDebugContext) != null; | ||
} | ||
|
||
public Entity getEntity() { | ||
if (entity == null || entity.isRemoved()) { | ||
Entity found = MinecraftClient.getInstance().world.getEntityLookup().get(uuid); | ||
if (found != null) { | ||
entity = found; | ||
} | ||
} | ||
return entity; | ||
} | ||
|
||
public static void register() { | ||
tagProcessor.registerTag(ElementTag.class, "entity_type", (attribute, object) -> { | ||
return new ElementTag(object.getEntity().getType().getUntranslatedName(), true); | ||
}); | ||
tagProcessor.registerTag(ElementTag.class, "health", (attribute, object) -> { | ||
if (object.getEntity() instanceof LivingEntity livingEntity) { | ||
return new ElementTag(livingEntity.getHealth()); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
public static ObjectTagProcessor<EntityTag> tagProcessor = new ObjectTagProcessor<>(); | ||
|
||
@Override | ||
public ObjectTag getObjectAttribute(Attribute attribute) { | ||
return tagProcessor.getObjectAttribute(this, attribute); | ||
} | ||
|
||
@Override | ||
public String identify() { | ||
return "e@" + uuid; | ||
} | ||
|
||
@Override | ||
public String identifySimple() { | ||
return identify(); | ||
} | ||
|
||
@Override | ||
public String debuggable() { | ||
String debuggable = "<LG>e@<Y>" + uuid; | ||
if (getEntity() != null) { | ||
debuggable += " <GR>(" + entity.getType().getUntranslatedName(); | ||
if (entity.hasCustomName()) { | ||
debuggable += "<Y>/<GR>" + entity.getCustomName().getString(); | ||
} | ||
debuggable += ")"; | ||
} | ||
return debuggable; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return identify(); | ||
} | ||
|
||
private String prefix = "Entity"; | ||
|
||
@Override | ||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
@Override | ||
public boolean isUnique() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ObjectTag setPrefix(String prefix) { | ||
this.prefix = prefix; | ||
return this; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessWidener v2 named | ||
|
||
accessible method net/minecraft/client/world/ClientWorld getEntityLookup ()Lnet/minecraft/world/entity/EntityLookup; |
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