Skip to content

Attach + EntityTag beginnings #6

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4bdedd
funny draft
acikek Oct 19, 2022
b9b1a0a
g
acikek Oct 19, 2022
6e53820
Merge branch 'main' into attach
tal5 Dec 3, 2022
5a90ace
`EntityTag` to `objects` , update `ClientTagBase`
tal5 Dec 4, 2022
0ed8bc1
Merge branch 'main' into attach
tal5 Dec 4, 2022
047a355
`EntityTag` cleanup and fixes
tal5 Dec 4, 2022
ec01f1f
Fix `AttachCommand` param
tal5 Dec 4, 2022
ceee245
Cleanup imports
tal5 Dec 5, 2022
b35468c
`client.self_entity`
tal5 Dec 5, 2022
f88cc7f
Fixup `attach` command
tal5 Dec 5, 2022
4927417
Merge branch 'main' into attach
acikek Jan 6, 2023
3280c05
actually make rendering work well i think
acikek Jan 6, 2023
abdf37b
Fix repository order
tal5 Jan 7, 2023
4d44a6c
Implement `debuggable` in `EntityTag`
tal5 Jan 9, 2023
a21f4bd
Revert "Implement `debuggable` in `EntityTag`"
tal5 Jan 9, 2023
417cb32
Implement `debuggable` in `EntityTag`
tal5 Jan 9, 2023
c9e741f
Fix attaching entities to other entities
tal5 Jan 9, 2023
055bf15
Attempted lighting improvment
tal5 Jan 9, 2023
29ba868
Merge branch 'main' into attach
tal5 Jan 9, 2023
865da19
Remove leftover
tal5 Jan 9, 2023
3ff18f0
Merge branch 'main' into attach
tal5 Jan 10, 2023
575cc53
Fix lighting issues with attach
tal5 Jan 13, 2023
9c477f0
Supress unchecked cast warning. remove old code
tal5 Jan 13, 2023
40b7f24
Minor `EntityTag` cleanups
tal5 Jan 13, 2023
165eb5f
experimental args for attach
acikek Jan 13, 2023
8f02565
Register `attached` feature renderer using API
tal5 Jan 13, 2023
d98e620
Prevent rotation for attached entities
tal5 Jan 13, 2023
7894a32
Supress warning in previous commit
tal5 Jan 13, 2023
03ceb06
Improve `EntityTag#debuggable`
tal5 Jan 15, 2023
feaaa97
Implement `client.flag` tags
tal5 Jan 15, 2023
eadfbeb
Merge branch 'main' into attach
tal5 Jan 15, 2023
e6813e7
Merge branch 'main' into attach
tal5 Jan 15, 2023
cd40ac3
Merge branch 'main' into attach
tal5 Feb 5, 2023
cb68791
Remove old code
tal5 Feb 5, 2023
65ebf1a
Replace Tabs
tal5 Feb 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/denizenscript/clientizen/Clientizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.clientizen.network.NetworkManager;
import com.denizenscript.clientizen.objects.ClientizenObjectRegistry;
import com.denizenscript.clientizen.objects.properties.PropertyRegistry;
import com.denizenscript.clientizen.render.ClientizenAttachedEntityFeatureRenderer;
import com.denizenscript.clientizen.scripts.commands.ClientizenCommandRegistry;
import com.denizenscript.clientizen.scripts.containers.ClientizenContainerRegistry;
import com.denizenscript.clientizen.tags.ClientizenTagContext;
Expand Down Expand Up @@ -79,6 +80,7 @@ public void onInitializeClient() {
// Initialize Clientizen systems
NetworkManager.init();
ClientizenDebugScreen.register();
ClientizenAttachedEntityFeatureRenderer.init();
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> new ClientExecuteCommand(dispatcher));

// Check for the client scripts folder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.denizenscript.clientizen.mixin.render;

import com.denizenscript.clientizen.scripts.commands.AttachCommand;
import net.minecraft.client.render.Frustum;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.world.WorldView;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EntityRenderDispatcher.class)
public class EntityRenderDispatcherMixin {

@Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true)
private <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);
}
}

