Skip to content

Commit

Permalink
More 1.21.2/3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Nov 19, 2024
1 parent d2c4b85 commit 914f149
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.util.math.MathHelper;

public class AirBalloonEntityModel extends EntityModel<AirBalloonEntity> {
public class AirBalloonEntityModel extends EntityModel<AirBalloonEntityRenderer.State> {

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

public AirBalloonEntityModel(ModelPart root) {
super(root);
this.root = root;
isBurner = root.hasChild("burner");
isSandbags = root.hasChild("sandbag_ne");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,127 @@
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.collision.MultiBox;
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity.BalloonDesign;
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity.BasketType;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.VertexRendering;
import net.minecraft.client.render.entity.*;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Items;
import net.minecraft.util.Colors;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;

public class AirBalloonEntityRenderer extends MobEntityRenderer<AirBalloonEntity, AirBalloonEntityModel> {
public class AirBalloonEntityRenderer extends MobEntityRenderer<AirBalloonEntity, AirBalloonEntityRenderer.State, AirBalloonEntityModel> {
public AirBalloonEntityRenderer(EntityRendererFactory.Context context) {
super(context, new AirBalloonEntityModel(AirBalloonEntityModel.getBasketModelData().createModel()), 0);
addFeature(new BalloonFeature(new AirBalloonEntityModel(AirBalloonEntityModel.getBurnerModelData().createModel()), this,
AirBalloonEntity::hasBurner, e -> {
return getComponentTexture(e.getStackInHand(Hand.MAIN_HAND).isOf(Items.SOUL_LANTERN) ? "soul_burner" : "burner");
}, (light, entity) -> entity.isAscending() ? 0xFF00FF : light));
i -> i.hasBurner, e -> {
return getComponentTexture(e.hasSoulFlame ? "soul_burner" : "burner");
}, (light, entity) -> entity.isAscending ? 0xFF00FF : light));
addFeature(new BalloonFeature(new AirBalloonEntityModel(AirBalloonEntityModel.getCanopyModelData().createModel()), this,
AirBalloonEntity::hasBalloon,
e -> getComponentTexture("canopy/" + e.getDesign().asString()),
(light, entity) -> entity.hasBurner() && entity.isAscending() ? light | 0x00005F : light)
i -> i.hasBalloon,
e -> getComponentTexture("canopy/" + e.design.asString()),
(light, entity) -> entity.hasBurner && entity.isAscending ? light | 0x00005F : light)
);
addFeature(new BalloonFeature(new AirBalloonEntityModel(AirBalloonEntityModel.getSandbagsModelData().createModel()),
this, e -> e.hasBalloon() && e.getInflation(1) >= 1, e -> getComponentTexture("sandbags"),
(light, entity) -> entity.hasBurner() && entity.isAscending() ? light | 0x00003F : light));
this, e -> e.hasBalloon && e.inflation >= 1, e -> getComponentTexture("sandbags"),
(light, entity) -> entity.hasBurner && entity.isAscending ? light | 0x00003F : light));
}

