Skip to content

Commit

Permalink
Fix seat entity despawning when block 2 blocks under is air. (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jab125 authored Mar 28, 2024
1 parent 2fbf303 commit 4335a28
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions common/src/main/java/com/ultreon/devices/entity/SeatEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ultreon.devices.init.DeviceEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
Expand All @@ -15,6 +16,7 @@
public class SeatEntity extends Entity
{
private double yOffset;
private BlockPos blockPos;
public SeatEntity(EntityType<SeatEntity> type, Level worldIn)
{
super(type, worldIn);
Expand All @@ -31,6 +33,7 @@ public SeatEntity(Level worldIn, BlockPos pos, double yOffset)
{
this(DeviceEntities.SEAT.get(), worldIn);
this.setPos(pos.getX() + 0.5, pos.getY() + yOffset, pos.getZ() + 0.5);
this.blockPos = pos;
}


Expand All @@ -39,6 +42,7 @@ public void setYOffset(double offset) {
}

public void setViaYOffset(BlockPos pos) {
blockPos = pos;
this.setPos(pos.getX() + 0.5, pos.getY() + yOffset, pos.getZ() + 0.5);
}

Expand All @@ -57,7 +61,7 @@ protected void defineSynchedData() {
@Override
public void tick()
{
if(!this.level().isClientSide && (!this.hasExactlyOnePlayerPassenger() || this.level().isEmptyBlock(this.getOnPos())))
if(!this.level().isClientSide && (blockPos == null || !this.hasExactlyOnePlayerPassenger() || this.level().isEmptyBlock(blockPos)))
{
this.kill();
}
Expand All @@ -79,8 +83,17 @@ public Packet<ClientGamePacketListener> getAddEntityPacket() {
// protected void.json init() {}

@Override
protected void readAdditionalSaveData(CompoundTag compound) {}
protected void readAdditionalSaveData(CompoundTag compound) {
if (compound.contains("DevicesChairX", Tag.TAG_INT) && compound.contains("DevicesChairY", Tag.TAG_INT) && compound.contains("DevicesChairZ", Tag.TAG_INT)) {
blockPos = new BlockPos(compound.getInt("DevicesChairX"), compound.getInt("DevicesChairY"), compound.getInt("DevicesChairZ"));
}
}

@Override
protected void addAdditionalSaveData(CompoundTag compound) {}
protected void addAdditionalSaveData(CompoundTag compound) {
if (blockPos == null) return;
compound.putInt("DevicesChairX", blockPos.getX());
compound.putInt("DevicesChairY", blockPos.getY());
compound.putInt("DevicesChairZ", blockPos.getZ());
}
}

0 comments on commit 4335a28

Please sign in to comment.