@Inject(method = "renderShadow", at = @At("HEAD"), cancellable = true)
private static void clientizen$cancelAttachShadow(MatrixStack matrices, VertexConsumerProvider vertexConsumers, Entity entity, float opacity, float tickDelta, WorldView world, float radius, CallbackInfo ci) {
AttachCommand.AttachData data = AttachCommand.attachedEntities.get(entity.getUuid());
if (data != null && data.noShadow()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.denizenscript.clientizen.mixin.render;

import com.denizenscript.clientizen.scripts.commands.AttachCommand;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntityRenderer.class)
public abstract class LivingEntityRendererMixin<T extends LivingEntity, M extends EntityModel<T>> {

private Entity clientizen$renderingEntity;

@Inject(method = "setupTransforms", cancellable = true, at = @At("HEAD"))
private void clientizen$cancelAttachAnimation(T entity, MatrixStack matrices, float animationProgress, float bodyYaw, float tickDelta, CallbackInfo ci) {
AttachCommand.AttachData data = AttachCommand.attachedEntities.get(entity.getUuid());
if (data != null && data.noAnimation()) {
ci.cancel();
}
}

@Inject(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At("HEAD"))
private void clientizen$captureRenderingEntity(T livingEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
clientizen$renderingEntity = livingEntity;
}

// TODO fix this (ordinal wrong maybe)
@ModifyVariable(
method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
at = @At(value = "STORE"), ordinal = 8)
private float clientizen$cancelAttachAngles(float animationProgress) {
if (clientizen$renderingEntity != null) {
AttachCommand.AttachData data = AttachCommand.attachedEntities.get(clientizen$renderingEntity.getUuid());
if (data != null && data.noAnimation()) {
return 0.0f;
}
}
return animationProgress;
}

@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/EntityModel;setAngles(Lnet/minecraft/entity/Entity;FFFFF)V"))
private void clienizen$disableAnimations(M instance, Entity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
AttachCommand.AttachData data = AttachCommand.attachedEntities.get(entity.getUuid());
if (data == null || !data.noAnimation()) {
//noinspection unchecked
instance.setAngles((T) entity, limbAngle, limbDistance, animationProgress, headYaw, headPitch);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.denizenscript.clientizen.render;

import com.denizenscript.clientizen.objects.EntityTag;
import com.denizenscript.clientizen.scripts.commands.AttachCommand;
import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRendererRegistrationCallback;
import net.minecraft.client.MinecraftClient;
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;
import net.minecraft.util.math.Direction;

import java.util.List;

public class ClientizenAttachedEntityFeatureRenderer<T extends Entity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {

public static void init() {
LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> {
registrationHelper.register(new ClientizenAttachedEntityFeatureRenderer<>(entityRenderer));
});
}

public ClientizenAttachedEntityFeatureRenderer(FeatureRendererContext<T, M> context) {
super(context);
}

@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
List<EntityTag> attachedEntities = AttachCommand.attachMap.get(entity.getUuid());
if (attachedEntities == null) {
return;
}
for (EntityTag attached : attachedEntities) {
matrices.push();
matrices.scale(1, 1, 1);
matrices.multiply(Direction.DOWN.getRotationQuaternion());
MinecraftClient.getInstance().getEntityRenderDispatcher().render(attached.getEntity(), 0, 0, 0, attached.getEntity().getYaw(tickDelta), tickDelta, matrices, vertexConsumers, light);
matrices.pop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.denizenscript.clientizen.scripts.commands;

import com.denizenscript.clientizen.objects.EntityTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull;
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 record AttachData(boolean noShadow, boolean noAnimation) {}

public static Map<UUID, List<EntityTag>> attachMap = new HashMap<>();
public static Map<UUID, AttachData> attachedEntities = new HashMap<>();

public AttachCommand() {
setName("attach");
setSyntax("attach [<entity>|...] [to:<entity>] (cancel) (no_shadow) (no_animation)");
setRequiredArguments(2, 5);
isProcedural = false;
autoCompile();
}

public static void autoExecute(ScriptEntry scriptEntry,
@ArgLinear @ArgName("entities") ListTag attachingEntities,
@ArgDefaultNull @ArgPrefixed @ArgName("to") EntityTag toEntity,
@ArgName("cancel") boolean cancel,
@ArgName("no_shadow") boolean noShadow,
@ArgName("no_animation") boolean noAnimation) {
if (!cancel && toEntity == null) {
throw new InvalidArgumentsRuntimeException("Must specify an entity to attach to");
}
List<EntityTag> attaching = attachingEntities.filter(EntityTag.class, scriptEntry.context);
AttachData attachData = new AttachData(noShadow, noAnimation);
if (attachMap.containsKey(toEntity.uuid)) {
attachMap.get(toEntity.uuid).addAll(attaching);
}
else {
attachMap.put(toEntity.uuid, attaching);
}
for (EntityTag entityTag : attaching) {
attachedEntities.put(entityTag.uuid, attachData);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
public class ClientizenCommandRegistry {

public static void registerCommands() {
registerCommand(NarrateCommand.class);
registerCommand(AttachCommand.class);
registerCommand(GuiCommand.class);
registerCommand(NarrateCommand.class);
registerCommand(ServerEventCommand.class);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/clientizen.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
accessWidener v2 named

accessible method net/minecraft/client/world/ClientWorld getEntityLookup ()Lnet/minecraft/world/entity/EntityLookup;

accessible method net/minecraft/client/render/entity/LivingEntityRenderer addFeature (Lnet/minecraft/client/render/entity/feature/FeatureRenderer;)Z

accessible method net/minecraft/client/render/entity/EntityRenderer getBlockLight (Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/BlockPos;)I
4 changes: 3 additions & 1 deletion src/main/resources/clientizen.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"FlagCommandMixin",
"IntPropertyAccessor",
"gui.WScrollPanelAccessor",
"gui.WTextAccessor"
"gui.WTextAccessor",
"render.EntityRenderDispatcherMixin",
"render.LivingEntityRendererMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down