Skip to content

Commit 914f149

Browse files
committed
More 1.21.2/3 updates
1 parent d2c4b85 commit 914f149

10 files changed

+135
-94
lines changed

src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityModel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import net.minecraft.entity.vehicle.BoatEntity;
1414
import net.minecraft.util.math.MathHelper;
1515

16-
public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
16+
public class AirBalloonEntityModel extends EntityModel<AirBalloonEntityRenderer.State> {
1717

1818
private final ModelPart root;
1919
private ModelPart main;
@@ -29,6 +29,7 @@ public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
2929
private final List<ModelPart> sandbags;
3030

3131
public AirBalloonEntityModel(ModelPart root) {
32+
super(root);
3233
this.root = root;
3334
isBurner = root.hasChild("burner");
3435
isSandbags = root.hasChild("sandbag_ne");

src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityRenderer.java

+78-37
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,127 @@
77
import com.minelittlepony.unicopia.Unicopia;
88
import com.minelittlepony.unicopia.entity.collision.MultiBox;
99
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
10+
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity.BalloonDesign;
11+
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity.BasketType;
1012

1113
import net.minecraft.client.MinecraftClient;
1214
import net.minecraft.client.render.RenderLayer;
1315
import net.minecraft.client.render.VertexConsumerProvider;
14-
import net.minecraft.client.render.WorldRenderer;
16+
import net.minecraft.client.render.VertexRendering;
1517
import net.minecraft.client.render.entity.*;
1618
import net.minecraft.client.render.entity.feature.FeatureRenderer;
1719
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
20+
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
1821
import net.minecraft.client.util.math.MatrixStack;
1922
import net.minecraft.item.Items;
2023
import net.minecraft.util.Colors;
2124
import net.minecraft.util.Hand;
2225
import net.minecraft.util.Identifier;
2326
import net.minecraft.util.math.MathHelper;
2427
import net.minecraft.util.math.RotationAxis;
28+
import net.minecraft.util.math.Box;
29+
import net.minecraft.util.math.Vec3d;
2530

26-
public class AirBalloonEntityRenderer extends MobEntityRenderer<AirBalloonEntity, AirBalloonEntityModel> {
31+
public class AirBalloonEntityRenderer extends MobEntityRenderer<AirBalloonEntity, AirBalloonEntityRenderer.State, AirBalloonEntityModel> {
2732
public AirBalloonEntityRenderer(EntityRendererFactory.Context context) {
2833
super(context, new AirBalloonEntityModel(AirBalloonEntityModel.getBasketModelData().createModel()), 0);
2934
addFeature(new BalloonFeature(new AirBalloonEntityModel(AirBalloonEntityModel.getBurnerModelData().createModel()), this,
30-
AirBalloonEntity::hasBurner, e -> {
31-
return getComponentTexture(e.getStackInHand(Hand.MAIN_HAND).isOf(Items.SOUL_LANTERN) ? "soul_burner" : "burner");
32-
}, (light, entity) -> entity.isAscending() ? 0xFF00FF : light));
35+
i -> i.hasBurner, e -> {
36+
return getComponentTexture(e.hasSoulFlame ? "soul_burner" : "burner");
37+
}, (light, entity) -> entity.isAscending ? 0xFF00FF : light));
3338
addFeature(new BalloonFeature(new AirBalloonEntityModel(AirBalloonEntityModel.getCanopyModelData().createModel()), this,
34-
AirBalloonEntity::hasBalloon,
35-
e -> getComponentTexture("canopy/" + e.getDesign().asString()),
36-
(light, entity) -> entity.hasBurner() && entity.isAscending() ? light | 0x00005F : light)
39+
i -> i.hasBalloon,
40+
e -> getComponentTexture("canopy/" + e.design.asString()),
41+
(light, entity) -> entity.hasBurner && entity.isAscending ? light | 0x00005F : light)
3742
);
3843
addFeature(new BalloonFeature(new AirBalloonEntityModel(AirBalloonEntityModel.getSandbagsModelData().createModel()),
39-
this, e -> e.hasBalloon() && e.getInflation(1) >= 1, e -> getComponentTexture("sandbags"),
40-
(light, entity) -> entity.hasBurner() && entity.isAscending() ? light | 0x00003F : light));
44+
this, e -> e.hasBalloon && e.inflation >= 1, e -> getComponentTexture("sandbags"),
45+
(light, entity) -> entity.hasBurner && entity.isAscending ? light | 0x00003F : light));
4146
}
4247

