-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attach + EntityTag beginnings #6
base: main
Are you sure you want to change the base?
Changes from 2 commits
c4bdedd
b9b1a0a
6e53820
5a90ace
0ed8bc1
047a355
ec01f1f
ceee245
b35468c
f88cc7f
4927417
3280c05
abdf37b
4d44a6c
a21f4bd
417cb32
c9e741f
055bf15
29ba868
865da19
3ff18f0
575cc53
9c477f0
40b7f24
165eb5f
8f02565
d98e620
7894a32
03ceb06
feaaa97
eadfbeb
e6813e7
cd40ac3
cb68791
65ebf1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.denizenscript.clientizen.mixin.render; | ||
|
||
import com.denizenscript.clientizen.scripts.commands.AttachCommand; | ||
import net.minecraft.client.render.Frustum; | ||
import net.minecraft.client.render.entity.EntityRenderDispatcher; | ||
import net.minecraft.entity.Entity; | ||
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(EntityRenderDispatcher.class) | ||
public class EntityRenderDispatcherMixin { | ||
|
||
/*@Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true) | ||
private static <E extends Entity> void clientizen$cancelRenderIfAttached( | ||
E entity, Frustum frustum, double x, double y, double z, CallbackInfoReturnable<Boolean> cir) { | ||
if (AttachCommand.attachedEntities.containsKey(entity.getUuid())) { | ||
cir.setReturnValue(false); | ||
} | ||
}*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.denizenscript.clientizen.mixin.render; | ||
|
||
import com.denizenscript.clientizen.scripts.commands.AttachCommand; | ||
import net.minecraft.client.render.entity.EntityRenderer; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.util.math.Vec3d; | ||
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(EntityRenderer.class) | ||
public class EntityRendererMixin<T extends Entity> { | ||
|
||
/*@Inject(method = "<init>", at = @At("TAIL")) | ||
private void clientizen$addAttachFeatureRenderer(EntityRendererFactory.Context ctx, CallbackInfo ci) { | ||
add | ||
}*/ | ||
|
||
@Inject(method = "getPositionOffset", cancellable = true, at = @At("HEAD")) | ||
private void clientizen$getAttachedOffset(T entity, float tickDelta, CallbackInfoReturnable<Vec3d> cir) { | ||
if (AttachCommand.attachedEntities.containsKey(entity.getUuid())) { | ||
cir.setReturnValue(AttachCommand.attachedEntities.get(entity.getUuid()).getEntity().getPos().subtract(entity.getPos())); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.denizenscript.clientizen.render; | ||
|
||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.entity.feature.FeatureRenderer; | ||
import net.minecraft.client.render.entity.feature.FeatureRendererContext; | ||
import net.minecraft.client.render.entity.model.EntityModel; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.Entity; | ||
|
||
public class ClientizenAttachedEntityFeatureRenderer extends FeatureRenderer<Entity, EntityModel<Entity>> { | ||
|
||
public ClientizenAttachedEntityFeatureRenderer(FeatureRendererContext<Entity, EntityModel<Entity>> context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, Entity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) { | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.denizenscript.clientizen.scripts.commands; | ||
|
||
import com.denizenscript.clientizen.tags.EntityTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntry; | ||
import com.denizenscript.denizencore.scripts.commands.AbstractCommand; | ||
import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear; | ||
import com.denizenscript.denizencore.scripts.commands.generator.ArgName; | ||
import com.denizenscript.denizencore.scripts.commands.generator.ArgPrefixed; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public class AttachCommand extends AbstractCommand { | ||
|
||
public static Map<UUID, EntityTag> attachedEntities = new HashMap<>(); | ||
|
||
public AttachCommand() { | ||
setName("attach"); | ||
setSyntax("attach [<entity>|...] [to:<entity>] (cancel)"); | ||
setRequiredArguments(2, 2); | ||
isProcedural = false; | ||
autoCompile(); | ||
} | ||
|
||
public static void autoExecute(ScriptEntry scriptEntry, | ||
@ArgLinear @ArgName("entities") List<EntityTag> attachingEntities, | ||
@ArgPrefixed @ArgName("to") EntityTag entity, | ||
@ArgName("cancel") boolean cancel) { | ||
for (EntityTag attachingEntity : attachingEntities) { | ||
if (cancel) { | ||
attachedEntities.remove(attachingEntity.uuid); | ||
} | ||
else { | ||
attachedEntities.put(attachingEntity.uuid, entity); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.denizenscript.clientizen.tags; | ||
|
||
import com.denizenscript.denizencore.objects.core.ListTag; | ||
import com.denizenscript.denizencore.tags.PseudoObjectTagBase; | ||
import com.denizenscript.denizencore.tags.TagManager; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
|
||
public class ClientTagBase extends PseudoObjectTagBase<ClientTagBase> { | ||
|
||
public static ClientTagBase instance; | ||
|
||
public static void register() { | ||
instance = new ClientTagBase(); | ||
TagManager.registerStaticTagBaseHandler(ClientTagBase.class, "client", t -> instance); | ||
} | ||
|
||
@Override | ||
public void registerTags() { | ||
|
||
tagProcessor.registerTag(ListTag.class, "loaded_entities", (attribute, object) -> { | ||
ListTag list = new ListTag(); | ||
for (Entity entity : MinecraftClient.getInstance().world.getEntities()) { | ||
list.addObject(new EntityTag(entity)); | ||
} | ||
return list; | ||
}); | ||
|
||
tagProcessor.registerTag(EntityTag.class, "target", (attribute, object) -> { | ||
System.out.println(MinecraftClient.getInstance().targetedEntity); | ||
return new EntityTag(MinecraftClient.getInstance().targetedEntity); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package com.denizenscript.clientizen.tags; | ||
|
||
import com.denizenscript.denizencore.objects.ObjectFetcher; | ||
import com.denizenscript.denizencore.objects.ObjectType; | ||
|
||
public class ClientizenTagRegistry { | ||
|
||
public static void registerTagHandlers() { | ||
public static ObjectType<EntityTag> TYPE_ENTITY; | ||
|
||
public static void registerTagHandlers() { | ||
ClientTagBase.register(); | ||
TYPE_ENTITY = ObjectFetcher.registerWithObjectFetcher(EntityTag.class, EntityTag.tagProcessor).setAsNOtherCode().generateBaseTag(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.denizenscript.clientizen.tags; | ||
|
||
import com.denizenscript.denizencore.objects.Fetchable; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.tags.ObjectTagProcessor; | ||
import com.denizenscript.denizencore.tags.TagContext; | ||
import com.denizenscript.denizencore.utilities.debugging.Debug; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
|
||
import java.util.UUID; | ||
|
||
public class EntityTag implements ObjectTag { | ||
|
||
public UUID uuid; | ||
|
||
public EntityTag(UUID uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public EntityTag(Entity entity) { | ||
this(entity.getUuid()); | ||
} | ||
|
||
@Fetchable("e") | ||
public static EntityTag valueOf(String string, TagContext tagContext) { | ||
if (string == null) { | ||
return null; | ||
} | ||
if (string.startsWith("e@")) { | ||
return new EntityTag(UUID.fromString(string.substring(2))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should check if it starts with |
||
} | ||
if (tagContext == null || tagContext.showErrors()) { | ||
Debug.log("valueOf EntityTag returning null: " + string); | ||
} | ||
return null; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also missing |
||
public Entity getEntity() { | ||
return MinecraftClient.getInstance().world.getEntityLookup().get(uuid); | ||
} | ||
|
||
public static ObjectTagProcessor<EntityTag> tagProcessor = new ObjectTagProcessor<>(); | ||
|
||
public static void registerTags() { | ||
|
||
tagProcessor.registerTag(ElementTag.class, "entity_type", (attribute, object) -> { | ||
return new ElementTag(object.getEntity().getType().getUntranslatedName(), true); | ||
}); | ||
} | ||
|
||
private String prefix = "Entity"; | ||
|
||
@Override | ||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
@Override | ||
public boolean isUnique() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String identify() { | ||
return "e@" + uuid; | ||
} | ||
|
||
@Override | ||
public String identifySimple() { | ||
return identify(); | ||
} | ||
|
||
@Override | ||
public ObjectTag setPrefix(String prefix) { | ||
this.prefix = prefix; | ||
return this; | ||
} | ||
} |
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List
isn't a supported parameter type, should useListTag
&ListTag#filter