81 lines
2.3 KiB
Java
81 lines
2.3 KiB
Java
package com.thebrokenrail.scriptcraft.api.block;
|
|
|
|
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
|
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
|
import net.minecraft.block.entity.BlockEntity;
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.Tickable;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
public class CustomBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable {
|
|
private static double newObjID = 0;
|
|
|
|
private final double objID;
|
|
|
|
public CustomBlockEntity(BlockEntityType<?> type, Identifier id) {
|
|
super(type);
|
|
|
|
objID = newObjID++;
|
|
|
|
ScriptCraftCore.useBridge("CustomBlockEntity.create", id.toString(), objID);
|
|
}
|
|
|
|
@Override
|
|
public void fromTag(CompoundTag tag) {
|
|
super.fromTag(tag);
|
|
ScriptCraftCore.useBridge("CustomBlockEntity.fromTag", objID, tag);
|
|
}
|
|
|
|
@Override
|
|
public void fromClientTag(CompoundTag compoundTag) {
|
|
fromTag(compoundTag);
|
|
}
|
|
|
|
@Override
|
|
public CompoundTag toTag(CompoundTag tag) {
|
|
return (CompoundTag) ScriptCraftCore.useBridge("CustomBlockEntity.toTag", objID, super.toTag(tag));
|
|
}
|
|
|
|
@Override
|
|
public CompoundTag toClientTag(CompoundTag compoundTag) {
|
|
return toTag(compoundTag);
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
ScriptCraftCore.useBridge("CustomBlockEntity.tick", objID);
|
|
}
|
|
|
|
@Override
|
|
public void setLocation(World world, BlockPos pos) {
|
|
super.setLocation(world, pos);
|
|
ScriptCraftCore.useBridge("CustomBlockEntity.setLocation", objID, world, pos.getX(), pos.getY(), pos.getZ());
|
|
}
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@Override
|
|
protected void finalize() throws Throwable {
|
|
try {
|
|
ScriptCraftCore.useBridge("CustomBlockEntity.free", objID);
|
|
} finally {
|
|
super.finalize();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void markDirty() {
|
|
super.markDirty();
|
|
if (hasWorld() && getWorld() instanceof ServerWorld) {
|
|
sync();
|
|
}
|
|
}
|
|
|
|
public double getObjID() {
|
|
return objID;
|
|
}
|
|
}
|