Skip to content

Commit

Permalink
Fix updating pos incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Jan 19, 2025
1 parent 4dc0c41 commit ac14350
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -65,8 +64,8 @@ public class PiranhaPlantEntity extends Monster implements GeoEntity {
public static final RawAnimation IDLE_ANIM = RawAnimation.begin().thenLoop("piranha_plant.idle");
public static final RawAnimation SQUASH_ANIM = RawAnimation.begin().thenPlayAndHold("piranha_plant.squash");
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private BlockPos attachedBlockPos = null;
private Direction attachedSide = null;
private BlockPos attachedBlockPos;
private Direction attachedSide;
private PiranhaPlantPart[] subEntities;
public PiranhaPlantPart head;
private float lastWidth = 1.0F;
Expand Down Expand Up @@ -193,9 +192,10 @@ public void tick() {
scale.setBaseValue(0.4F);

if (attachedBlockPos != null) {
BlockPos newPos = this.findValidBlockPos();
if (this.level().isEmptyBlock(attachedBlockPos) && !this.isHiding()) {
this.detachFromBlock();
} else if (this.getBlockAttachedTo(this.level()).isAir() && !this.isHiding()) {
} else if (newPos == null && !this.isHiding()) {
this.detachFromBlock();
} else {
this.setNoGravity(true);
Expand All @@ -204,16 +204,13 @@ public void tick() {
}

if (attachedBlockPos == null) {
BlockPos newBlock = this.findValidBlock();
if (newBlock != null)
this.attachToBlock(newBlock, this.determineAttachmentSide(newBlock));
BlockPos newPos = this.findValidBlockPos();
if (newPos != null)
this.attachToBlock(newPos, this.determineAttachmentSide(newPos));
else if (this.onGround() && this.getAttachedSide() == Direction.UP)
this.setNoGravity(false);
}

if (!this.blockPosition().equals(this.attachedBlockPos))
this.attachedBlockPos = this.blockPosition();

if (currentWidth != lastWidth || currentHeight != lastHeight) {
lastWidth = currentWidth;
lastHeight = currentHeight;
Expand Down Expand Up @@ -373,7 +370,7 @@ public void detachFromBlock() {
this.setNoGravity(false);
}

private BlockPos findValidBlock() {
private BlockPos findValidBlockPos() {
BlockPos entityPos = this.blockPosition();
for (Direction direction : Direction.values()) {
BlockPos neighborPos = entityPos.relative(direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ public EntityDimensions getDimensions(Pose pose) {

@Override
public boolean hurt(DamageSource source, float damageAmount) {
if (this.level().isClientSide && source.getDirectEntity() instanceof Player player) {
if (this.level().isClientSide && source.getDirectEntity() instanceof Player player)
this.level().sendPacketToServer(ServerboundInteractPacket.createAttackPacket(this.getParent(), player.isShiftKeyDown()));
}

return !this.isInvulnerableTo(source) && this.getParent().hurt(source, damageAmount);
}

Expand Down

0 comments on commit ac14350

Please sign in to comment.