Begin updating to 1.19.3

This commit is contained in:
Tara 2023-01-03 22:04:57 -07:00
parent b19fd441f8
commit e0ec89d15d
7 changed files with 194 additions and 267 deletions

View file

@ -3,8 +3,8 @@
org.gradle.jvmargs=-Xmx8G
org.gradle.daemon=false
my_version=1.3.4.4
my_version=1.3.5.0
mc_version=1.19.2
forge_version=43.1.40
libz_version=1.0.1.2
mc_version=1.19.3
forge_version=44.1.0
libz_version=1.0.2.0

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -110,8 +110,6 @@ public class Handler
HealerQueue.Pass=0;
HealerQueue.ToHeal.addAll(HealerQueue.ToValidate);
HealerQueue.ToValidate = new ArrayList<>();
HealerQueue.Shuffle();

View file

@ -69,224 +69,9 @@ public class HealerManager implements Runnable
healerWorker.doTick=true;
}
if(HealerQueue.ToHeal.size()==0 && HealerQueue.ToValidate.size()==0)
{
HealerQueue.Pass=0;
if(HealerQueue.dirty())
HealerQueue.dump();
continue;
}
// Get the first block in the list
final StoredBlock sb = HealerQueue.locateLowestBlock(HealerQueue.ToHeal);
ServerLevel level = null;
StoredBlock below = null;
if(sb != null)
{
level = sb.getWorldPosition().getActualDimension();
below = HealerQueue.getExact(new WorldPosition(sb.getWorldPosition().Position.moveDown(), level));
}
switch(HealerQueue.Pass)
{
case 0:
{
// Pass 1. Set all positions to bedrock
// The code will check is the block is solid. If the block below it is not solid, it will set it to air, regardless of if it is a falling block of not
if(HealerQueue.ToHeal.size()==0)
{
// Move the validate list back into healer queue, and increment pass
OTEMod.LOGGER.info("Pass 1 completed, moving to pass 2");
HealerQueue.Pass=1;
HealerQueue.ToHeal = HealerQueue.ToValidate;
HealerQueue.ToValidate = new ArrayList<>();
HealerQueue.dump();
break; // Exit this loop
}
if(below == null){
// This line will prevent the block below from getting set to Sculk
below = StoredBlock.getSculk(new WorldPosition(sb.getWorldPosition().Position.moveDown(), level)); // below is null so it is a unknown, accept a loss if its a falling block
}
if(!sb.getState().isAir() && below.getState().isAir())
{
HealRunner.scheduleHeal(StoredBlock.getSculk(below.getWorldPosition()));
skipWait=false;
}else {
if(!sb.getState().isAir())
{
HealRunner.scheduleHeal(StoredBlock.getSculk(sb.getWorldPosition()));
skipWait=false;
} else {
skipWait=true;
}
}
HealerQueue.ToValidate.add(sb);
HealerQueue.ToHeal.remove(sb);
break;
}
case 1:
{
// Pass 2 only sets the solid blocks
if(HealerQueue.ToHeal.size()==0)
{
OTEMod.LOGGER.info("Pass 2 completed, moving to pass 3");
HealerQueue.Pass++;
HealerQueue.ToHeal = HealerQueue.ToValidate;
HealerQueue.ToValidate = new ArrayList<>();
HealerQueue.dump();
break;
}
if(!sb.getState().isAir())
{
skipWait=false;
HealRunner.scheduleHeal(sb);
}else{
skipWait=true;
HealerQueue.ToValidate.add(sb);
}
HealerQueue.ToHeal.remove(sb);
break;
}
case 2:
{
// Pass 3 removes bedrock by setting blocks that are air
if(HealerQueue.ToHeal.size()==0)
{
OTEMod.LOGGER.info("Pass 3 has been completed. Ending restore");
HealerQueue.Pass=0;
HealerQueue.ToHeal.clear();
HealerQueue.ToValidate.clear();
HealerQueue.dump();
break;
}
HealerQueue.ToHeal.remove(sb);
if(sb.getState().isAir())
{
BlockState bs = sb.getWorldPosition().getActualDimension().getBlockState(sb.getPos());
if(!bs.isAir() && !bs.is(Blocks.SCULK))
{
skipWait=true;
continue;
}
if(!bs.isAir()){
skipWait=false;
HealRunner.scheduleHeal(sb);
}else skipWait=true;
}else skipWait=true;
break;
}
default:
{
HealerQueue.Pass=0;
OTEMod.LOGGER.info("/!\\ ALERT /!\\\n\nWARNING: Unknown pass operation was added to the HealQueue");
break;
}
}
}catch(Exception e){}
}
OTEMod.ALIVE=false;
/*while(OTEMod.ALIVE) // do nothing, code is disabled here.
{
try{
// Loop back to start if no items in queue
if(HealerQueue.ToHeal.size()==0){
if(HealerQueue.ToValidate.size()==0)continue;
boolean redo = false;
// Validate success
for(StoredBlock sb : HealerQueue.ToValidate)
{
try{
final ServerLevel level = sb.getWorldPosition().getActualDimension();
if(!level.getBlockState(sb.getPos()).is(sb.getState().getBlock()))
{
redo=true;
// Redo restore
HealerQueue.ToHeal.add(sb);
}
}catch(Exception e){}
}
HealerQueue.ToValidate.clear();
OTEMod.LOGGER.info("Validation of restore completed");
HealerQueue.dump();
if(redo)
{
HealerQueue.Shuffle();
OTEMod.LOGGER.info("Validation was not successful, and the repair will be repeated");
}
continue;
}
// Get the first block in the list
final StoredBlock sb = HealerQueue.locateHighestBlock(HealerQueue.ToHeal);
final ServerLevel level = sb.getWorldPosition().getActualDimension();
// Remove the block from the queue now to prevent further issues
if( !HealerQueue.ToValidate.add(sb) )
{
OTEMod.LOGGER.info("Failed to add Block to Validation queue!!! Verification of restore will not work");
}else
HealerQueue.ToHeal.remove(sb);
// Healer object should have been added to the validation list
// Check if the block to restore, and the block at position are air.
if(level.getBlockState(sb.getPos()).isAir() && sb.getState().isAir()){
skipWait=true;
continue; // Skip the wait, and this block
} else skipWait=false;
if(skipWait)
{
if(skipCount > 5){
skipCount=0;
skipWait=false;// Give the server a chance to breathe
}
else {
skipCount++;
}
}else skipCount=0;
if(!skipWait) // Only save the queue when sleeping appropriately
{
if(lastSave+saveInterval < Instant.now().getEpochSecond()){
try {
HealerQueue.dump();
lastSave = Instant.now().getEpochSecond();
OTEMod.LOGGER.info("Flushing current healer queue to disk...");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}catch (Exception e)
{
e.printStackTrace();
}
}*/
OTEMod.LOGGER.info("Tearing down healer jobs. Saving remaining queue, stand by...");
try {

View file

@ -32,13 +32,11 @@ public class HealerQueue {
public static final String HealerQueueDebugFile = "OTEHealerLastQueue.snbt";
public static List<StoredBlock> ToHeal = new ArrayList<StoredBlock>(); // Air and Solid Blocks get set to bedrock initially
public static List<StoredBlock> ToValidate = new ArrayList<StoredBlock>(); // This contains all the blocks except air
public static int Pass = 0;
private static List<StoredBlock> LastToHeal = new ArrayList<StoredBlock>();
private static List<StoredBlock> LastToValidate = new ArrayList<StoredBlock>();
private static int LastPass = 0;
public static HealerManager ManagerInstance=null;
@ -91,6 +89,30 @@ public class HealerQueue {
return sb;
}
public static StoredBlock locateLowestBlockForWorker(List<StoredBlock> list, HealerWorker worker)
{
StoredBlock sb = null;
double currentY = 300;
for (StoredBlock storedBlock : ToHeal) {
if(storedBlock.getWorldPosition().Position.y < currentY && storedBlock.isClaimedBy(worker))
{
currentY = storedBlock.getWorldPosition().Position.y;
sb=storedBlock;
}
}
return sb;
}
public static List<StoredBlock> getBlocksByWorker(HealerWorker worker)
{
List<StoredBlock> blocks = new ArrayList<>();
for (StoredBlock storedBlock : ToHeal) {
if(storedBlock.isClaimedBy(worker))blocks.add(storedBlock);
}
return blocks;
}
public static StoredBlock getExact(WorldPosition wp)
{
for (StoredBlock storedBlock : ToHeal) {
@ -99,12 +121,6 @@ public class HealerQueue {
return storedBlock;
}
}
for (StoredBlock storedBlock : ToValidate) {
if(storedBlock.getWorldPosition().same(wp))
{
return storedBlock;
}
}
return null;
}
@ -121,9 +137,6 @@ public class HealerQueue {
return true;
}
}
for (StoredBlock storedBlock : ToValidate) {
if(storedBlock.getWorldPosition().same(real))return true;
}
return false;
}
@ -180,6 +193,11 @@ public class HealerQueue {
Thread txx = new Thread(ManagerInstance);
txx.start();
HealerWorker worker = new HealerWorker(ToHeal);
Thread txxx = new Thread(worker);
ManagerInstance.registerWorker(worker);
txxx.start();
OTEMod.HEALER_THREAD = txx;
}
@ -192,14 +210,8 @@ public class HealerQueue {
{
lst.add(block.serialize());
}
ListTag lst2 = new ListTag();
for(final StoredBlock block : HealerQueue.ToValidate)
{
lst2.add(block.serialize());
}
tag.put("queue", lst);
tag.put("validate", lst2);
tag.putInt("pass", HealerQueue.Pass);
//OTEMod.LOGGER.info("HEAL ["+HealerQueue.ToHeal.size()+"] / VALIDATE ["+HealerQueue.ToValidate.size()+"]");
@ -212,7 +224,6 @@ public class HealerQueue {
public static List<StoredBlock> removeSame(List<StoredBlock> other)
{
other=removeSameFrom(ToHeal, other);
other=removeSameFrom(ToValidate,other);
return other;
}
@ -243,11 +254,6 @@ public class HealerQueue {
ToHeal.remove(i);
}
}
for (int i = 0; i < ToValidate.size(); i++) {
if(ToValidate.get(i).getWorldPosition().same(pos)){
ToValidate.remove(i);
}
}
}
@ -261,6 +267,7 @@ public class HealerQueue {
// Read the list
ListTag items = tag.getList("queue", Tag.TAG_COMPOUND);
for(int i=0;i<items.size();i++)
{
@ -268,33 +275,20 @@ public class HealerQueue {
StoredBlock sb = new StoredBlock(stored);
HealerQueue.ToHeal.add(sb);
}
}
OTEMod.LOGGER.info("Finished loading the queue ["+HealerQueue.ToHeal.size()+"] items");
if(tag.contains("validate"))
{
HealerQueue.ToValidate.clear();
ListTag items2 = tag.getList("validate", Tag.TAG_COMPOUND);
for(int i=0;i<items2.size();i++)
{
CompoundTag stored = items2.getCompound(i);
StoredBlock sb = new StoredBlock(stored);
HealerQueue.ToValidate.add(sb);
}
}
HealerQueue.Pass = tag.getInt("pass");
OTEMod.LOGGER.info("Finished loading validation queue for healer ["+HealerQueue.ToValidate.size()+"] items");
OTEMod.HEALER_WAIT=false;
}
public static boolean dirty()
{
if(ToHeal!=LastToHeal)return true;
if(ToValidate!=LastToValidate)return true;
if(Pass != LastPass)return true;
return false;
}
@ -302,7 +296,6 @@ public class HealerQueue {
public static void dump() throws IOException
{
LastToHeal = ToHeal;
LastToValidate = ToValidate;
LastPass = Pass;
CompoundTag serialized = HealerQueue.serialize();
if(OTEServerConfig.DEBUG_HEALER.get())

View file

@ -1,16 +1,27 @@
package dev.zontreck.otemod.antigrief;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
public class HealerWorker implements Runnable
{
private final List<StoredBlock> proc;
private List<StoredBlock> proc;
public boolean alive=false; // These are the
public boolean doTick = false;
public Thread MyThread;
private boolean skipWait;
public int Pass; // A local pass for this worker
public HealerWorker(List<StoredBlock> toProcess)
{
// TODO: Make this a individualized heal worker that does the task of the current HealerManager, but with a central list of positions for de-duplication. But that a second worker would not process the same positions
@ -25,16 +36,21 @@ public class HealerWorker implements Runnable
@Override
public void run()
{
alive=true;
MyThread=Thread.currentThread();
HealerQueue.ManagerInstance.registerWorker(this);
for (StoredBlock storedBlock : proc) {
storedBlock.setClaimedBy(Thread.currentThread());
OTEMod.LOGGER.info("Hello from Healer Worker "+Thread.currentThread().getName());
for(int i=0;i<proc.size();i++){
StoredBlock sb = proc.get(i);
sb.setClaimedBy(MyThread);
}
while(alive){
while(alive && OTEMod.ALIVE){
// Stay alive
// The tick event will be fired when appropriate
if(doTick)tick();
if(skipWait)tick();
doTick=false;
@ -47,8 +63,136 @@ public class HealerWorker implements Runnable
public void tick()
{
// A tick in the healer worker tells it to repair a block
// The healer manager is responsible for dispatching ticks
try{
// A tick in the healer worker tells it to repair a block
// The healer manager is responsible for dispatching ticks
if(proc.size()==0 && HealerQueue.getBlocksByWorker(this).size()==0)
{
alive=false;
if(HealerQueue.dirty())
HealerQueue.dump();
return;
}
// Get the first block in the list
final StoredBlock sb = HealerQueue.locateLowestBlock(proc);
ServerLevel level = null;
StoredBlock below = null;
if(sb != null)
{
level = sb.getWorldPosition().getActualDimension();
below = HealerQueue.getExact(new WorldPosition(sb.getWorldPosition().Position.moveDown(), level));
}
switch(Pass)
{
case 0:
{
// Pass 1. Set all positions to bedrock
// The code will check is the block is solid. If the block below it is not solid, it will set it to air, regardless of if it is a falling block of not
if(proc.size()==0)
{
// Move the validate list back into healer queue, and increment pass
OTEMod.LOGGER.info("Pass 1 completed, moving to pass 2");
Pass=1;
proc = HealerQueue.getBlocksByWorker(this);
HealerQueue.dump();
break; // Exit this loop
}
if(below == null){
// This line will prevent the block below from getting set to Sculk
below = StoredBlock.getSculk(new WorldPosition(sb.getWorldPosition().Position.moveDown(), level)); // below is null so it is a unknown, accept a loss if its a falling block
}
if(!sb.getState().isAir() && below.getState().isAir())
{
HealRunner.scheduleHeal(StoredBlock.getSculk(below.getWorldPosition()));
skipWait=false;
}else {
if(!sb.getState().isAir())
{
HealRunner.scheduleHeal(StoredBlock.getSculk(sb.getWorldPosition()));
skipWait=false;
} else {
skipWait=true;
}
}
proc.remove(sb);
break;
}
case 1:
{
// Pass 2 only sets the solid blocks
if(proc.size()==0)
{
OTEMod.LOGGER.info("Pass 2 completed, moving to pass 3");
Pass++;
proc = HealerQueue.getBlocksByWorker(this);
HealerQueue.dump();
break;
}
if(!sb.getState().isAir())
{
skipWait=false;
HealRunner.scheduleHeal(sb);
HealerQueue.ToHeal.remove(sb);
}else{
skipWait=true;
}
proc.remove(sb);
break;
}
case 2:
{
// Pass 3 removes bedrock by setting blocks that are air
if(proc.size()==0)
{
OTEMod.LOGGER.info("Pass 3 has been completed. Ending restore");
Pass=0;
proc.clear();
HealerQueue.dump();
break;
}
proc.remove(sb);
HealerQueue.ToHeal.remove(sb);
if(sb.getState().isAir())
{
BlockState bs = sb.getWorldPosition().getActualDimension().getBlockState(sb.getPos());
if(!bs.isAir() && !bs.is(Blocks.SCULK))
{
skipWait=true;
return;
}
if(!bs.isAir()){
skipWait=false;
HealRunner.scheduleHeal(sb);
}else skipWait=true;
}else skipWait=true;
break;
}
default:
{
Pass=0;
OTEMod.LOGGER.info("/!\\ ALERT /!\\\n\nWARNING: Unknown pass operation was added to the HealQueue");
break;
}
}
}catch(Exception e){}
}
}

View file

@ -76,6 +76,12 @@ public class StoredBlock implements Comparable
claimed_by=tx;
}
public boolean isClaimedBy(HealerWorker worker)
{
if(worker.MyThread == claimed_by && claimed())return true;
return false;
}
public StoredBlock(final BlockPos pos, final BlockState toSave, final ServerLevel lvl)
{
@ -159,6 +165,7 @@ public class StoredBlock implements Comparable
final CompoundTag tmp = tag.getCompound("entity");
blockEntity = tmp.isEmpty() ? null : tmp;
}
@Override
public int compareTo(Object o) {
if(o instanceof StoredBlock)