4348
@Override
44-
public void render(AirBalloonEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertices, int light) {
49+
public void render(State entity, MatrixStack matrices, VertexConsumerProvider vertices, int light) {
4550
matrices.push();
46-
if (entity.hurtTime > 0) {
47-
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(MathHelper.sin(entity.age + tickDelta) * 3));
51+
if (entity.hurt) {
52+
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(MathHelper.sin(entity.age) * 3));
4853
}
49-
super.render(entity, yaw, tickDelta, matrices, vertices, light);
54+
super.render(entity, matrices, vertices, light);
5055
matrices.pop();
5156

52-
if (MinecraftClient.getInstance().getEntityRenderDispatcher().shouldRenderHitboxes() && !entity.isInvisible() && !MinecraftClient.getInstance().hasReducedDebugInfo()) {
53-
MultiBox.forEach(entity.getBoundingBox(), box -> {
54-
WorldRenderer.drawBox(matrices, vertices.getBuffer(RenderLayer.getLines()), box.offset(entity.getPos().multiply(-1)), 1, 1, 1, 1);
57+
if (MinecraftClient.getInstance().getEntityRenderDispatcher().shouldRenderHitboxes() && !entity.invisible && !MinecraftClient.getInstance().hasReducedDebugInfo()) {
58+
MultiBox.forEach(entity.boundingBox, box -> {
59+
VertexRendering.drawBox(matrices, vertices.getBuffer(RenderLayer.getLines()), box.offset(entity.pos.multiply(-1)), 1, 1, 1, 1);
5560
});
5661
}
5762

5863
}
5964

65+
66+
@Override
67+
public State createRenderState() {
68+
return new State();
69+
}
70+
6071
@Override
61-
public Identifier getTexture(AirBalloonEntity entity) {
62-
return getComponentTexture("basket/" + entity.getBasketType().id().getPath());
72+
public void updateRenderState(AirBalloonEntity entity, State state, float tickDelta) {
73+
super.updateRenderState(entity, state, tickDelta);
74+
state.design = entity.getDesign();
75+
state.basket = entity.getBasketType();
76+
state.inflation = entity.getInflation(tickDelta);
77+
state.hasBurner = entity.hasBurner();
78+
state.hasBalloon = entity.hasBalloon();
79+
state.isAscending = entity.isAscending();
80+
state.boundingBox = entity.getBoundingBox();
81+
state.hasSoulFlame = entity.getStackInHand(Hand.MAIN_HAND).isOf(Items.SOUL_LANTERN);
82+
state.pos = entity.getPos();
83+
}
84+
85+
public static class State extends LivingEntityRenderState {
86+
public BalloonDesign design;
87+
public BasketType basket;
88+
89+
public float inflation;
90+
public boolean hasBurner;
91+
public boolean hasBalloon;
92+
public boolean isAscending;
93+
public boolean hasSoulFlame;
94+
public Box boundingBox;
95+
public Vec3d pos;
6396
}
6497

6598
@Override
66-
protected float getLyingAngle(AirBalloonEntity entity) {
67-
return 0;
99+
protected Box getBoundingBox(AirBalloonEntity entity) {
100+
if (entity.hasBalloon()) {
101+
return entity.getBalloonBoundingBox().withMinY(entity.getY());
102+
}
103+
return entity.getInteriorBoundingBox();
104+
}
105+
106+
@Override
107+
public Identifier getTexture(State entity) {
108+
return getComponentTexture("basket/" + entity.basket.id().getPath());
109+
}
110+
111+
@Override
112+
protected float method_3919() {
113+
return 90.0F;
68114
}
69115

70116
private Identifier getComponentTexture(String componentName) {
71117
return Unicopia.id("textures/entity/air_balloon/" + componentName + ".png");
72118
}
73119

74-
final class BalloonFeature extends FeatureRenderer<AirBalloonEntity, AirBalloonEntityModel> {
120+
final class BalloonFeature extends FeatureRenderer<State, AirBalloonEntityModel> {
75121
private final AirBalloonEntityModel model;
76-
private final Predicate<AirBalloonEntity> visibilityTest;
77-
private final Function<AirBalloonEntity, Identifier> textureFunc;
78-
private final BiFunction<Integer, AirBalloonEntity, Integer> lightFunc;
122+
private final Predicate<State> visibilityTest;
123+
private final Function<State, Identifier> textureFunc;
124+
private final BiFunction<Integer, State, Integer> lightFunc;
79125

80126
public BalloonFeature(AirBalloonEntityModel model,
81-
FeatureRendererContext<AirBalloonEntity, AirBalloonEntityModel> context,
82-
Predicate<AirBalloonEntity> visibilityTest,
83-
Function<AirBalloonEntity, Identifier> textureFunc,
84-
BiFunction<Integer, AirBalloonEntity, Integer> lightFunc) {
127+
FeatureRendererContext<State, AirBalloonEntityModel> context,
128+
Predicate<State> visibilityTest,
129+
Function<State, Identifier> textureFunc,
130+
BiFunction<Integer, State, Integer> lightFunc) {
85131
super(context);
86132
this.model = model;
87133
this.visibilityTest = visibilityTest;
@@ -90,16 +136,11 @@ public BalloonFeature(AirBalloonEntityModel model,
90136
}
91137

92138
@Override
93-
public void render(MatrixStack matrices, VertexConsumerProvider vertices, int light, AirBalloonEntity entity,
94-
float limbAngle, float limbDistance, float tickDelta, float animationProgress, float yaw, float pitch) {
139+
public void render(MatrixStack matrices, VertexConsumerProvider vertices, int light, State entity, float limbDistance, float limbAngle) {
95140
if (visibilityTest.test(entity)) {
96-
Identifier texture = textureFunc.apply(entity);
97-
var model = this.model;
98-
if (texture.getPath().indexOf("sandbags") != -1) {
99-
model = new AirBalloonEntityModel(AirBalloonEntityModel.getSandbagsModelData().createModel());
100-
}
101-
render(getModel(), model, texture, matrices, vertices, lightFunc.apply(light, entity), entity, limbAngle, limbDistance, 0, yaw, pitch, tickDelta, Colors.WHITE);
141+
render(model, textureFunc.apply(entity), matrices, vertices, lightFunc.apply(light, entity), entity, Colors.WHITE);
102142
}
103143
}
104144
}
145+
105146
}

src/main/java/com/minelittlepony/unicopia/entity/effect/ButterfingersStatusEffect.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.item.ItemStack;
1313
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
1414
import net.minecraft.server.network.ServerPlayerEntity;
15+
import net.minecraft.server.world.ServerWorld;
1516
import net.minecraft.util.Hand;
1617
import net.minecraft.util.math.MathHelper;
1718

@@ -22,18 +23,18 @@ public class ButterfingersStatusEffect extends StatusEffect {
2223
}
2324

2425
@Override
25-
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
26+
public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
2627
amplifier = MathHelper.clamp(amplifier, 0, 5);
2728
final int scale = 500 + (int)(((5 - amplifier) / 5F) * 900);
2829

2930
if (entity.getWorld().random.nextInt(scale / 4) == 0) {
30-
applyInstantEffect(null, null, entity, amplifier, entity.getWorld().random.nextInt(scale));
31+
applyInstantEffect(world, null, null, entity, amplifier, entity.getWorld().random.nextInt(scale));
3132
}
3233
return true;
3334
}
3435

3536
@Override
36-
public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
37+
public void applyInstantEffect(ServerWorld world, @Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
3738

3839
if (target.getWorld().isClient) {
3940
return;
@@ -49,7 +50,7 @@ public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacke
4950
ItemStack stack = target.getMainHandStack();
5051
if (!stack.isEmpty()) {
5152
target.setStackInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
52-
target.dropStack(stack);
53+
target.dropStack(world, stack);
5354
target.getWorld().playSound(null, target.getBlockPos(), USounds.ENTITY_GENERIC_BUTTER_FINGERS, target.getSoundCategory());
5455
}
5556
}

src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
88

99
import net.minecraft.entity.LivingEntity;
10+
import net.minecraft.entity.SpawnReason;
1011
import net.minecraft.entity.attribute.EntityAttributeModifier;
1112
import net.minecraft.entity.attribute.EntityAttributes;
1213
import net.minecraft.entity.effect.StatusEffectCategory;
1314
import net.minecraft.entity.effect.StatusEffectInstance;
1415
import net.minecraft.entity.effect.StatusEffects;
1516
import net.minecraft.entity.mob.HostileEntity;
1617
import net.minecraft.entity.player.PlayerEntity;
18+
import net.minecraft.server.world.ServerWorld;
1719
import net.minecraft.util.Identifier;
1820
import net.minecraft.world.WorldEvents;
1921

@@ -22,12 +24,12 @@ public class CorruptInfluenceStatusEffect extends SimpleStatusEffect {
2224

2325
CorruptInfluenceStatusEffect(int color) {
2426
super(StatusEffectCategory.NEUTRAL, color, false);
25-
addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, CORRUPTION_MODIFIER_ID, 15, EntityAttributeModifier.Operation.ADD_VALUE);
26-
addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, CORRUPTION_MODIFIER_ID, 10, EntityAttributeModifier.Operation.ADD_VALUE);
27+
addAttributeModifier(EntityAttributes.ATTACK_DAMAGE, CORRUPTION_MODIFIER_ID, 15, EntityAttributeModifier.Operation.ADD_VALUE);
28+
addAttributeModifier(EntityAttributes.ATTACK_SPEED, CORRUPTION_MODIFIER_ID, 10, EntityAttributeModifier.Operation.ADD_VALUE);
2729
}
2830

2931
@Override
30-
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
32+
public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
3133

3234
if (entity.getWorld().isClient) {
3335
return true;
@@ -53,7 +55,7 @@ public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
5355

5456

5557
} else if (entity.age % 2000 == 0) {
56-
entity.damage(Living.living(entity).damageOf(UDamageTypes.ALICORN_AMULET), 2);
58+
entity.damage(world, Living.living(entity).damageOf(UDamageTypes.ALICORN_AMULET), 2);
5759
}
5860

5961
return true;
@@ -65,22 +67,22 @@ public boolean canApplyUpdateEffect(int duration, int amplifier) {
6567
}
6668

6769
public static void reproduce(HostileEntity mob) {
68-
HostileEntity clone = (HostileEntity)mob.getType().create(mob.getWorld());
70+
HostileEntity clone = (HostileEntity)mob.getType().create(mob.getWorld(), SpawnReason.BREEDING);
6971
clone.copyPositionAndRotation(mob);
7072
clone.takeKnockback(0.1, 0.5, 0.5);
7173
mob.takeKnockback(0.1, -0.5, -0.5);
7274
if (mob.getRandom().nextInt(4) != 0) {
7375
mob.clearStatusEffects();
7476
} else {
75-
if (clone.getAttributes().hasAttribute(EntityAttributes.GENERIC_MAX_HEALTH)) {
77+
if (clone.getAttributes().hasAttribute(EntityAttributes.MAX_HEALTH)) {
7678
float maxHealthDifference = mob.getMaxHealth() - clone.getMaxHealth();
7779
clone.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 900000, 2));
78-
clone.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH)
80+
clone.getAttributeInstance(EntityAttributes.MAX_HEALTH)
7981
.addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, maxHealthDifference + 1, EntityAttributeModifier.Operation.ADD_VALUE));
8082
}
81-
if (clone.getAttributes().hasAttribute(EntityAttributes.GENERIC_ATTACK_DAMAGE)) {
82-
clone.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE)
83-
.addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, mob.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE));
83+
if (clone.getAttributes().hasAttribute(EntityAttributes.ATTACK_DAMAGE)) {
84+
clone.getAttributeInstance(EntityAttributes.ATTACK_DAMAGE)
85+
.addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, mob.getAttributeValue(EntityAttributes.ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE));
8486
}
8587
}
8688

