Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix seat entity despawning when block 2 blocks under is air. #105

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading