diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityModel.java b/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityModel.java index 96588b3c..ba0ab80f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityModel.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityModel.java @@ -13,7 +13,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.util.math.MathHelper; -public class AirBalloonEntityModel extends EntityModel { +public class AirBalloonEntityModel extends EntityModel { private final ModelPart root; private ModelPart main; @@ -29,6 +29,7 @@ public class AirBalloonEntityModel extends EntityModel { private final List sandbags; public AirBalloonEntityModel(ModelPart root) { + super(root); this.root = root; isBurner = root.hasChild("burner"); isSandbags = root.hasChild("sandbag_ne"); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityRenderer.java index c4bb76d0..3d6269b9 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/entity/AirBalloonEntityRenderer.java @@ -7,14 +7,17 @@ import java.util.function.Predicate; 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; @@ -22,66 +25,109 @@ 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 { +public class AirBalloonEntityRenderer extends MobEntityRenderer { 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 Identifier getTexture(AirBalloonEntity entity) { - return getComponentTexture("basket/" + entity.getBasketType().id().getPath()); + public State createRenderState() { + return new State(); } @Override - protected float getLyingAngle(AirBalloonEntity entity) { - return 0; + 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 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 { + final class BalloonFeature extends FeatureRenderer { private final AirBalloonEntityModel model; - private final Predicate visibilityTest; - private final Function textureFunc; - private final BiFunction lightFunc; + private final Predicate visibilityTest; + private final Function textureFunc; + private final BiFunction lightFunc; public BalloonFeature(AirBalloonEntityModel model, - FeatureRendererContext context, - Predicate visibilityTest, - Function textureFunc, - BiFunction lightFunc) { + FeatureRendererContext context, + Predicate visibilityTest, + Function textureFunc, + BiFunction lightFunc) { super(context); this.model = model; this.visibilityTest = visibilityTest; @@ -90,16 +136,11 @@ public class AirBalloonEntityRenderer extends MobEntityRenderer getEntry(Entity entity) { - return entity.getRegistryManager().get(RegistryKeys.STATUS_EFFECT).getEntry(this); + return entity.getRegistryManager().getOrThrow(RegistryKeys.STATUS_EFFECT).getEntry(this); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java index f30752d4..1d3e0978 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java @@ -12,6 +12,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.server.world.ServerWorld; public class SunBlindnessStatusEffect extends SimpleStatusEffect { public static final int MAX_DURATION = 250; @@ -21,7 +22,7 @@ public class SunBlindnessStatusEffect extends SimpleStatusEffect { } @Override - public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { + public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) { StatusEffectInstance state = entity.getStatusEffect(getEntry(entity)); if (state == null || isSunImmune(entity)) { @@ -32,7 +33,7 @@ public class SunBlindnessStatusEffect extends SimpleStatusEffect { if (!hasSunExposure(entity)) { entity.setStatusEffect(new StatusEffectInstance(getEntry(entity), (int)(state.getDuration() * 0.8F), Math.max(1, amplifier - 1), true, false), entity); } else { - entity.damage(Living.living(entity).damageOf(amplifier == 2 ? UDamageTypes.SUN : UDamageTypes.SUNLIGHT), amplifier / 5F); + entity.damage(world, Living.living(entity).damageOf(amplifier == 2 ? UDamageTypes.SUN : UDamageTypes.SUNLIGHT), amplifier / 5F); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java index 3b8f7e9c..056880c2 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java @@ -21,6 +21,7 @@ import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.registry.RegistryKey; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.util.ActionResult; @@ -228,8 +229,10 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp setInflation(inflation); } - if (activeFuel <= 0 && !fuelItems.isEmpty()) { - activeFuel = FurnaceBlockEntity.createFuelTimeMap().getOrDefault(fuelItems.remove(0).getItem(), 0); + if (getWorld() instanceof ServerWorld sw) { + if (activeFuel <= 0 && !fuelItems.isEmpty()) { + activeFuel = sw.getFuelRegistry().getFuelTicks(fuelItems.remove(0)); + } } if (activeFuel > -6 && age % 2 == 0) { @@ -329,13 +332,13 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp } @Override - public boolean damage(DamageSource source, float amount) { + public boolean damage(ServerWorld world, DamageSource source, float amount) { if (source.getAttacker() instanceof PlayerEntity player && player.getAbilities().creativeMode) { - dropInventory(); + dropInventory(world); remove(RemovalReason.KILLED); return true; } - if (super.damage(source, amount)) { + if (super.damage(world, source, amount)) { hurtTime = 0; maxHurtTime = 0; return true; @@ -432,7 +435,9 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp if (stack.isIn(ConventionalItemTags.SHEAR_TOOLS) && hasBalloon()) { stack.damage(1, player, getSlotForHand(hand)); - dropStack(BalloonDesignComponent.set(UItems.GIANT_BALLOON.getDefaultStack(), new BalloonDesignComponent(getDesign(), true))); + if (getWorld() instanceof ServerWorld sw) { + dropStack(sw, BalloonDesignComponent.set(UItems.GIANT_BALLOON.getDefaultStack(), new BalloonDesignComponent(getDesign(), true))); + } setDesign(BalloonDesign.NONE); playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY.value(), 1, 1); if (!player.isSneaky()) { @@ -456,8 +461,8 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp return ActionResult.SUCCESS; } - if (hasBurner()) { - int fuel = FurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0); + if (hasBurner() && getWorld() instanceof ServerWorld sw) { + int fuel = sw.getFuelRegistry().getFuelTicks(stack); if (fuel > 0) { if (fuelItems.size() < 64) { fuelItems.add(stack.splitUnlessCreative(1, player)); @@ -473,17 +478,17 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp } @Override - protected void dropInventory() { - dropStack(getPickBlockStack()); - if (getWorld().getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { + protected void dropInventory(ServerWorld world) { + dropStack(world, getPickBlockStack()); + if (world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { ItemStack lantern = getStackInHand(Hand.MAIN_HAND); setStackInHand(Hand.MAIN_HAND, ItemStack.EMPTY); - dropStack(lantern); + dropStack(world, lantern); if (hasBalloon()) { - dropStack(BalloonDesignComponent.set(UItems.GIANT_BALLOON.getDefaultStack(), new BalloonDesignComponent(getDesign(), true))); + dropStack(world, BalloonDesignComponent.set(UItems.GIANT_BALLOON.getDefaultStack(), new BalloonDesignComponent(getDesign(), true))); setDesign(BalloonDesign.NONE); } - fuelItems.forEach(this::dropStack); + fuelItems.forEach(s -> dropStack(world, s)); fuelItems.clear(); } } @@ -612,20 +617,12 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp return MultiBox.of(box, boxes); } - @Override - public Box getVisibilityBoundingBox() { - if (hasBalloon()) { - return getBalloonBoundingBox().withMinY(getY()); - } - return getInteriorBoundingBox(); - } - - protected Box getInteriorBoundingBox() { + public Box getInteriorBoundingBox() { Box box = MultiBox.unbox(getBoundingBox()); return box.withMinY(box.minY - 0.05).contract(0.15, 0, 0.15); } - protected Box getBalloonBoundingBox() { + public Box getBalloonBoundingBox() { float inflation = getInflation(1); return MultiBox.unbox(getBoundingBox()) .offset(0.125, 7.3 * inflation, 0.125) diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/UTreeGen.java b/src/main/java/com/minelittlepony/unicopia/server/world/UTreeGen.java index 77f43a34..ec61fb6c 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/UTreeGen.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/UTreeGen.java @@ -30,7 +30,7 @@ public interface UTreeGen { UniformIntProvider.create(3, 6), 0.3f, UniformIntProvider.create(1, 3), - Registries.BLOCK.getOrCreateEntryList(BlockTags.MANGROVE_LOGS_CAN_GROW_THROUGH) + Registries.BLOCK.getOrThrow(BlockTags.MANGROVE_LOGS_CAN_GROW_THROUGH) ), new JungleFoliagePlacer( ConstantIntProvider.create(3), ConstantIntProvider.create(2),