Start to add in a block queue system to allow my other mods to have separate queues for different things.

This commit is contained in:
zontreck 2024-04-11 00:47:31 -07:00
parent 99e38893ca
commit 3302ab14b8
3 changed files with 63 additions and 22 deletions

View file

@ -0,0 +1,44 @@
package dev.zontreck.libzontreck.memory.world;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import java.util.ArrayList;
import java.util.List;
public abstract class BlockRestoreQueue
{
private List<PrimitiveBlock> BLOCK_QUEUE = new ArrayList<>();
/**
* Returns the restore queue name
* @return Name of the restore queue
*/
public abstract String getRestoreQueueName();
/**
* @return The number of blocks remaining in this queue
*/
public int getQueuedBlocks()
{
return BLOCK_QUEUE.size();
}
/**
* Queues a block to be restored
* @param block
*/
public void enqueueBlock(SavedBlock block)
{
BLOCK_QUEUE.add(block.getBlockPrimitive());
}
/**
* Queues a block to be restored
* @param block
*/
public void enqueueBlock(PrimitiveBlock block)
{
BLOCK_QUEUE.add(block);
}
}

View file

@ -9,13 +9,22 @@ import net.minecraft.world.level.block.state.BlockState;
public class PrimitiveBlock public class PrimitiveBlock
{ {
public SavedBlock block; public final SavedBlock savedBlock;
public Block blockType; public final Block blockType;
public BlockState blockState; public final BlockState blockState;
public CompoundTag blockEntity; public final CompoundTag blockEntity;
public BlockPos position; public final BlockPos position;
public ServerLevel level; public final ServerLevel level;
public PrimitiveBlock(SavedBlock savedBlock, Block blockType, BlockState blockState, CompoundTag blockEntity, BlockPos position, ServerLevel level)
{
this.savedBlock = savedBlock;
this.blockType = blockType;
this.blockEntity = blockEntity;
this.position = position;
this.level = level;
this.blockState = blockState;
}
/** /**
* Alias method * Alias method
* @see SavedBlock#serialize() * @see SavedBlock#serialize()
@ -23,7 +32,7 @@ public class PrimitiveBlock
*/ */
public CompoundTag serialize() public CompoundTag serialize()
{ {
return block.serialize(); return savedBlock.serialize();
} }
/** /**
@ -40,14 +49,13 @@ public class PrimitiveBlock
/** /**
* Compare a block with this primitive block * Compare a block with this primitive block
* @param block The block type to compare
* @param state The block state to compare * @param state The block state to compare
* @param entity The block entity to compare * @param entity The block entity to compare
* @return True if identical * @return True if identical
*/ */
public boolean is(Block block, BlockState state, BlockEntity entity) public boolean is(BlockState state, BlockEntity entity)
{ {
if(block == this.blockType) if(state.getBlock() == this.blockType)
{ {
// Check the block state // Check the block state
if(this.blockState.equals(state)) if(this.blockState.equals(state))

View file

@ -2,19 +2,15 @@ package dev.zontreck.libzontreck.memory.world;
import dev.zontreck.libzontreck.api.Vector3; import dev.zontreck.libzontreck.api.Vector3;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization; import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.libzontreck.vectors.Vector3i;
import dev.zontreck.libzontreck.vectors.WorldPosition; import dev.zontreck.libzontreck.vectors.WorldPosition;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.server.ServerLifecycleHooks;
public class SavedBlock public class SavedBlock
{ {
@ -90,18 +86,11 @@ public class SavedBlock
public PrimitiveBlock getBlockPrimitive() public PrimitiveBlock getBlockPrimitive()
{ {
PrimitiveBlock prim = new PrimitiveBlock();
ServerLevel level = position.getActualDimension(); ServerLevel level = position.getActualDimension();
BlockState state = NbtUtils.readBlockState(level.holderLookup(Registries.BLOCK), blockState); BlockState state = NbtUtils.readBlockState(level.holderLookup(Registries.BLOCK), blockState);
prim.blockState = state;
prim.block = this;
prim.blockType = state.getBlock();
prim.blockEntity = blockEntity;
prim.position = position.Position.asBlockPos();
prim.level = level;
return prim; return new PrimitiveBlock(this, state.getBlock(), state, blockEntity, position.Position.asBlockPos(), level);
} }
} }