Stop upgrading to 1.19.3

This commit is contained in:
Tara 2023-01-06 23:18:04 -07:00
parent e0ec89d15d
commit 0669dd5dab
10 changed files with 321 additions and 93 deletions

View file

@ -0,0 +1,128 @@
package dev.zontreck.otemod.zschem;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
public class StoredBlock
{
public CompoundTag blockData;
private WorldPosition position;
private BlockState state;
private CompoundTag blockEntity;
private int tick;
public void tick(){
this.tick--;
}
public boolean isExpired() {
return tick <= 0;
}
public StoredBlock(final BlockPos pos, final BlockState toSave, final ServerLevel lvl)
{
position = new WorldPosition(new Vector3(pos), lvl);
this.state=toSave;
}
public StoredBlock(final CompoundTag tag)
{
this.deserialize(tag);
}
public final BlockPos getPos()
{
return position.Position.asBlockPos();
}
public final WorldPosition getWorldPosition()
{
return position;
}
public final BlockState getState()
{
return state;
}
public final long getChunkX()
{
Vector3 pos = position.Position;
return pos.rounded().x >> 4;
}
public final long getChunkZ()
{
Vector3 pos = position.Position;
return pos.rounded().z >> 4;
}
public void setBlockEntity(BlockEntity entity)
{
CompoundTag tag = entity.saveWithoutMetadata();
this.blockEntity=tag;
}
public final CompoundTag getBlockEntity(){
return blockEntity;
}
public static boolean hasBlockEntity(final CompoundTag tag){
return tag.contains("entity", Tag.TAG_COMPOUND);
}
public CompoundTag serialize()
{
final CompoundTag tag = new CompoundTag();
tag.put("pos", position.serialize());
tag.put("state", NbtUtils.writeBlockState(state));
if(blockEntity != null) tag.put("entity", blockEntity);
return tag;
}
public void deserialize(final CompoundTag tag)
{
try {
position = new WorldPosition(tag.getCompound("pos"), false);
} catch (InvalidDeserialization e) {
e.printStackTrace();
}
state = NbtUtils.readBlockState(tag.getCompound("state"));
final CompoundTag tmp = tag.getCompound("entity");
blockEntity = tmp.isEmpty() ? null : tmp;
}
}