icbm/src/main/java/icbm/gangshao/turret/mount/ESeat.java

117 lines
3 KiB
Java
Raw Normal View History

2022-11-09 22:15:45 +01:00
package icbm.gangshao.turret.mount;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import icbm.core.MainBase;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
public class ESeat extends Entity implements IEntityAdditionalSpawnData {
private TileEntity controller;
private boolean shouldSit;
public ESeat(final World par1World) {
super(par1World);
this.shouldSit = false;
this.setSize(1.0f, 1.0f);
super.noClip = true;
}
2022-11-09 22:16:55 +01:00
public ESeat(
final World par1World,
final Vector3 position,
final TileEntity controller,
final boolean sit
) {
2022-11-09 22:15:45 +01:00
this(par1World);
super.isImmuneToFire = true;
this.setPosition(position.x, position.y, position.z);
this.controller = controller;
this.shouldSit = sit;
}
2022-11-13 15:51:36 +01:00
@Override
public String getCommandSenderName() {
2022-11-09 22:15:45 +01:00
return "Seat";
}
@Override
public void writeSpawnData(final ByteBuf data) {
if (this.controller != null) {
data.writeInt(this.controller.xCoord);
data.writeInt(this.controller.yCoord);
data.writeInt(this.controller.zCoord);
} else {
MainBase.LOGGER.severe("Failed to send ridable turret packet!");
}
2022-11-09 22:16:55 +01:00
2022-11-09 22:15:45 +01:00
data.writeBoolean(this.shouldSit);
}
@Override
public void readSpawnData(final ByteBuf data) {
try {
this.controller = super.worldObj.getTileEntity(
2022-11-09 22:16:55 +01:00
data.readInt(), data.readInt(), data.readInt()
);
2022-11-09 22:15:45 +01:00
this.shouldSit = data.readBoolean();
} catch (final Exception e) {
e.printStackTrace();
}
}
@Override
public void onUpdate() {
if (this.controller == null) {
this.setDead();
return;
}
2022-11-09 22:16:55 +01:00
2022-11-09 22:15:45 +01:00
if (this.controller.isInvalid()) {
this.setDead();
return;
}
2022-11-09 22:16:55 +01:00
2022-11-10 21:41:55 +01:00
if (this.controller instanceof TTurretSeat) {
((TTurretSeat) this.controller).entityFake = this;
2022-11-09 22:15:45 +01:00
}
2022-11-09 22:16:55 +01:00
2022-11-09 22:15:45 +01:00
if (super.worldObj.isRemote && super.riddenByEntity != null) {
super.riddenByEntity.updateRiderPosition();
}
2022-11-09 22:16:55 +01:00
2022-11-09 22:15:45 +01:00
super.posY = this.controller.yCoord + 1.2;
}
@Override
public double getMountedYOffset() {
return -0.5;
}
@Override
protected boolean canTriggerWalking() {
return false;
}
@Override
public boolean shouldRiderSit() {
return this.shouldSit;
}
@Override
2022-11-09 22:16:55 +01:00
protected void entityInit() {}
2022-11-09 22:15:45 +01:00
@Override
protected void readEntityFromNBT(final NBTTagCompound nbt) {
this.shouldSit = nbt.getBoolean("shouldSit");
}
@Override
protected void writeEntityToNBT(final NBTTagCompound nbt) {
nbt.setBoolean("shouldSit", this.shouldSit);
}
}