Skip to content

Commit

Permalink
修复铁砧上升动画
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuRuoLing committed Sep 27, 2024
1 parent ab165d5 commit e775690
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@

import net.minecraft.core.BlockPos;
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.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.List;

@Getter
public class AnimateAscendingBlockEntity extends Entity {

Expand Down Expand Up @@ -77,21 +82,26 @@ protected void defineSynchedData(SynchedEntityData.@NotNull Builder builder) {
builder.define(DATA_START_POS, BlockPos.ZERO).define(DATA_END_POS, BlockPos.ZERO);
}

@Override
public void onSyncedDataUpdated(List<SynchedEntityData.DataValue<?>> dataValues) {
super.onSyncedDataUpdated(dataValues);
}

@Override
public void tick() {
if (this.blockState.isAir()) {
this.discard();
return;
}
if (!this.isNoGravity()) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0, 0.4, 0.0));
}
this.move(MoverType.SELF, this.getDeltaMovement());
Vec3 mov = this.getDeltaMovement().add(0.0, 0.4, 0.0);
this.setDeltaMovement(mov);
this.setPos(this.getX() + mov.x, this.getY() + mov.y, this.getZ() + mov.z);
if (this.level().isClientSide) return;
BlockPos current = this.blockPosition();
BlockPos eyePos = BlockPos.containing(this.getEyePosition());
BlockPos up = current.above();
if (!this.level().getBlockState(up).isAir()
BlockState bs = this.level().getBlockState(up);
if (!bs.isAir()
|| current.getY() >= getEndPos().getY()
|| eyePos.getY() >= getEndPos().getY()) {
this.discard();
Expand Down Expand Up @@ -123,6 +133,11 @@ public static void animate(
level.addFreshEntity(entity);
}

@Override
@NotNull public Packet<ClientGamePacketListener> getAddEntityPacket(@NotNull ServerEntity entity) {
return new ClientboundAddEntityPacket(this, entity, Block.getId(this.getBlockState()));
}

@Override
public void recreateFromPacket(@NotNull ClientboundAddEntityPacket packet) {
super.recreateFromPacket(packet);
Expand All @@ -135,6 +150,11 @@ public void recreateFromPacket(@NotNull ClientboundAddEntityPacket packet) {
this.setStartPos(this.blockPosition());
}

@Override
protected @NotNull AABB makeBoundingBox() {
return new AABB(this.blockPosition());
}

@Override
public @NotNull EntityDimensions getDimensions(@NotNull Pose pose) {
return EntityDimensions.fixed(1, 1);
Expand Down

0 comments on commit e775690

Please sign in to comment.