Skip to content

Commit

Permalink
Tweak hitbox for sideways piranha
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Jan 18, 2025
1 parent b671970 commit 60d9cff
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<? extends Monster> entityType, ServerLevelAccessor serverWorld,
MobSpawnType spawnType, BlockPos pos, RandomSource random) {
return serverWorld.getDifficulty() != Difficulty.PEACEFUL
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) {
throw new UnsupportedOperationException();
return new ClientboundAddEntityPacket(this, entity);
}

@NotNull
Expand All @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class EntityRegistry {
.nameTagOffset(-0.05F).build("mini_goomba"));
public static final DeferredHolder<EntityType<?>, EntityType<PiranhaPlantEntity>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 60d9cff

Please sign in to comment.