Push final changes for the night
This commit is contained in:
parent
9f6758c5c6
commit
0d65d57219
6 changed files with 223 additions and 108 deletions
|
@ -149,8 +149,6 @@ dependencies {
|
|||
|
||||
// Examples using mod jars from ./libs
|
||||
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
|
||||
api 'org.apache.commons:commons-math3:3.6.1'
|
||||
implementation 'com.google.guava:guava:22.0'
|
||||
implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.8'
|
||||
compileOnly 'org.mariadb.jdbc:mariadb-java-client'
|
||||
// For more info...
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
org.gradle.jvmargs=-Xmx8G
|
||||
org.gradle.daemon=false
|
||||
|
||||
my_version=1.3.4.3
|
||||
my_version=1.3.4.4
|
||||
|
||||
mc_version=1.19.2
|
||||
forge_version=43.1.32
|
||||
jei_version=11.3.0.262
|
||||
libz_version=1.0.1.0
|
||||
forge_version=43.1.40
|
||||
jei_version=11.3.0.271
|
||||
libz_version=1.0.1.2
|
|
@ -70,6 +70,8 @@ public class OTEMod
|
|||
public static List<TeleportContainer> TeleportRegistry = new ArrayList<>();
|
||||
public static MinecraftServer THE_SERVER;
|
||||
public static boolean ALIVE;
|
||||
public static boolean HEALER_WAIT=true; // Only on loading finish should this unlock
|
||||
public static Thread HEALER_THREAD;
|
||||
|
||||
public static boolean DEVELOPER=false;
|
||||
private static Thread MasterThread;
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -22,6 +24,7 @@ import net.minecraftforge.event.entity.item.ItemEvent;
|
|||
import net.minecraftforge.event.level.BlockEvent;
|
||||
import net.minecraftforge.event.level.ChunkDataEvent;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
import net.minecraftforge.event.level.BlockEvent.NeighborNotifyEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
package dev.zontreck.otemod.antigrief;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Random;
|
||||
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import net.minecraft.server.commands.SetBlockCommand;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.item.FallingBlockEntity;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.FallingBlock;
|
||||
import net.minecraft.world.level.block.SandBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
|
||||
public class HealerManager implements Runnable
|
||||
{
|
||||
|
@ -21,8 +29,14 @@ public class HealerManager implements Runnable
|
|||
@Override
|
||||
public void run(){
|
||||
boolean skipWait=false;
|
||||
int skipCount=0;
|
||||
long lastSave = 0;
|
||||
final long saveInterval = (2*60); // Every 2 minutes
|
||||
boolean lastWait = false;
|
||||
|
||||
while(OTEMod.ALIVE)
|
||||
{
|
||||
try{
|
||||
// Run the queue
|
||||
// We want to restore one block per run, then halt for number of seconds in config
|
||||
try {
|
||||
|
@ -33,6 +47,12 @@ public class HealerManager implements Runnable
|
|||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(lastWait != OTEMod.HEALER_WAIT){
|
||||
OTEMod.LOGGER.info("Healer wait flag was toggled");
|
||||
}
|
||||
lastWait = OTEMod.HEALER_WAIT;
|
||||
if(OTEMod.HEALER_WAIT)
|
||||
continue; // Wait until the saved queue has been fully imported
|
||||
|
||||
if(!OTEMod.ALIVE)
|
||||
{
|
||||
|
@ -46,57 +66,94 @@ public class HealerManager implements Runnable
|
|||
|
||||
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.addAll(HealerQueue.ToValidate);
|
||||
HealerQueue.ToValidate.clear();
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
// Play a popping sound at the block position
|
||||
final SoundEvent pop = SoundEvents.ITEM_PICKUP;
|
||||
// Get the first block in the list
|
||||
final StoredBlock sb = HealerQueue.ToHeal.get(0);
|
||||
final StoredBlock sb = HealerQueue.locateHighestBlock(HealerQueue.ToHeal);
|
||||
final ServerLevel level = sb.getWorldPosition().getActualDimension();
|
||||
|
||||
|
||||
// Remove the block from the queue now to prevent further issues
|
||||
HealerQueue.ToHeal.remove(sb);
|
||||
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 the location are identical
|
||||
if(level.getBlockState(sb.getPos()).is(sb.getState().getBlock())){
|
||||
// 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;
|
||||
|
||||
|
||||
level.getServer().execute(new Runnable(){
|
||||
public void run()
|
||||
{
|
||||
|
||||
level.setBlockAndUpdate(sb.getPos(), sb.getState());
|
||||
//BlockSnapshot bs = BlockSnapshot.create(level.dimension(), level, sb.getPos());
|
||||
|
||||
//BlockState current = level.getBlockState(sb.getPos());
|
||||
BlockState nState = Block.updateFromNeighbourShapes(sb.getState(), level, sb.getPos());
|
||||
level.setBlock(sb.getPos(), nState, Block.UPDATE_CLIENTS | Block.UPDATE_KNOWN_SHAPE); // no update?
|
||||
|
||||
|
||||
//level.setBlocksDirty(sb.getPos(), sb.getState(), level.getBlockState(sb.getPos()));
|
||||
//level.markAndNotifyBlock(sb.getPos(), level.getChunkAt(sb.getPos()), sb.getState(), level.getBlockState(sb.getPos()), 2, 0);
|
||||
|
||||
//level.getChunkAt(sb.getPos()).setBlockState(sb.getPos(), sb.getState(), false);
|
||||
|
||||
BlockEntity be = level.getBlockEntity(sb.getPos());
|
||||
|
||||
if(be!=null)
|
||||
be.deserializeNBT(sb.getBlockEntity());
|
||||
if(be!=null){
|
||||
//be.deserializeNBT(sb.getBlockEntity());
|
||||
be.load(sb.getBlockEntity());
|
||||
be.setChanged();
|
||||
|
||||
}
|
||||
|
||||
// Everything is restored, play sound
|
||||
SoundSource ss = SoundSource.NEUTRAL;
|
||||
|
@ -121,12 +178,26 @@ public class HealerManager implements Runnable
|
|||
|
||||
|
||||
|
||||
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 {
|
||||
|
|
|
@ -12,15 +12,17 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
|
@ -31,6 +33,8 @@ public class HealerQueue {
|
|||
|
||||
public static List<StoredBlock> ToHeal = new ArrayList<StoredBlock>();
|
||||
public static List<StoredBlock> ToValidate = new ArrayList<StoredBlock>();
|
||||
public static List<StoredBlock> FinishedBlocks = new ArrayList<StoredBlock>();
|
||||
|
||||
|
||||
public static Path getPath()
|
||||
{
|
||||
|
@ -49,6 +53,39 @@ public class HealerQueue {
|
|||
return configFile;
|
||||
}
|
||||
|
||||
public static StoredBlock locateHighestBlock(List<StoredBlock> list)
|
||||
{
|
||||
StoredBlock sb = null;
|
||||
double currentY = 0;
|
||||
for (StoredBlock storedBlock : ToHeal) {
|
||||
if(storedBlock.getWorldPosition().Position.y > currentY)
|
||||
{
|
||||
currentY = storedBlock.getWorldPosition().Position.y;
|
||||
sb=storedBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static boolean HasValidatePosition(BlockPos pos, ServerLevel lvl)
|
||||
{
|
||||
Vector3 realPos = new Vector3(pos);
|
||||
WorldPosition real = new WorldPosition(realPos, lvl);
|
||||
|
||||
for (StoredBlock storedBlock : ToHeal) {
|
||||
if(storedBlock.getWorldPosition().same(real))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (StoredBlock storedBlock : ToValidate) {
|
||||
if(storedBlock.getWorldPosition().same(real))return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Thread tx = new Thread(new Runnable(){
|
||||
|
@ -76,7 +113,7 @@ public class HealerQueue {
|
|||
|
||||
try {
|
||||
HealerQueue.deserialize(NbtUtils.snbtToStructure(FinalStr));
|
||||
} catch (CommandSyntaxException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
|
@ -91,7 +128,7 @@ public class HealerQueue {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
OTEMod.HEALER_WAIT=false;
|
||||
}
|
||||
});
|
||||
tx.start();
|
||||
|
@ -99,6 +136,8 @@ public class HealerQueue {
|
|||
// Set up the HealerManager / Runner
|
||||
Thread txx = new Thread(new HealerManager());
|
||||
txx.start();
|
||||
|
||||
OTEMod.HEALER_THREAD = txx;
|
||||
}
|
||||
|
||||
public static CompoundTag serialize()
|
||||
|
@ -128,6 +167,7 @@ public class HealerQueue {
|
|||
|
||||
public static void deserialize(CompoundTag tag)
|
||||
{
|
||||
OTEMod.HEALER_WAIT=true;
|
||||
// Begin parsing
|
||||
if(tag.contains("queue"))
|
||||
{
|
||||
|
@ -144,7 +184,7 @@ public class HealerQueue {
|
|||
}
|
||||
}
|
||||
|
||||
OTEMod.LOGGER.info("Finished loading the queue");
|
||||
OTEMod.LOGGER.info("Finished loading the queue ["+HealerQueue.ToHeal.size()+"] items");
|
||||
|
||||
if(tag.contains("validate"))
|
||||
{
|
||||
|
@ -159,7 +199,8 @@ public class HealerQueue {
|
|||
}
|
||||
}
|
||||
|
||||
OTEMod.LOGGER.info("Finished loading validation queue for healer");
|
||||
OTEMod.LOGGER.info("Finished loading validation queue for healer ["+HealerQueue.ToValidate.size()+"] items");
|
||||
OTEMod.HEALER_WAIT=false;
|
||||
}
|
||||
public static void dump() throws IOException
|
||||
{
|
||||
|
|
Reference in a new issue