Skip to content

Commit 0f4eb5e

Browse files
authored
Implement scaling for display entities (#4111)
1 parent c179926 commit 0f4eb5e

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/DisplayMixin_API.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,30 @@
2424
*/
2525
package org.spongepowered.common.mixin.api.minecraft.world.entity;
2626

27+
import net.minecraft.network.syncher.EntityDataAccessor;
2728
import net.minecraft.world.entity.Display;
29+
import org.joml.Vector3f;
2830
import org.spongepowered.api.entity.display.DisplayEntity;
31+
import org.spongepowered.asm.mixin.Final;
2932
import org.spongepowered.asm.mixin.Mixin;
33+
import org.spongepowered.asm.mixin.Shadow;
34+
import org.spongepowered.math.vector.Vector3d;
3035

3136
@Mixin(Display.class)
3237
public abstract class DisplayMixin_API extends EntityMixin_API implements DisplayEntity {
3338

39+
// @formatter:off
40+
@Shadow @Final private static EntityDataAccessor<Vector3f> DATA_SCALE_ID;
41+
// @formatter:on
42+
43+
@Override
44+
public void setScale(Vector3d scale) {
45+
entityData.set(DisplayMixin_API.DATA_SCALE_ID, new Vector3f((float) scale.x(), (float) scale.y(), (float) scale.z()));
46+
}
47+
48+
@Override
49+
public Vector3d scale() {
50+
Vector3f scale = entityData.get(DisplayMixin_API.DATA_SCALE_ID);
51+
return new Vector3d(scale.x, scale.y, scale.z);
52+
}
3453
}

src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/EntityMixin_API.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.minecraft.core.Registry;
3131
import net.minecraft.core.registries.Registries;
3232
import net.minecraft.nbt.CompoundTag;
33+
import net.minecraft.network.syncher.SynchedEntityData;
3334
import net.minecraft.resources.ResourceLocation;
3435
import net.minecraft.server.MinecraftServer;
3536
import net.minecraft.server.level.ServerPlayer;
@@ -87,6 +88,7 @@ public abstract class EntityMixin_API implements org.spongepowered.api.entity.En
8788
@Shadow protected UUID uuid;
8889
@Shadow @Final private net.minecraft.world.entity.EntityType<?> type;
8990
@Shadow private Level level;
91+
@Shadow @Final protected SynchedEntityData entityData;
9092

9193
@Shadow public abstract double shadow$getX();
9294
@Shadow public abstract double shadow$getY();

testplugins/src/main/java/org/spongepowered/test/entity/DisplayEntityTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public void onRegisterCommand(final RegisterCommandEvent<Parameterized> event) {
238238
player.world().spawnEntity(blockDisplay);
239239
blockDisplay.offer(Keys.TELEPORT_DURATION, Ticks.of(20));
240240
blockDisplay.setLocation(((ServerLocation) blockDisplay.location().add(0.0, 4.0, 0.0)));
241+
blockDisplay.setScale(new Vector3d(1.0,5.0,1.0));
241242

242243

243244
textDisplay = createEntity(player.world(), EntityTypes.TEXT_DISPLAY, centerPos, forwardDir, col7, 0);

0 commit comments

Comments
 (0)