Finish implementing creeperheal.
This commit is contained in:
parent
2d525f3c7f
commit
1ada902c26
7 changed files with 104 additions and 63 deletions
|
@ -3,7 +3,7 @@
|
|||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
libzontreck=1201.13.042424.0415
|
||||
libzontreck=1201.13.042524.0527
|
||||
|
||||
## Environment Properties
|
||||
|
||||
|
@ -48,7 +48,7 @@ mod_name=Aria's Essentials
|
|||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=GPLv3
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=1201.2.041224.0854
|
||||
mod_version=1201.2.042524.0537
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
import dev.zontreck.essentials.antiexplode.CreeperHealQueue;
|
||||
import dev.zontreck.essentials.blocks.ModBlocks;
|
||||
import dev.zontreck.essentials.client.Keybindings;
|
||||
import dev.zontreck.essentials.client.renderer.TimeBoostEntityRenderer;
|
||||
|
@ -16,6 +17,7 @@ import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
|||
import dev.zontreck.essentials.configs.client.AEClientConfig;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.essentials.entities.ModEntities;
|
||||
import dev.zontreck.essentials.events.MainEventHandlers;
|
||||
import dev.zontreck.essentials.events.TeleportEvent;
|
||||
import dev.zontreck.essentials.client.renderer.HeartsRenderer;
|
||||
import dev.zontreck.essentials.imc.Events;
|
||||
|
@ -26,16 +28,26 @@ import dev.zontreck.essentials.rtp.RTPCaches;
|
|||
import dev.zontreck.essentials.rtp.RTPCachesEventHandlers;
|
||||
import dev.zontreck.essentials.util.BackPositionCaches;
|
||||
import dev.zontreck.essentials.util.CommandCooldowns;
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueue;
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueueRegistry;
|
||||
import dev.zontreck.libzontreck.memory.world.SavedBlock;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.SNbtIo;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3i;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -63,7 +75,7 @@ public class AriasEssentials {
|
|||
public static boolean ALIVE;
|
||||
public static Map<UUID, Homes> player_homes = new HashMap<>();
|
||||
public static boolean DEBUG = true;
|
||||
public static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
public static ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
|
||||
|
||||
|
||||
|
||||
|
@ -72,8 +84,10 @@ public class AriasEssentials {
|
|||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
bus.addListener(this::setup);
|
||||
|
||||
LOGGER.info("/!\\ Loading Aria's Essentials Configuration Files /!\\");
|
||||
AEServerConfig.loadFromFile();
|
||||
AEClientConfig.loadFromFile();
|
||||
LOGGER.info("/!\\ DONE LOADING AECONFIG /!\\");
|
||||
|
||||
|
||||
|
||||
|
@ -86,6 +100,7 @@ public class AriasEssentials {
|
|||
MinecraftForge.EVENT_BUS.register(new CommandCooldowns());
|
||||
MinecraftForge.EVENT_BUS.register(RTPCachesEventHandlers.class);
|
||||
MinecraftForge.EVENT_BUS.register(Events.class);
|
||||
MinecraftForge.EVENT_BUS.register(MainEventHandlers.class);
|
||||
|
||||
ModItems.register(bus);
|
||||
ModBlocks.register(bus);
|
||||
|
@ -93,6 +108,7 @@ public class AriasEssentials {
|
|||
CreativeModeTabs.register(bus);
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTeleport(TeleportEvent event)
|
||||
{
|
||||
|
@ -115,7 +131,9 @@ public class AriasEssentials {
|
|||
public void onServerStart(final ServerStartedEvent ev)
|
||||
{
|
||||
ALIVE=true;
|
||||
// Print out the server config
|
||||
|
||||
LOGGER.debug(NbtUtils.structureToSnbt(AEServerConfig.getInstance().serialize()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package dev.zontreck.essentials.antiexplode;
|
||||
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueue;
|
||||
import dev.zontreck.libzontreck.memory.world.PrimitiveBlock;
|
||||
import dev.zontreck.libzontreck.memory.world.SortedBlockQueue;
|
||||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.libzontreck.memory.world.*;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CreeperHealQueue extends BlockRestoreQueue
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getRestoreQueueName() {
|
||||
return "creeperheal";
|
||||
|
@ -18,6 +23,7 @@ public class CreeperHealQueue extends BlockRestoreQueue
|
|||
|
||||
@Override
|
||||
public void databaseUpdate(PrimitiveBlock block) {
|
||||
if(Blocks.AIR == block.blockType) return; // Do not cache air
|
||||
super.databaseUpdate(block);
|
||||
notifyDirtyQueue(true);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.zontreck.essentials.configs.server;
|
||||
|
||||
import dev.zontreck.ariaslib.util.Lists;
|
||||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.configs.server.sections.*;
|
||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||
import dev.zontreck.essentials.util.Maps;
|
||||
|
@ -29,26 +30,33 @@ public class AEServerConfig
|
|||
public static AEServerConfig deserialize(CompoundTag tag)
|
||||
{
|
||||
AEServerConfig config = new AEServerConfig();
|
||||
config.costs = Costs.deserialize(tag.getCompound(Costs.TAG_NAME));
|
||||
config.limits = Limitations.deserialize(tag.getCompound(Limitations.TAG_NAME));
|
||||
config.cooldowns = new HashMap<>();
|
||||
ListTag cools = tag.getList(Cooldown.TAG_NAME, ListTag.TAG_COMPOUND);
|
||||
for(Tag cooldown : cools)
|
||||
{
|
||||
Cooldown cd = Cooldown.deserialize((CompoundTag) cooldown);
|
||||
config.cooldowns.put(cd.Command, cd);
|
||||
}
|
||||
config.back = Back.deserialize(tag.getCompound(Back.TAG_NAME));
|
||||
config.teleport = Teleportation.deserialize(tag.getCompound(Teleportation.TAG_NAME));
|
||||
config.messages = Messages.deserialize(tag.getCompound(Messages.TAG_NAME));
|
||||
if(tag.contains(Bottles.TAG_NAME))
|
||||
{
|
||||
config.bottles = Bottles.deserialize(tag.getCompound(Bottles.TAG_NAME));
|
||||
} else config.bottles = new Bottles();
|
||||
try {
|
||||
AriasEssentials.LOGGER.info("Loading Aria's Essentials configuration for - Server");
|
||||
config.costs = Costs.deserialize(tag.getCompound(Costs.TAG_NAME));
|
||||
config.limits = Limitations.deserialize(tag.getCompound(Limitations.TAG_NAME));
|
||||
config.cooldowns = new HashMap<>();
|
||||
ListTag cools = tag.getList(Cooldown.TAG_NAME, ListTag.TAG_COMPOUND);
|
||||
for(Tag cooldown : cools)
|
||||
{
|
||||
Cooldown cd = Cooldown.deserialize((CompoundTag) cooldown);
|
||||
config.cooldowns.put(cd.Command, cd);
|
||||
}
|
||||
config.back = Back.deserialize(tag.getCompound(Back.TAG_NAME));
|
||||
config.teleport = Teleportation.deserialize(tag.getCompound(Teleportation.TAG_NAME));
|
||||
config.messages = Messages.deserialize(tag.getCompound(Messages.TAG_NAME));
|
||||
if(tag.contains(Bottles.TAG_NAME))
|
||||
{
|
||||
config.bottles = Bottles.deserialize(tag.getCompound(Bottles.TAG_NAME));
|
||||
} else config.bottles = new Bottles();
|
||||
|
||||
if(tag.contains(CreeperHeal.TAG_NAME))
|
||||
{
|
||||
config.creeperHeal = CreeperHeal.deserialize(tag.getCompound(CreeperHeal.TAG_NAME));
|
||||
if(tag.contains(CreeperHeal.TAG_NAME))
|
||||
{
|
||||
config.creeperHeal = CreeperHeal.deserialize(tag.getCompound(CreeperHeal.TAG_NAME));
|
||||
} else config.creeperHeal = new CreeperHeal();
|
||||
|
||||
AriasEssentials.LOGGER.info("Aria's Essentials Server Configuration Loaded");
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,7 +65,7 @@ public class AEServerConfig
|
|||
|
||||
public static void loadFromFile()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("server.snbt");
|
||||
Path serverConfig = EssentialsDatastore.of("server.snbt",false);
|
||||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import dev.zontreck.ariaslib.util.Lists;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.libzontreck.util.TagUtils;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
|
@ -13,22 +15,16 @@ public class CreeperHeal
|
|||
{
|
||||
public static final String TAG_NAME = "creeper_heal";
|
||||
public static final String TAG_BLACKLIST = "blacklisted_dims";
|
||||
public static final String TAG_VERSION = "version";
|
||||
public static final String TAG_DURATION = "duration";
|
||||
|
||||
|
||||
public List<String> blacklistedDimensions = new ArrayList<>();
|
||||
public int version = 0;
|
||||
public List<String> blacklistedDimensions = Lists.of("minecraft:the_nether", "minecraft:the_end");
|
||||
|
||||
public int duration = 40; // Once every 2 seconds
|
||||
|
||||
|
||||
public static final int VERSION = 1;
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt(TAG_VERSION, version);
|
||||
ListTag blacklist = new ListTag();
|
||||
for(String dimension : blacklistedDimensions)
|
||||
{
|
||||
|
@ -43,22 +39,13 @@ public class CreeperHeal
|
|||
public static CreeperHeal deserialize(CompoundTag tag)
|
||||
{
|
||||
CreeperHeal heal = new CreeperHeal();
|
||||
heal.version = tag.getInt(TAG_VERSION);
|
||||
heal.duration = TagUtils.intOr(tag, TAG_DURATION, 40);
|
||||
|
||||
if(heal.version == 0){
|
||||
heal.version = VERSION;
|
||||
return heal;
|
||||
}
|
||||
|
||||
if(heal.version >= 1)
|
||||
ListTag lst = tag.getList(TAG_BLACKLIST, StringTag.TAG_STRING);
|
||||
heal.blacklistedDimensions.clear();
|
||||
for(Tag t : lst)
|
||||
{
|
||||
|
||||
ListTag lst = tag.getList(TAG_BLACKLIST, StringTag.TAG_STRING);
|
||||
for(Tag t : lst)
|
||||
{
|
||||
heal.blacklistedDimensions.add(t.getAsString());
|
||||
}
|
||||
heal.duration = tag.getInt(TAG_DURATION);
|
||||
heal.blacklistedDimensions.add(t.getAsString());
|
||||
}
|
||||
|
||||
return heal;
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package dev.zontreck.essentials.events;
|
||||
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueue;
|
||||
import dev.zontreck.libzontreck.memory.world.BlockRestoreQueueRegistry;
|
||||
import dev.zontreck.libzontreck.memory.world.SavedBlock;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3i;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MainEventHandlers
|
||||
{
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onExplosionEvent(ExplosionEvent event)
|
||||
{
|
||||
for(BlockPos pos : event.getExplosion().getToBlow())
|
||||
{
|
||||
SavedBlock sb = SavedBlock.takeSnapshot(new Vector3i(pos), event.getLevel());
|
||||
|
||||
BlockRestoreQueue queue = BlockRestoreQueueRegistry.getQueue("creeperheal");
|
||||
queue.enqueueBlock(sb);
|
||||
|
||||
event.getLevel().removeBlockEntity(pos);
|
||||
event.getLevel().setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_CLIENTS, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import dev.zontreck.essentials.antiexplode.CreeperHealQueue;
|
|||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.essentials.util.BackPositionCaches;
|
||||
import dev.zontreck.libzontreck.config.ServerConfig;
|
||||
import dev.zontreck.libzontreck.events.BlockRestoreQueueRegistrationEvent;
|
||||
import dev.zontreck.libzontreck.events.TeleportEvent;
|
||||
|
@ -14,6 +15,8 @@ import dev.zontreck.libzontreck.memory.world.BlockRestoreRunner;
|
|||
import dev.zontreck.libzontreck.memory.world.SavedBlock;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3i;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -33,7 +36,6 @@ public class Events
|
|||
TeleportContainer container = new TeleportContainer(ev.getPlayer(), ev.getPosition().Position.asMinecraftVector(), Vec2.ZERO, ev.getPosition().getActualDimension());
|
||||
|
||||
TeleportActioner.PerformTeleport(container, false);
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -41,21 +43,7 @@ public class Events
|
|||
{
|
||||
CreeperHealQueue queue = new CreeperHealQueue();
|
||||
event.register(queue);
|
||||
|
||||
BlockRestoreRunner runner = new BlockRestoreRunner(queue);
|
||||
AriasEssentials.executorService.scheduleAtFixedRate(runner, 0, AEServerConfig.getInstance().creeperHeal.duration * 1000 / 20, TimeUnit.MILLISECONDS);
|
||||
|
||||
queue.schedule(AEServerConfig.getInstance().creeperHeal.duration * 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onExplosionEvent(ExplosionEvent.Detonate event)
|
||||
{
|
||||
for(BlockPos pos : event.getAffectedBlocks())
|
||||
{
|
||||
SavedBlock sb = SavedBlock.takeSnapshot(new Vector3i(pos), event.getLevel());
|
||||
|
||||
BlockRestoreQueue queue = BlockRestoreQueueRegistry.getQueue("creeperheal");
|
||||
queue.enqueueBlock(sb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue