2022-05-03 23:09:21 -05:00
|
|
|
package noppes.npcs.scripted;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.api.IBlock;
|
|
|
|
|
import noppes.npcs.api.INbt;
|
|
|
|
|
import noppes.npcs.api.IPos;
|
|
|
|
|
import noppes.npcs.api.ITileEntity;
|
|
|
|
|
import noppes.npcs.api.IWorld;
|
2022-05-03 23:09:21 -05:00
|
|
|
|
|
|
|
|
public class ScriptTileEntity<T extends TileEntity> implements ITileEntity {
|
|
|
|
|
protected T tileEntity;
|
2022-11-06 01:25:28 -06:00
|
|
|
protected IWorld world;
|
2022-05-03 23:09:21 -05:00
|
|
|
|
2022-11-06 01:25:28 -06:00
|
|
|
public ScriptTileEntity(T tileEntity) {
|
|
|
|
|
this.tileEntity = tileEntity;
|
|
|
|
|
this.world = NpcAPI.Instance().getIWorld(tileEntity.getWorldObj());
|
|
|
|
|
}
|
2022-05-03 23:09:21 -05:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public int getBlockMetadata() {
|
2022-05-03 23:09:21 -05:00
|
|
|
return tileEntity.getBlockMetadata();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public IWorld getWorld() {
|
2022-11-06 01:25:28 -06:00
|
|
|
return world;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setWorld(IWorld world) {
|
|
|
|
|
this.tileEntity.setWorldObj(world.getMCWorld());
|
|
|
|
|
this.world = world;
|
2022-05-03 23:09:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TileEntity getMCTileEntity() {
|
|
|
|
|
return this.tileEntity;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void markDirty() {
|
2022-11-06 01:25:28 -06:00
|
|
|
this.tileEntity.markDirty();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void readFromNBT(INbt nbt) {
|
2022-05-03 23:09:21 -05:00
|
|
|
this.tileEntity.readFromNBT(nbt.getMCNBT());
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public double getDistanceFrom(double x, double y, double z) {
|
|
|
|
|
return this.tileEntity.getDistanceFrom(x, y, z);
|
2022-05-03 23:09:21 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public double getDistanceFrom(IPos pos) {
|
|
|
|
|
return this.getDistanceFrom(pos.getXD(), pos.getYD(), pos.getZD());
|
2022-11-06 01:25:28 -06:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public IBlock getBlockType() {
|
2022-11-06 01:25:28 -06:00
|
|
|
return NpcAPI.Instance().getIBlock(world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
2022-05-03 23:09:21 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public boolean isInvalid() {
|
2022-05-03 23:09:21 -05:00
|
|
|
return tileEntity.isInvalid();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void invalidate() {
|
2022-05-03 23:09:21 -05:00
|
|
|
tileEntity.invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void validate() {
|
|
|
|
|
tileEntity.validate();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void updateContainingBlockInfo() {
|
2022-05-03 23:09:21 -05:00
|
|
|
tileEntity.updateContainingBlockInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public INbt getNBT() {
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
this.tileEntity.writeToNBT(compound);
|
|
|
|
|
return NpcAPI.Instance().getINbt(compound);
|
|
|
|
|
}
|
|
|
|
|
}
|