diff --git a/src/main/java/com/wenxin2/marioverse/entities/PiranhaPlantEntity.java b/src/main/java/com/wenxin2/marioverse/entities/PiranhaPlantEntity.java index f942fc5..b910055 100644 --- a/src/main/java/com/wenxin2/marioverse/entities/PiranhaPlantEntity.java +++ b/src/main/java/com/wenxin2/marioverse/entities/PiranhaPlantEntity.java @@ -23,6 +23,7 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MobSpawnType; @@ -67,8 +68,8 @@ public class PiranhaPlantEntity extends Monster implements GeoEntity { private Direction attachedSide = null; private PiranhaPlantPart[] subEntities; public PiranhaPlantPart head; - private float lastWidth = -1.0F; - private float lastHeight = -1.0F; + private float lastWidth = 1.0F; + private float lastHeight = 1.0F; @Nullable private BlockPos targetPosition; @@ -223,6 +224,19 @@ public void baseTick() { this.handleAirSupply(i); } + @Override + protected EntityDimensions getDefaultDimensions(Pose pose) { + Direction attachedSide = this.getAttachedSide(); + + if (attachedSide == Direction.NORTH || attachedSide == Direction.SOUTH + || attachedSide == Direction.EAST || attachedSide == Direction.WEST) { + return EntityDimensions.scalable(1.0F, 1.0F); + } else if (attachedSide == Direction.DOWN) + return EntityDimensions.scalable(1.0F, 1.0F).withEyeHeight(-0.9F); + + return super.getDefaultDimensions(pose); + } + public static boolean checkPiranhaPlantSpawnRules(EntityType entityType, ServerLevelAccessor serverWorld, MobSpawnType spawnType, BlockPos pos, RandomSource random) { return serverWorld.getDifficulty() != Difficulty.PEACEFUL @@ -286,22 +300,13 @@ public void aiStep() { Direction attachedSide = this.getAttachedSide(); if (attachedSide != null) { Vec3 offset = calculateHitboxOffset(attachedSide); - this.tickPart(this.head, offset.x, offset.y, offset.z); + if (attachedSide == Direction.NORTH || attachedSide == Direction.SOUTH + || attachedSide == Direction.EAST || attachedSide == Direction.WEST + || attachedSide == Direction.DOWN) + this.tickPart(this.head, offset.x, offset.y, offset.z); } } - public boolean hurt(DamageSource source, float damageAmount) { - if (damageAmount < 0.01F) { - return false; - } - this.reallyHurt(source, damageAmount); - return true; - } - - protected void reallyHurt(DamageSource source, float damageAmount) { - super.hurt(source, damageAmount); - } - private void tickPart(PiranhaPlantPart part, double offsetX, double offsetY, double offsetZ) { part.setPos(this.getX() + offsetX, this.getY() + offsetY, this.getZ() + offsetZ); } @@ -315,7 +320,7 @@ private Vec3 calculateHitboxOffset(Direction attachedSide) { double width = this.getWidthAttribute(); double height = this.getHeightAttribute(); double offsetX = 0.0; - double offsetY = 0.5 * height; + double offsetY = 0.0; double offsetZ = 0.0; switch (attachedSide) { @@ -435,7 +440,7 @@ public void hideInBlock() { return; } - Direction[] prioritizedDirections = new Direction[]{Direction.UP, Direction.DOWN, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST}; + Direction[] prioritizedDirections = new Direction[]{Direction.UP, Direction.DOWN, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST}; if (this.isHiding()) { // Handle emerging from hiding diff --git a/src/main/java/com/wenxin2/marioverse/entities/part_entities/PiranhaPlantPart.java b/src/main/java/com/wenxin2/marioverse/entities/part_entities/PiranhaPlantPart.java index 3194c53..0e2ad70 100644 --- a/src/main/java/com/wenxin2/marioverse/entities/part_entities/PiranhaPlantPart.java +++ b/src/main/java/com/wenxin2/marioverse/entities/part_entities/PiranhaPlantPart.java @@ -7,14 +7,16 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerEntity; import net.minecraft.world.InteractionHand; -import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Pose; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.entity.PartEntity; import org.jetbrains.annotations.NotNull; @@ -58,15 +60,10 @@ public void baseTick() { this.checkForCollisions(); } - @Override - public boolean hurt(DamageSource source, float damageAmount) { - return !this.isInvulnerableTo(source) && this.parentMob.hurt(source, damageAmount); - } - @NotNull @Override public Packet getAddEntityPacket(ServerEntity entity) { - throw new UnsupportedOperationException(); + return new ClientboundAddEntityPacket(this, entity); } @NotNull @@ -75,12 +72,6 @@ public EntityDimensions getDimensions(Pose pose) { return this.size; } - @Override - public void refreshDimensions() { - super.refreshDimensions(); - this.setBoundingBox(this.size.makeBoundingBox(this.position())); - } - @Override public boolean canBeHitByProjectile() { return this.isAlive(); @@ -93,6 +84,21 @@ public void push(final Entity entity) { } } + @Override + public boolean isPushable() { + return false; + } + + @Override + public boolean isPushedByFluid() { + return false; + } + + @Override + public InteractionResult interact(Player p_19978_, InteractionHand p_19979_) { + return super.interact(p_19978_, p_19979_); + } + @Override public boolean canCollideWith(final Entity entity) { return !this.isPassengerOfSameVehicle(entity); diff --git a/src/main/java/com/wenxin2/marioverse/init/EntityRegistry.java b/src/main/java/com/wenxin2/marioverse/init/EntityRegistry.java index 41bdc18..fee723c 100644 --- a/src/main/java/com/wenxin2/marioverse/init/EntityRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/EntityRegistry.java @@ -59,7 +59,7 @@ public class EntityRegistry { .nameTagOffset(-0.05F).build("mini_goomba")); public static final DeferredHolder, EntityType> PIRANHA_PLANT = Marioverse.ENTITIES.register("piranha_plant", () -> EntityType.Builder.of(PiranhaPlantEntity::new, MobCategory.MONSTER) - .sized(1.0F, 1.0F).eyeHeight(0.9F).ridingOffset(0.1F).build("piranha_plant")); + .sized(1.0F, 2.3125F).eyeHeight(2.0F).ridingOffset(0.1F).build("piranha_plant")); @SubscribeEvent public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) { diff --git a/src/main/java/com/wenxin2/marioverse/items/BetterSpawnEggItem.java b/src/main/java/com/wenxin2/marioverse/items/BetterSpawnEggItem.java index bd0d286..a23577b 100644 --- a/src/main/java/com/wenxin2/marioverse/items/BetterSpawnEggItem.java +++ b/src/main/java/com/wenxin2/marioverse/items/BetterSpawnEggItem.java @@ -45,8 +45,7 @@ public InteractionResult useOn(UseOnContext context) { } else { EntityType entityType = this.getType(stack); - BlockPos spawnPos = context.getClickedFace() == Direction.DOWN - ? (new BlockPos(pos.getX(), (int) (pos.getY() - entityType.getHeight()), pos.getZ())) : pos.relative(context.getClickedFace()); + BlockPos spawnPos = pos.relative(context.getClickedFace()); Entity entity = entityType.spawn((ServerLevel) world, stack, context.getPlayer(), spawnPos, MobSpawnType.SPAWN_EGG, true, direction == Direction.UP);