From 325a6ed11fb77ed219f13dce6e2a4448f7cb9987 Mon Sep 17 00:00:00 2001 From: Zontreck Date: Sun, 16 Oct 2022 06:04:21 -0700 Subject: [PATCH] Push optimizations * Attempt to fix vault screen text offsets * Begin implementation of creeper heal ** Legacy implementation of ZSchem3 will be added, along with modded implementation * Known: Will not build due to in-progress changes --- gradle.properties | 2 +- .../zontreck/otemod/antigrief/Handler.java | 58 ++++++++++++++ .../otemod/antigrief/StoredBlock.java | 65 +++++++++++++++ .../otemod/commands/antigrief/HealNow.java | 8 ++ .../otemod/commands/homes/HomeCommand.java | 23 +----- .../otemod/commands/homes/SetHomeCommand.java | 2 +- .../otemod/commands/warps/RTPWarpCommand.java | 2 +- .../otemod/commands/warps/SetWarpCommand.java | 2 +- .../otemod/commands/warps/WarpCommand.java | 20 +---- .../zontreck/otemod/containers/Vector3.java | 13 +++ .../otemod/containers/WorldPosition.java | 79 +++++++++++++++++++ .../otemod/database/TeleportDestination.java | 33 +++++--- .../otemod/implementation/VaultScreen.java | 8 +- src/main/resources/META-INF/mods.toml | 2 +- .../worldgen/noise_settings/resource.json | 12 +-- 15 files changed, 261 insertions(+), 68 deletions(-) create mode 100644 src/main/java/dev/zontreck/otemod/antigrief/Handler.java create mode 100644 src/main/java/dev/zontreck/otemod/antigrief/StoredBlock.java create mode 100644 src/main/java/dev/zontreck/otemod/commands/antigrief/HealNow.java create mode 100644 src/main/java/dev/zontreck/otemod/containers/WorldPosition.java diff --git a/gradle.properties b/gradle.properties index 74d4abc..3946841 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G org.gradle.daemon=false -my_version=1.3.4.1 +my_version=1.3.4.2 mc_version=1.19.2 forge_version=43.1.32 diff --git a/src/main/java/dev/zontreck/otemod/antigrief/Handler.java b/src/main/java/dev/zontreck/otemod/antigrief/Handler.java new file mode 100644 index 0000000..f6a8904 --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/antigrief/Handler.java @@ -0,0 +1,58 @@ +package dev.zontreck.otemod.antigrief; + +import java.util.Collection; + +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.event.level.ChunkDataEvent; +import net.minecraftforge.event.level.ExplosionEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class Handler +{ + private static final String EXPLOSION_HEAL_TAG = "OTEEH"; + + + @OnlyIn(Dist.DEDICATED_SERVER) + @SubscribeEvent + public void onChunkLoad(final ChunkDataEvent.Load event) + { + final CompoundTag EHTag = event.getData().getCompound(EXPLOSION_HEAL_TAG); + if(!EHTag.isEmpty()) + { + final CompoundTag healer = EHTag.getCompound("healer"); + if(!healer.isEmpty()){ + // This would re-queue the healer + } + } + } + + @OnlyIn(Dist.DEDICATED_SERVER) + @SubscribeEvent + public void onDetonation(ExplosionEvent.Detonate event) + { + ServerLevel level = (ServerLevel)event.getLevel(); + + Entity exploder = event.getExplosion().getExploder(); + + if(exploder==null)return ; // TODO: Make this check config + + final Collection affectedBlocks = buildBlocks(level, event.getAffectedBlocks()); + } + + private Collection buildBlocks(ServerLevel level, Collection positions) + { + for(final BlockPos pos : positions) + { + final BlockState state = level.getBlockState(pos); + + + } + } +} diff --git a/src/main/java/dev/zontreck/otemod/antigrief/StoredBlock.java b/src/main/java/dev/zontreck/otemod/antigrief/StoredBlock.java new file mode 100644 index 0000000..7afbbae --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/antigrief/StoredBlock.java @@ -0,0 +1,65 @@ +package dev.zontreck.otemod.antigrief; + +import dev.zontreck.otemod.OTEMod; +import dev.zontreck.otemod.commands.teleport.TeleportContainer; +import dev.zontreck.otemod.containers.Vector3; +import dev.zontreck.otemod.containers.WorldPosition; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.TagBuilder; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.storage.ChunkSerializer; + +public class StoredBlock { + public CompoundTag blockData; + + private WorldPosition position; + private BlockState state; + + public StoredBlock(final BlockPos pos, final BlockState toSave, final ServerLevel lvl) + { + position = new WorldPosition(new Vector3(pos), lvl); + + this.state=toSave; + } + + public StoredBlock(final CompoundTag tag) + { + this.deserialize(tag); + } + + + public final BlockPos getPos() + { + return pos; + } + + public final BlockState getState() + { + return state; + } + + public final int getChunkX() + { + return pos.getX() >> 4; + } + + public final int getChunkZ() + { + return pos.getZ() >> 4; + } + + + public CompoundTag serialize() + { + final CompoundTag tag = new CompoundTag(); + + + tag.put("pos", ) + } + + +} diff --git a/src/main/java/dev/zontreck/otemod/commands/antigrief/HealNow.java b/src/main/java/dev/zontreck/otemod/commands/antigrief/HealNow.java new file mode 100644 index 0000000..de5b6a7 --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/commands/antigrief/HealNow.java @@ -0,0 +1,8 @@ +package dev.zontreck.otemod.commands.antigrief; + +// This will accelerate the healing queue, not do it instantly! +// The queue will get processed at a rate of 10* the configured rate. +public class HealNow +{ + +} diff --git a/src/main/java/dev/zontreck/otemod/commands/homes/HomeCommand.java b/src/main/java/dev/zontreck/otemod/commands/homes/HomeCommand.java index b517f52..52e1c73 100644 --- a/src/main/java/dev/zontreck/otemod/commands/homes/HomeCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/homes/HomeCommand.java @@ -86,28 +86,7 @@ public class HomeCommand { position = dest.Position.asMinecraftVector(); rot = dest.Rotation.asMinecraftVector(); - String dim = dest.Dimension; - String[] dims = dim.split(":"); - - ResourceLocation rl = new ResourceLocation(dims[0], dims[1]); - - ServerLevel dimL = null; - for (ServerLevel lServerLevel : p.server.getAllLevels()) { - ResourceLocation XL = lServerLevel.dimension().location(); - - if(XL.getNamespace().equals(rl.getNamespace())){ - if(XL.getPath().equals(rl.getPath())){ - dimL = lServerLevel; - } - } - } - - if(dimL == null) - { - SQL = "Failed to find the dimension"; - ctx.sendFailure(Component.literal(ChatColor.DARK_RED+ChatColor.BOLD+"FAILED TO LOCATE THAT DIMENSION. CONTACT THE SERVER ADMIN")); - return 1; - } + ServerLevel dimL = dest.getActualDimension(); TeleportActioner.ApplyTeleportEffect(p); // Instantiate a Teleport Runner diff --git a/src/main/java/dev/zontreck/otemod/commands/homes/SetHomeCommand.java b/src/main/java/dev/zontreck/otemod/commands/homes/SetHomeCommand.java index 07e092c..3c42121 100644 --- a/src/main/java/dev/zontreck/otemod/commands/homes/SetHomeCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/homes/SetHomeCommand.java @@ -52,7 +52,7 @@ public class SetHomeCommand { Vec3 position = p.position(); Vec2 rot = p.getRotationVector(); - TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel().dimension().location().getNamespace() + ":" + p.getLevel().dimension().location().getPath()); + TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); String SQL = "REPLACE INTO `homes` (user, home_name, teleporter) VALUES (?, ?, ?);"; PreparedStatement pstat = con.prepareStatement(SQL); diff --git a/src/main/java/dev/zontreck/otemod/commands/warps/RTPWarpCommand.java b/src/main/java/dev/zontreck/otemod/commands/warps/RTPWarpCommand.java index 97f1a94..fcc84ce 100644 --- a/src/main/java/dev/zontreck/otemod/commands/warps/RTPWarpCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/warps/RTPWarpCommand.java @@ -49,7 +49,7 @@ public class RTPWarpCommand { Vec3 position = p.position(); Vec2 rot = p.getRotationVector(); - TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel().dimension().location().getNamespace() + ":" + p.getLevel().dimension().location().getPath()); + TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); String SQL = "REPLACE INTO `warps` (warpname, owner, warptype, teleporter) values (?, ?, ?, ?);"; pstat = con.prepareStatement(SQL); diff --git a/src/main/java/dev/zontreck/otemod/commands/warps/SetWarpCommand.java b/src/main/java/dev/zontreck/otemod/commands/warps/SetWarpCommand.java index 5e84a75..2b925c6 100644 --- a/src/main/java/dev/zontreck/otemod/commands/warps/SetWarpCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/warps/SetWarpCommand.java @@ -48,7 +48,7 @@ public class SetWarpCommand { Vec3 position = p.position(); Vec2 rot = p.getRotationVector(); - TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel().dimension().location().getNamespace() + ":" + p.getLevel().dimension().location().getPath()); + TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); String SQL = "REPLACE INTO `warps` (warpname, owner, warptype, teleporter) values (?, ?, ?, ?);"; pstat = con.prepareStatement(SQL); diff --git a/src/main/java/dev/zontreck/otemod/commands/warps/WarpCommand.java b/src/main/java/dev/zontreck/otemod/commands/warps/WarpCommand.java index 354dd27..6f758d6 100644 --- a/src/main/java/dev/zontreck/otemod/commands/warps/WarpCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/warps/WarpCommand.java @@ -59,27 +59,9 @@ public class WarpCommand { { TeleportDestination dest = new TeleportDestination(NbtUtils.snbtToStructure(rs.getString("teleporter"))); - String dim = dest.Dimension; - String[] dims = dim.split(":"); - ResourceLocation rl = new ResourceLocation(dims[0], dims[1]); + ServerLevel dimL = dest.getActualDimension(); - ServerLevel dimL = null; - for (ServerLevel lServerLevel : p.server.getAllLevels()) { - ResourceLocation XL = lServerLevel.dimension().location(); - - if(XL.getNamespace().equals(rl.getNamespace())){ - if(XL.getPath().equals(rl.getPath())){ - dimL = lServerLevel; - } - } - } - - if(dimL == null) - { - ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.literal(ChatColor.RED+"DIMENSION COULD NOT BE FOUND"), source.getServer()); - return 1; - } final int type = rs.getInt("warptype"); final ServerLevel f_dim = dimL; diff --git a/src/main/java/dev/zontreck/otemod/containers/Vector3.java b/src/main/java/dev/zontreck/otemod/containers/Vector3.java index 565ff46..c7daa00 100644 --- a/src/main/java/dev/zontreck/otemod/containers/Vector3.java +++ b/src/main/java/dev/zontreck/otemod/containers/Vector3.java @@ -1,6 +1,7 @@ package dev.zontreck.otemod.containers; import dev.zontreck.otemod.exceptions.InvalidDeserialization; +import net.minecraft.core.BlockPos; import net.minecraft.world.phys.Vec3; public class Vector3 @@ -13,6 +14,11 @@ public class Vector3 return new Vec3(x, y, z); } + public BlockPos asBlockPos() + { + return new BlockPos(asMinecraftVector()); + } + public Vector3() { @@ -32,6 +38,13 @@ public class Vector3 z=pos.z; } + public Vector3(BlockPos pos) + { + x=pos.getX(); + y=pos.getY(); + z=pos.getZ(); + } + public Vector3(String pos) throws InvalidDeserialization { // This will be serialized most likely from the ToString method diff --git a/src/main/java/dev/zontreck/otemod/containers/WorldPosition.java b/src/main/java/dev/zontreck/otemod/containers/WorldPosition.java new file mode 100644 index 0000000..556441c --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/containers/WorldPosition.java @@ -0,0 +1,79 @@ +package dev.zontreck.otemod.containers; + +import dev.zontreck.otemod.OTEMod; +import dev.zontreck.otemod.exceptions.InvalidDeserialization; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; + +public class WorldPosition +{ + + public Vector3 Position; + public String Dimension; + + public WorldPosition(CompoundTag tag) throws InvalidDeserialization + { + Position = new Vector3(tag.getString("Position")); + Dimension = tag.getString("Dimension"); + + } + + public WorldPosition(Vector3 pos, String dim) + { + Position=pos; + Dimension=dim; + } + + public WorldPosition(Vector3 pos, ServerLevel lvl) + { + Position=pos; + Dimension = lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath(); + } + + @Override + public String toString() + { + return NbtUtils.structureToSnbt(serialize()); + } + + public CompoundTag serialize() + { + CompoundTag tag = new CompoundTag(); + + tag.putString("Position", Position.toString()); + tag.putString("Dimension", Dimension); + + return tag; + } + + + + public ServerLevel getActualDimension() + { + + String dim = Dimension; + String[] dims = dim.split(":"); + + ResourceLocation rl = new ResourceLocation(dims[0], dims[1]); + ServerLevel dimL = null; + for (ServerLevel lServerLevel : OTEMod.THE_SERVER.getAllLevels()) { + ResourceLocation XL = lServerLevel.dimension().location(); + + if(XL.getNamespace().equals(rl.getNamespace())){ + if(XL.getPath().equals(rl.getPath())){ + dimL = lServerLevel; + } + } + } + + if(dimL == null) + { + OTEMod.LOGGER.error("DIMENSION COULD NOT BE FOUND : "+Dimension); + return null; + } + + return dimL; + } +} diff --git a/src/main/java/dev/zontreck/otemod/database/TeleportDestination.java b/src/main/java/dev/zontreck/otemod/database/TeleportDestination.java index a52375a..67c9701 100644 --- a/src/main/java/dev/zontreck/otemod/database/TeleportDestination.java +++ b/src/main/java/dev/zontreck/otemod/database/TeleportDestination.java @@ -2,41 +2,50 @@ package dev.zontreck.otemod.database; import dev.zontreck.otemod.containers.Vector2; import dev.zontreck.otemod.containers.Vector3; +import dev.zontreck.otemod.containers.WorldPosition; import dev.zontreck.otemod.exceptions.InvalidDeserialization; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; +import net.minecraft.server.level.ServerLevel; /** * This defines the data structure, and methods for deserializing and serializing teleport destinations, for easier storage in the database **/ -public class TeleportDestination { - public Vector3 Position; +public class TeleportDestination extends WorldPosition +{ public Vector2 Rotation; - public String Dimension; public TeleportDestination(CompoundTag tag) throws InvalidDeserialization { - Position = new Vector3(tag.getString("Position")); + super(tag); Rotation = new Vector2(tag.getString("Rotation")); - Dimension = tag.getString("Dimension"); } public TeleportDestination(Vector3 pos, Vector2 rot, String dim) { - Position = pos; + super(pos, dim); Rotation = rot; - Dimension = dim; + } + + public TeleportDestination(Vector3 pos, Vector2 rot, ServerLevel dim) + { + super(pos,dim); + Rotation=rot; } @Override public String toString() { - CompoundTag tag = new CompoundTag(); - tag.putString("Position", Position.toString()); + + return NbtUtils.structureToSnbt(serialize()); + + } + + public CompoundTag serialize(){ + + CompoundTag tag = super.serialize(); tag.putString("Rotation", Rotation.toString()); - tag.putString("Dimension", Dimension); - - return NbtUtils.structureToSnbt(tag); + return tag; } } diff --git a/src/main/java/dev/zontreck/otemod/implementation/VaultScreen.java b/src/main/java/dev/zontreck/otemod/implementation/VaultScreen.java index 759fa02..eac23eb 100644 --- a/src/main/java/dev/zontreck/otemod/implementation/VaultScreen.java +++ b/src/main/java/dev/zontreck/otemod/implementation/VaultScreen.java @@ -37,16 +37,16 @@ public class VaultScreen extends AbstractContainerScreen super.render(stack, mouseX, mouseY, partialTicks); this.renderTooltip(stack, mouseX, mouseY); - //this.font.draw(stack, this.title, this.leftPos + 17, this.topPos + 15, 0xFFFFFF); - //this.font.draw(stack, this.playerInventoryTitle, this.leftPos + 17, this.topPos + 123, 0xFFFFFF); + this.font.draw(stack, this.title, this.leftPos + 17, this.topPos + 15, 0xFFFFFF); + this.font.draw(stack, this.playerInventoryTitle, this.leftPos + 17, this.topPos + 123, 0xFFFFFF); } @Override protected void renderLabels(PoseStack stack, int mouseX, int mouseY) { - this.font.draw(stack, this.title.getString(), this.leftPos + 17, this.topPos + 15, 0xFFFFFF); + //this.font.draw(stack, this.title.getString(), this.leftPos + 17, this.topPos + 15, 0xFFFFFF); - this.font.draw(stack, this.playerInventoryTitle.getString(), this.leftPos + 17, this.topPos + 123, 0xFFFFFF); + //this.font.draw(stack, this.playerInventoryTitle.getString(), this.leftPos + 17, this.topPos + 123, 0xFFFFFF); } @Override diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 371b3c2..7cca8fa 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="otemod" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.3.4.1" #mandatory +version="1.3.4.2" #mandatory # A display name for the mod displayName="OTEMod Resources" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ diff --git a/src/main/resources/data/otemod/worldgen/noise_settings/resource.json b/src/main/resources/data/otemod/worldgen/noise_settings/resource.json index 9fd949b..60a0a59 100644 --- a/src/main/resources/data/otemod/worldgen/noise_settings/resource.json +++ b/src/main/resources/data/otemod/worldgen/noise_settings/resource.json @@ -275,8 +275,8 @@ "when_in_range": { "type": "minecraft:noise", "noise": "minecraft:ore_veininess", - "xz_scale": 5, - "y_scale": 5 + "xz_scale": 10, + "y_scale": 10 }, "when_out_of_range": 0 } @@ -298,8 +298,8 @@ "when_in_range": { "type": "minecraft:noise", "noise": "minecraft:ore_vein_a", - "xz_scale": 8, - "y_scale": 8 + "xz_scale": 16, + "y_scale": 16 }, "when_out_of_range": 0 } @@ -317,8 +317,8 @@ "when_in_range": { "type": "minecraft:noise", "noise": "minecraft:ore_vein_b", - "xz_scale": 8, - "y_scale": 8 + "xz_scale": 16, + "y_scale": 16 }, "when_out_of_range": 0 }