Stop upgrading to 1.19.3
This commit is contained in:
parent
e0ec89d15d
commit
0669dd5dab
10 changed files with 321 additions and 93 deletions
|
@ -105,7 +105,7 @@ public class OTEMod
|
|||
MinecraftForge.EVENT_BUS.register(new ChatServerOverride());
|
||||
MinecraftForge.EVENT_BUS.register(new CommandRegistry());
|
||||
MinecraftForge.EVENT_BUS.register(new VaultWatcher());
|
||||
MinecraftForge.EVENT_BUS.register(new dev.zontreck.otemod.antigrief.Handler());
|
||||
MinecraftForge.EVENT_BUS.register(new dev.zontreck.otemod.zschem.EventHandler());
|
||||
MenuInitializer.CONTAINERS.register(bus);
|
||||
|
||||
ModBlocks.register(bus);
|
||||
|
|
|
@ -1,29 +1,11 @@
|
|||
package dev.zontreck.otemod.antigrief;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
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.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.Blocks;
|
||||
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
|
||||
{
|
||||
|
|
68
src/main/java/dev/zontreck/otemod/antigrief2/Healer.java
Normal file
68
src/main/java/dev/zontreck/otemod/antigrief2/Healer.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package dev.zontreck.otemod.antigrief2;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.antigrief.HealRunner;
|
||||
import dev.zontreck.otemod.antigrief.StoredBlock;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
|
||||
public class Healer extends SavedData implements Supplier<Object>
|
||||
{
|
||||
private Level world;
|
||||
private TickingHealerTask task;
|
||||
static final String DATAKEY = OTEMod.MOD_ID+":"+Healer.class.getSimpleName();
|
||||
|
||||
public Healer()
|
||||
{
|
||||
task = new TickingHealerTask();
|
||||
}
|
||||
|
||||
public void onTick()
|
||||
{
|
||||
Collection<StoredBlock> blocks = task.tick();
|
||||
if(blocks != null)
|
||||
{
|
||||
for(StoredBlock bdata : blocks)
|
||||
{
|
||||
HealRunner.scheduleHeal(bdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDetonate(ExplosionEvent.Detonate event)
|
||||
{
|
||||
Level world = event.getLevel();
|
||||
int maxTicks = 0;
|
||||
for(BlockPos posExplode : event.getAffectedBlocks())
|
||||
{
|
||||
BlockState stateExplode = world.getBlockState(posExplode);
|
||||
if(!isValid(stateExplode))
|
||||
continue;
|
||||
|
||||
if(!stateExplode.isAir())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag save(CompoundTag p_77763_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package dev.zontreck.otemod.antigrief2.handlers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import dev.zontreck.otemod.antigrief2.Healer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public class WorldEventHandler {
|
||||
private Map<ServerLevel, Healer> healers = new HashMap<ServerLevel, Healer>();
|
||||
|
||||
public Map<ServerLevel, Healer> getHealers()
|
||||
{
|
||||
return healers;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLoadLevel(LevelEvent.Load ev)
|
||||
{
|
||||
if(!ev.getLevel().isClientSide() && ev.getLevel() instanceof ServerLevel)
|
||||
{
|
||||
healers.put((ServerLevel)ev.getLevel(), Healer.acquire((ServerLevel)ev.getLevel()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onUnload(LevelEvent.Unload ev)
|
||||
{
|
||||
if(!ev.getLevel().isClientSide())
|
||||
{
|
||||
healers.remove(ev.getLevel());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
package dev.zontreck.otemod.blocks;
|
||||
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.level.block.DoorBlock;
|
||||
|
||||
public class AuroraDoorBlock extends DoorBlock
|
||||
{
|
||||
|
||||
public AuroraDoorBlock(Properties p_52737_, String name) {
|
||||
super(p_52737_);
|
||||
super(p_52737_, SoundEvents.IRON_DOOR_CLOSE, SoundEvents.IRON_DOOR_OPEN);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package dev.zontreck.otemod.zschem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
public class BlockContainerList {
|
||||
private static final BlockContainerList INSTANCE =new BlockContainerList();
|
||||
private final Lock lock;
|
||||
private final List<StoredBlock> containers;
|
||||
|
||||
private BlockContainerList()
|
||||
{
|
||||
this.lock = new ReentrantLock();
|
||||
this.containers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static BlockContainerList getInstance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void add(StoredBlock item)
|
||||
{
|
||||
lock.lock();
|
||||
try{
|
||||
for(StoredBlock sb : containers)
|
||||
{
|
||||
if(sb.getWorldPosition().same(item.getWorldPosition()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
containers.add(item);
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void tick()
|
||||
{
|
||||
lock.lock();
|
||||
try{
|
||||
for (StoredBlock storedBlock : containers) {
|
||||
storedBlock.tick();
|
||||
if(storedBlock.isExpired()){
|
||||
HealRunner.scheduleHeal(storedBlock);
|
||||
containers.remove(storedBlock);
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundTag save(CompoundTag tag){
|
||||
lock.lock();
|
||||
try{
|
||||
|
||||
ListTag lst = new ListTag();
|
||||
for (StoredBlock block : containers) {
|
||||
lst.add(block.serialize());
|
||||
}
|
||||
tag.put("blocks", lst);
|
||||
return tag;
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockContainerList load(CompoundTag tag){
|
||||
BlockContainerList lst = new BlockContainerList();
|
||||
|
||||
ListTag xlst = tag.getList("blocks", CompoundTag.TAG_BYTE);
|
||||
ListIterator<Tag> it = xlst.listIterator();
|
||||
while(it.hasNext()){
|
||||
Tag tg = it.next();
|
||||
CompoundTag blk = (CompoundTag)tg;
|
||||
StoredBlock sb = new StoredBlock(blk);
|
||||
|
||||
lst.add(sb);
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
}
|
89
src/main/java/dev/zontreck/otemod/zschem/BlockSaver.java
Normal file
89
src/main/java/dev/zontreck/otemod/zschem/BlockSaver.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package dev.zontreck.otemod.zschem;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import dev.zontreck.otemod.configs.OTEServerConfig;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
public class BlockSaver {
|
||||
private static final int SAVE_INTERVAL = 1;
|
||||
|
||||
private final ScheduledExecutorService executor;
|
||||
|
||||
public BlockSaver(ScheduledExecutorService service)
|
||||
{
|
||||
executor=service;
|
||||
}
|
||||
|
||||
public static void InitialLoad()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
executor.scheduleAtFixedRate(()->{
|
||||
CompoundTag primary = new CompoundTag();
|
||||
primary=BlockContainerList.getInstance().save(primary);
|
||||
|
||||
File x = getPath().toFile();
|
||||
|
||||
if(OTEServerConfig.DEBUG_HEALER.get())
|
||||
{
|
||||
// Save as sNBT
|
||||
String prettyFormat = NbtUtils.structureToSnbt(primary);
|
||||
|
||||
BufferedWriter bw;
|
||||
try {
|
||||
bw = new BufferedWriter(new FileWriter(x));
|
||||
bw.write(prettyFormat);
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
try {
|
||||
NbtIo.writeCompressed(primary, x);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}, SAVE_INTERVAL, SAVE_INTERVAL, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Healer Queue's data source is a NBT File in the config folder
|
||||
public static final String HealerQueueFile = "OTEHealerLastQueue.nbt";
|
||||
public static final String HealerQueueDebugFile = "OTEHealerLastQueue.snbt";
|
||||
|
||||
public static Path getPath()
|
||||
{
|
||||
|
||||
Path configDir = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath());
|
||||
Path configFile = null;
|
||||
if(OTEServerConfig.DEBUG_HEALER.get())
|
||||
{
|
||||
configFile = configDir.resolve(BlockSaver.HealerQueueDebugFile);
|
||||
|
||||
}else {
|
||||
configFile = configDir.resolve(BlockSaver.HealerQueueFile);
|
||||
}
|
||||
|
||||
//OTEMod.LOGGER.info("OTE HEALER TEMPORARY FILE: "+configFile.toFile().getAbsolutePath());
|
||||
return configFile;
|
||||
}
|
||||
}
|
15
src/main/java/dev/zontreck/otemod/zschem/EventHandler.java
Normal file
15
src/main/java/dev/zontreck/otemod/zschem/EventHandler.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package dev.zontreck.otemod.zschem;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public class EventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDetonate(ExplosionEvent.Detonate ev)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.zontreck.otemod.antigrief;
|
||||
package dev.zontreck.otemod.zschem;
|
||||
|
||||
import java.util.Random;
|
||||
|
|
@ -1,85 +1,41 @@
|
|||
package dev.zontreck.otemod.antigrief;
|
||||
|
||||
import java.time.Instant;
|
||||
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 implements Comparable
|
||||
public class StoredBlock
|
||||
{
|
||||
|
||||
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 int tick;
|
||||
|
||||
private boolean claim = false;
|
||||
private long claimed_at = 0;
|
||||
private Thread claimed_by;
|
||||
|
||||
public void setClaimed()
|
||||
{
|
||||
claimed_at = Instant.now().getEpochSecond();
|
||||
claim=true;
|
||||
public void tick(){
|
||||
this.tick--;
|
||||
}
|
||||
|
||||
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 boolean isClaimedBy(HealerWorker worker)
|
||||
{
|
||||
if(worker.MyThread == claimed_by && claimed())return true;
|
||||
return false;
|
||||
public boolean isExpired() {
|
||||
return tick <= 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,7 +82,7 @@ public class StoredBlock implements Comparable
|
|||
|
||||
public void setBlockEntity(BlockEntity entity)
|
||||
{
|
||||
CompoundTag tag = entity.serializeNBT();
|
||||
CompoundTag tag = entity.saveWithoutMetadata();
|
||||
this.blockEntity=tag;
|
||||
}
|
||||
|
||||
|
@ -159,6 +115,7 @@ public class StoredBlock implements Comparable
|
|||
} catch (InvalidDeserialization e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
state = NbtUtils.readBlockState(tag.getCompound("state"));
|
||||
|
||||
|
@ -166,21 +123,6 @@ public class StoredBlock implements Comparable
|
|||
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