Skip to content

Commit e775690

Browse files
committed
修复铁砧上升动画
1 parent ab165d5 commit e775690

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/main/java/dev/dubhe/anvilcraft/entity/AnimateAscendingBlockEntity.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,30 @@
55

66
import net.minecraft.core.BlockPos;
77
import net.minecraft.nbt.CompoundTag;
8+
import net.minecraft.network.protocol.Packet;
9+
import net.minecraft.network.protocol.game.ClientGamePacketListener;
810
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
911
import net.minecraft.network.syncher.EntityDataAccessor;
1012
import net.minecraft.network.syncher.EntityDataSerializers;
1113
import net.minecraft.network.syncher.SynchedEntityData;
14+
import net.minecraft.server.level.ServerEntity;
1215
import net.minecraft.world.entity.Entity;
1316
import net.minecraft.world.entity.EntityDimensions;
1417
import net.minecraft.world.entity.EntityType;
15-
import net.minecraft.world.entity.MoverType;
1618
import net.minecraft.world.entity.Pose;
1719
import net.minecraft.world.level.Level;
1820
import net.minecraft.world.level.block.Block;
1921
import net.minecraft.world.level.block.Blocks;
2022
import net.minecraft.world.level.block.state.BlockState;
2123
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
24+
import net.minecraft.world.phys.AABB;
2225
import net.minecraft.world.phys.Vec3;
2326

2427
import lombok.Getter;
2528
import org.jetbrains.annotations.NotNull;
2629

30+
import java.util.List;
31+
2732
@Getter
2833
public class AnimateAscendingBlockEntity extends Entity {
2934

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

85+
@Override
86+
public void onSyncedDataUpdated(List<SynchedEntityData.DataValue<?>> dataValues) {
87+
super.onSyncedDataUpdated(dataValues);
88+
}
89+
8090
@Override
8191
public void tick() {
8292
if (this.blockState.isAir()) {
8393
this.discard();
8494
return;
8595
}
86-
if (!this.isNoGravity()) {
87-
this.setDeltaMovement(this.getDeltaMovement().add(0.0, 0.4, 0.0));
88-
}
89-
this.move(MoverType.SELF, this.getDeltaMovement());
96+
Vec3 mov = this.getDeltaMovement().add(0.0, 0.4, 0.0);
97+
this.setDeltaMovement(mov);
98+
this.setPos(this.getX() + mov.x, this.getY() + mov.y, this.getZ() + mov.z);
9099
if (this.level().isClientSide) return;
91100
BlockPos current = this.blockPosition();
92101
BlockPos eyePos = BlockPos.containing(this.getEyePosition());
93102
BlockPos up = current.above();
94-
if (!this.level().getBlockState(up).isAir()
103+
BlockState bs = this.level().getBlockState(up);
104+
if (!bs.isAir()
95105
|| current.getY() >= getEndPos().getY()
96106
|| eyePos.getY() >= getEndPos().getY()) {
97107
this.discard();
@@ -123,6 +133,11 @@ public static void animate(
123133
level.addFreshEntity(entity);
124134
}
125135

136+
@Override
137+
@NotNull public Packet<ClientGamePacketListener> getAddEntityPacket(@NotNull ServerEntity entity) {
138+
return new ClientboundAddEntityPacket(this, entity, Block.getId(this.getBlockState()));
139+
}
140+
126141
@Override
127142
public void recreateFromPacket(@NotNull ClientboundAddEntityPacket packet) {
128143
super.recreateFromPacket(packet);
@@ -135,6 +150,11 @@ public void recreateFromPacket(@NotNull ClientboundAddEntityPacket packet) {
135150
this.setStartPos(this.blockPosition());
136151
}
137152

153+
@Override
154+
protected @NotNull AABB makeBoundingBox() {
155+
return new AABB(this.blockPosition());
156+
}
157+
138158
@Override
139159
public @NotNull EntityDimensions getDimensions(@NotNull Pose pose) {
140160
return EntityDimensions.fixed(1, 1);

0 commit comments

Comments
 (0)