Fixed the healing code
This commit is contained in:
parent
0d65d57219
commit
b19fd441f8
9 changed files with 486 additions and 96 deletions
|
@ -1,5 +1,7 @@
|
|||
package dev.zontreck.otemod.antigrief;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
|
@ -8,17 +10,73 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
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 class StoredBlock implements Comparable
|
||||
{
|
||||
|
||||
public static final StoredBlock getBedrock(WorldPosition pos){
|
||||
StoredBlock sb = new StoredBlock(pos.Position.asBlockPos(), Blocks.BEDROCK.defaultBlockState(), pos.getActualDimension());
|
||||
|
||||
return sb;
|
||||
}
|
||||
public static final StoredBlock getAir(WorldPosition pos){
|
||||
StoredBlock sb = new StoredBlock(pos.Position.asBlockPos(), Blocks.AIR.defaultBlockState(), pos.getActualDimension());
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static final StoredBlock getSculk(WorldPosition pos){
|
||||
StoredBlock sb = new StoredBlock(pos.Position.asBlockPos(), Blocks.SCULK.defaultBlockState() ,pos.getActualDimension());
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static final int UNSET = 0;
|
||||
public static final int PHASE1 = 1;
|
||||
public static final int PHASE2 = 2;
|
||||
public static final int PHSAE3 = 4;
|
||||
|
||||
public CompoundTag blockData;
|
||||
|
||||
private WorldPosition position;
|
||||
private BlockState state;
|
||||
|
||||
private CompoundTag blockEntity;
|
||||
|
||||
private boolean claim = false;
|
||||
private long claimed_at = 0;
|
||||
private Thread claimed_by;
|
||||
|
||||
public void setClaimed()
|
||||
{
|
||||
claimed_at = Instant.now().getEpochSecond();
|
||||
claim=true;
|
||||
}
|
||||
|
||||
public boolean claimed()
|
||||
{
|
||||
if(claimed_by == null)
|
||||
{
|
||||
if(claim)
|
||||
{
|
||||
if(Instant.now().getEpochSecond() > claimed_at+30)
|
||||
{
|
||||
claim=false;
|
||||
claimed_at = 0; // The claim timed out as no thread was set
|
||||
return false;
|
||||
}else return true; // Temporary lock on claim
|
||||
}else return false; // Not claimed
|
||||
}else return true; // Permanent process lock
|
||||
}
|
||||
|
||||
public void setClaimedBy(Thread tx){
|
||||
claimed_by=tx;
|
||||
}
|
||||
|
||||
|
||||
public StoredBlock(final BlockPos pos, final BlockState toSave, final ServerLevel lvl)
|
||||
{
|
||||
position = new WorldPosition(new Vector3(pos), lvl);
|
||||
|
@ -32,6 +90,7 @@ public class StoredBlock {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public final BlockPos getPos()
|
||||
{
|
||||
return position.Position.asBlockPos();
|
||||
|
@ -100,6 +159,21 @@ public class StoredBlock {
|
|||
final CompoundTag tmp = tag.getCompound("entity");
|
||||
blockEntity = tmp.isEmpty() ? null : tmp;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if(o instanceof StoredBlock)
|
||||
{
|
||||
StoredBlock sb = (StoredBlock)o;
|
||||
if(sb.position.same(position))
|
||||
{
|
||||
if(sb.state.equals(state))
|
||||
{
|
||||
return 0;
|
||||
}return -1;
|
||||
}else return -1;
|
||||
|
||||
}return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue