Skip to content

Commit

Permalink
Draft for event
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyces committed Oct 31, 2024
1 parent 62eb61a commit 0ab23c6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
if (flag) {
p_361028_.nameTag = this.getNameTag(p_362104_);
p_361028_.nameTagAttachment = p_362104_.getAttachments().getNullable(EntityAttachment.NAME_TAG, 0, p_362104_.getYRot(p_362204_));
@@ -302,5 +_,7 @@
@@ -302,5 +_,9 @@
}

p_361028_.displayFireAnimation = p_362104_.displayFireAnimation();
+
+ p_361028_.partialTick = p_362204_;
+ net.neoforged.neoforge.attachment.AttachmentInternals.copyEntityAttachments(p_362104_, p_362104_, false);
+ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.client.event.UpdateRenderStateEvent<>(p_362104_, p_361028_));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
--- a/net/minecraft/client/renderer/entity/state/EntityRenderState.java
+++ b/net/minecraft/client/renderer/entity/state/EntityRenderState.java
@@ -7,7 +_,7 @@
import net.neoforged.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
-public class EntityRenderState {
+public class EntityRenderState extends net.neoforged.neoforge.attachment.AttachmentHolder {
public double x;
public double y;
public double z;
@@ -27,6 +_,7 @@
public Vec3 nameTagAttachment;
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static void copyEntityAttachments(Entity from, Entity to, boolean isDeath
copyAttachments(from.registryAccess(), from, to, isDeath ? type -> type.copyOnDeath : type -> true);
}

public static <H extends AttachmentHolder> void copyEntityAttachments(Entity from, H to, boolean isDeath) {
copyAttachments(from.registryAccess(), from, to, isDeath ? type -> type.copyOnDeath : type -> true);
}

@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event) {
event.getEntity().copyAttachmentsFrom(event.getOriginal(), event.isWasDeath());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.client.event;

import net.minecraft.client.renderer.entity.state.EntityRenderState;
import net.minecraft.world.entity.Entity;
import net.neoforged.bus.api.Event;
import org.jetbrains.annotations.ApiStatus;

public class UpdateRenderStateEvent<E extends Entity, S extends EntityRenderState> extends Event {
private final E entity;
private final S renderState;

@ApiStatus.Internal
public UpdateRenderStateEvent(E entity, S renderState) {
this.entity = entity;
this.renderState = renderState;
}

public E getEntity() {
return entity;
}

public S getCurrentState() {
return renderState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.SectionPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Blocks;
Expand All @@ -19,6 +20,7 @@
import net.neoforged.neoforge.client.event.ClientPlayerChangeGameTypeEvent;
import net.neoforged.neoforge.client.event.RegisterRenderBuffersEvent;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import net.neoforged.neoforge.client.event.RenderPlayerEvent;
import net.neoforged.neoforge.client.model.data.ModelData;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.testframework.DynamicTest;
Expand Down Expand Up @@ -103,4 +105,21 @@ static void addSectionGeometryTest(final ClientChatEvent chatEvent, final Dynami
test.requestConfirmation(player, Component.literal("Is a diamond block rendered above you?"));
}
}

@TestHolder(description = { "" }, enabledByDefault = true)
static void updateRenderState(final DynamicTest test) {
var testAttachment = test.registrationHelper().attachments().registerSimpleAttachment("test", () -> 3);
test.whenEnabled(listeners -> {
listeners.forge().addListener((RenderPlayerEvent.Post event) -> {
int numRender = event.getRenderState().getData(testAttachment);
var poseStack = event.getPoseStack();
poseStack.pushPose();
for (int i = 0; i < numRender; i++) {
poseStack.translate(0, 1, 0);
Minecraft.getInstance().getBlockRenderer().renderSingleBlock(Blocks.CALCITE.defaultBlockState(), poseStack, event.getMultiBufferSource(), event.getPackedLight(), OverlayTexture.NO_OVERLAY, ModelData.EMPTY, RenderType.solid());
}
poseStack.popPose();
});
});
}
}

0 comments on commit 0ab23c6

Please sign in to comment.