@Override
public void render(AirBalloonEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertices, int light) {
public void render(State entity, MatrixStack matrices, VertexConsumerProvider vertices, int light) {
matrices.push();
if (entity.hurtTime > 0) {
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(MathHelper.sin(entity.age + tickDelta) * 3));
if (entity.hurt) {
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(MathHelper.sin(entity.age) * 3));
}
super.render(entity, yaw, tickDelta, matrices, vertices, light);
super.render(entity, matrices, vertices, light);
matrices.pop();

if (MinecraftClient.getInstance().getEntityRenderDispatcher().shouldRenderHitboxes() && !entity.isInvisible() && !MinecraftClient.getInstance().hasReducedDebugInfo()) {
MultiBox.forEach(entity.getBoundingBox(), box -> {
WorldRenderer.drawBox(matrices, vertices.getBuffer(RenderLayer.getLines()), box.offset(entity.getPos().multiply(-1)), 1, 1, 1, 1);
if (MinecraftClient.getInstance().getEntityRenderDispatcher().shouldRenderHitboxes() && !entity.invisible && !MinecraftClient.getInstance().hasReducedDebugInfo()) {
MultiBox.forEach(entity.boundingBox, box -> {
VertexRendering.drawBox(matrices, vertices.getBuffer(RenderLayer.getLines()), box.offset(entity.pos.multiply(-1)), 1, 1, 1, 1);
});
}

}


@Override
public State createRenderState() {
return new State();
}

@Override
public Identifier getTexture(AirBalloonEntity entity) {
return getComponentTexture("basket/" + entity.getBasketType().id().getPath());
public void updateRenderState(AirBalloonEntity entity, State state, float tickDelta) {
super.updateRenderState(entity, state, tickDelta);
state.design = entity.getDesign();
state.basket = entity.getBasketType();
state.inflation = entity.getInflation(tickDelta);
state.hasBurner = entity.hasBurner();
state.hasBalloon = entity.hasBalloon();
state.isAscending = entity.isAscending();
state.boundingBox = entity.getBoundingBox();
state.hasSoulFlame = entity.getStackInHand(Hand.MAIN_HAND).isOf(Items.SOUL_LANTERN);
state.pos = entity.getPos();
}

public static class State extends LivingEntityRenderState {
public BalloonDesign design;
public BasketType basket;

public float inflation;
public boolean hasBurner;
public boolean hasBalloon;
public boolean isAscending;
public boolean hasSoulFlame;
public Box boundingBox;
public Vec3d pos;
}

@Override
protected float getLyingAngle(AirBalloonEntity entity) {
return 0;
protected Box getBoundingBox(AirBalloonEntity entity) {
if (entity.hasBalloon()) {
return entity.getBalloonBoundingBox().withMinY(entity.getY());
}
return entity.getInteriorBoundingBox();
}

@Override
public Identifier getTexture(State entity) {
return getComponentTexture("basket/" + entity.basket.id().getPath());
}

@Override
protected float method_3919() {
return 90.0F;
}

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

final class BalloonFeature extends FeatureRenderer<AirBalloonEntity, AirBalloonEntityModel> {
final class BalloonFeature extends FeatureRenderer<State, AirBalloonEntityModel> {
private final AirBalloonEntityModel model;
private final Predicate<AirBalloonEntity> visibilityTest;
private final Function<AirBalloonEntity, Identifier> textureFunc;
private final BiFunction<Integer, AirBalloonEntity, Integer> lightFunc;
private final Predicate<State> visibilityTest;
private final Function<State, Identifier> textureFunc;
private final BiFunction<Integer, State, Integer> lightFunc;

public BalloonFeature(AirBalloonEntityModel model,
FeatureRendererContext<AirBalloonEntity, AirBalloonEntityModel> context,
Predicate<AirBalloonEntity> visibilityTest,
Function<AirBalloonEntity, Identifier> textureFunc,
BiFunction<Integer, AirBalloonEntity, Integer> lightFunc) {
FeatureRendererContext<State, AirBalloonEntityModel> context,
Predicate<State> visibilityTest,
Function<State, Identifier> textureFunc,
BiFunction<Integer, State, Integer> lightFunc) {
super(context);
this.model = model;
this.visibilityTest = visibilityTest;
Expand All @@ -90,16 +136,11 @@ public BalloonFeature(AirBalloonEntityModel model,
}

@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertices, int light, AirBalloonEntity entity,
float limbAngle, float limbDistance, float tickDelta, float animationProgress, float yaw, float pitch) {
public void render(MatrixStack matrices, VertexConsumerProvider vertices, int light, State entity, float limbDistance, float limbAngle) {
if (visibilityTest.test(entity)) {
Identifier texture = textureFunc.apply(entity);
var model = this.model;
if (texture.getPath().indexOf("sandbags") != -1) {
model = new AirBalloonEntityModel(AirBalloonEntityModel.getSandbagsModelData().createModel());
}
render(getModel(), model, texture, matrices, vertices, lightFunc.apply(light, entity), entity, limbAngle, limbDistance, 0, yaw, pitch, tickDelta, Colors.WHITE);
render(model, textureFunc.apply(entity), matrices, vertices, lightFunc.apply(light, entity), entity, Colors.WHITE);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;

Expand All @@ -22,18 +23,18 @@ public class ButterfingersStatusEffect extends StatusEffect {
}

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

if (entity.getWorld().random.nextInt(scale / 4) == 0) {
applyInstantEffect(null, null, entity, amplifier, entity.getWorld().random.nextInt(scale));
applyInstantEffect(world, null, null, entity, amplifier, entity.getWorld().random.nextInt(scale));
}
return true;
}

@Override
public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
public void applyInstantEffect(ServerWorld world, @Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {

if (target.getWorld().isClient) {
return;
Expand All @@ -49,7 +50,7 @@ public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacke
ItemStack stack = target.getMainHandStack();
if (!stack.isEmpty()) {
target.setStackInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
target.dropStack(stack);
target.dropStack(world, stack);
target.getWorld().playSound(null, target.getBlockPos(), USounds.ENTITY_GENERIC_BUTTER_FINGERS, target.getSoundCategory());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.world.WorldEvents;

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

CorruptInfluenceStatusEffect(int color) {
super(StatusEffectCategory.NEUTRAL, color, false);
addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, CORRUPTION_MODIFIER_ID, 15, EntityAttributeModifier.Operation.ADD_VALUE);
addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, CORRUPTION_MODIFIER_ID, 10, EntityAttributeModifier.Operation.ADD_VALUE);
addAttributeModifier(EntityAttributes.ATTACK_DAMAGE, CORRUPTION_MODIFIER_ID, 15, EntityAttributeModifier.Operation.ADD_VALUE);
addAttributeModifier(EntityAttributes.ATTACK_SPEED, CORRUPTION_MODIFIER_ID, 10, EntityAttributeModifier.Operation.ADD_VALUE);
}

@Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {

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


} else if (entity.age % 2000 == 0) {
entity.damage(Living.living(entity).damageOf(UDamageTypes.ALICORN_AMULET), 2);
entity.damage(world, Living.living(entity).damageOf(UDamageTypes.ALICORN_AMULET), 2);
}

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

public static void reproduce(HostileEntity mob) {
HostileEntity clone = (HostileEntity)mob.getType().create(mob.getWorld());
HostileEntity clone = (HostileEntity)mob.getType().create(mob.getWorld(), SpawnReason.BREEDING);
clone.copyPositionAndRotation(mob);
clone.takeKnockback(0.1, 0.5, 0.5);
mob.takeKnockback(0.1, -0.5, -0.5);
if (mob.getRandom().nextInt(4) != 0) {
mob.clearStatusEffects();
} else {
if (clone.getAttributes().hasAttribute(EntityAttributes.GENERIC_MAX_HEALTH)) {
if (clone.getAttributes().hasAttribute(EntityAttributes.MAX_HEALTH)) {
float maxHealthDifference = mob.getMaxHealth() - clone.getMaxHealth();
clone.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 900000, 2));
clone.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH)
clone.getAttributeInstance(EntityAttributes.MAX_HEALTH)
.addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, maxHealthDifference + 1, EntityAttributeModifier.Operation.ADD_VALUE));
}
if (clone.getAttributes().hasAttribute(EntityAttributes.GENERIC_ATTACK_DAMAGE)) {
clone.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE)
.addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, mob.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE));
if (clone.getAttributes().hasAttribute(EntityAttributes.ATTACK_DAMAGE)) {
clone.getAttributeInstance(EntityAttributes.ATTACK_DAMAGE)
.addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, mob.getAttributeValue(EntityAttributes.ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.Nullable;

import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.util.TypedActionResult;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.FoodComponent;
Expand All @@ -15,8 +16,8 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.TypedActionResult;

public class FoodPoisoningStatusEffect extends StatusEffect {

Expand All @@ -25,12 +26,8 @@ public class FoodPoisoningStatusEffect extends StatusEffect {
}

@Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
if (entity.getWorld().isClient) {
return true;
}

boolean showParticles = entity.getStatusEffect(entity.getRegistryManager().get(RegistryKeys.STATUS_EFFECT).getEntry(this)).shouldShowParticles();
public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
boolean showParticles = entity.getStatusEffect(entity.getRegistryManager().getOrThrow(RegistryKeys.STATUS_EFFECT).getEntry(this)).shouldShowParticles();

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

if (EffectUtils.isPoisoned(entity) && entity.getRandom().nextInt(12) == 0 && !entity.hasStatusEffect(StatusEffects.POISON)) {
StatusEffects.POISON.value().applyUpdateEffect(entity, 1);
StatusEffects.POISON.value().applyUpdateEffect(world, entity, 1);
}

return true;
}

@Override
public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
applyUpdateEffect(target, amplifier);
public void applyInstantEffect(ServerWorld world, @Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
applyUpdateEffect(world, target, amplifier);
}

@Override
Expand Down
Loading

0 comments on commit 914f149

Please sign in to comment.