src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.jetbrains.annotations.Nullable;
44

55
import com.minelittlepony.unicopia.USounds;
6+
import com.minelittlepony.unicopia.util.TypedActionResult;
67

78
import net.minecraft.component.DataComponentTypes;
89
import net.minecraft.component.type.FoodComponent;
@@ -15,8 +16,8 @@
1516
import net.minecraft.entity.player.PlayerEntity;
1617
import net.minecraft.item.ItemStack;
1718
import net.minecraft.registry.RegistryKeys;
19+
import net.minecraft.server.world.ServerWorld;
1820
import net.minecraft.sound.SoundCategory;
19-
import net.minecraft.util.TypedActionResult;
2021

2122
public class FoodPoisoningStatusEffect extends StatusEffect {
2223

@@ -25,12 +26,8 @@ public class FoodPoisoningStatusEffect extends StatusEffect {
2526
}
2627

2728
@Override
28-
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
29-
if (entity.getWorld().isClient) {
30-
return true;
31-
}
32-
33-
boolean showParticles = entity.getStatusEffect(entity.getRegistryManager().get(RegistryKeys.STATUS_EFFECT).getEntry(this)).shouldShowParticles();
29+
public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
30+
boolean showParticles = entity.getStatusEffect(entity.getRegistryManager().getOrThrow(RegistryKeys.STATUS_EFFECT).getEntry(this)).shouldShowParticles();
3431

3532
if (!entity.hasStatusEffect(StatusEffects.NAUSEA) && entity.getRandom().nextInt(12) == 0) {
3633
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, showParticles, false));
@@ -41,15 +38,15 @@ public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
4138
}
4239

4340
if (EffectUtils.isPoisoned(entity) && entity.getRandom().nextInt(12) == 0 && !entity.hasStatusEffect(StatusEffects.POISON)) {
44-
StatusEffects.POISON.value().applyUpdateEffect(entity, 1);
41+
StatusEffects.POISON.value().applyUpdateEffect(world, entity, 1);
4542
}
4643

4744
return true;
4845
}
4946

5047
@Override
51-
public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
52-
applyUpdateEffect(target, amplifier);
48+
public void applyInstantEffect(ServerWorld world, @Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
49+
applyUpdateEffect(world, target, amplifier);
5350
}
5451

5552
@Override

0 commit comments

Comments
 (0)