From 5eeb71414539b8f6c46b61ca941a04817b3cdfeb Mon Sep 17 00:00:00 2001 From: OmerBenGera Date: Wed, 3 Aug 2022 21:32:39 +0300 Subject: [PATCH] Moved all nms classes to their own version packages --- .../wildloaders/WildLoadersPlugin.java | 27 +- .../ChunkLoaderNPC.java} | 7 +- .../EntityHolograms.java} | 6 +- .../NMSAdapter.java} | 172 ++------- .../loader/TileEntityChunkLoader.java | 129 +++++++ .../ChunkLoaderNPC.java} | 7 +- .../EntityHolograms.java} | 6 +- .../NMSAdapter.java} | 158 +-------- .../loader/TileEntityChunkLoader.java | 144 ++++++++ .../ChunkLoaderNPC.java} | 7 +- .../EntityHolograms.java} | 6 +- .../NMSAdapter.java} | 177 +--------- .../loader/TileEntityChunkLoader.java | 140 ++++++++ .../loader/TileEntityChunkLoaderTicker.java | 28 ++ .../nms/ChunkLoaderNPC_v1_18_R1.java | 150 -------- .../wildloaders/nms/NMSAdapter_v1_18_R1.java | 333 ------------------ .../wildloaders/nms/NMSMappings_v1_18_R1.java | 143 -------- .../nms/v1_18_R1/ChunkLoaderNPC.java | 207 +++++++++++ .../EntityHolograms.java} | 87 ++++- .../wildloaders/nms/v1_18_R1/NMSAdapter.java | 200 +++++++++++ .../loader/TileEntityChunkLoader.java | 161 +++++++++ .../loader/TileEntityChunkLoaderTicker.java | 46 +++ .../nms/v1_18_R1/mappings/MappedObject.java | 15 + .../net/minecraft/core/BlockPosition.java | 40 +++ .../net/minecraft/nbt/NBTTagCompound.java | 77 ++++ .../net/minecraft/world/entity/Entity.java | 29 ++ .../net/minecraft/world/item/ItemStack.java | 29 ++ .../world/level/ChunkCoordIntPair.java | 36 ++ .../net/minecraft/world/level/World.java | 87 +++++ .../world/level/block/entity/TileEntity.java | 22 ++ .../world/level/block/state/IBlockData.java | 29 ++ .../minecraft/world/level/chunk/Chunk.java | 33 ++ .../nms/ChunkLoaderNPC_v1_18_R2.java | 150 -------- .../nms/EntityHolograms_v1_18_R2.java | 168 --------- .../wildloaders/nms/NMSAdapter_v1_18_R2.java | 333 ------------------ .../wildloaders/nms/NMSMappings_v1_18_R2.java | 144 -------- .../nms/v1_18_R2/ChunkLoaderNPC.java | 207 +++++++++++ .../nms/v1_18_R2/EntityHolograms.java | 245 +++++++++++++ .../wildloaders/nms/v1_18_R2/NMSAdapter.java | 200 +++++++++++ .../loader/TileEntityChunkLoader.java | 161 +++++++++ .../loader/TileEntityChunkLoaderTicker.java | 46 +++ .../nms/v1_18_R2/mappings/MappedObject.java | 15 + .../net/minecraft/core/BlockPosition.java | 40 +++ .../net/minecraft/nbt/NBTTagCompound.java | 77 ++++ .../net/minecraft/world/entity/Entity.java | 29 ++ .../net/minecraft/world/item/ItemStack.java | 29 ++ .../world/level/ChunkCoordIntPair.java | 36 ++ .../net/minecraft/world/level/World.java | 87 +++++ .../world/level/block/entity/TileEntity.java | 22 ++ .../world/level/block/state/IBlockData.java | 29 ++ .../minecraft/world/level/chunk/Chunk.java | 33 ++ v1_19_R1/build.gradle | 2 +- .../nms/ChunkLoaderNPC_v1_19_R1.java | 150 -------- .../nms/EntityHolograms_v1_19_R1.java | 168 --------- .../wildloaders/nms/NMSAdapter_v1_19_R1.java | 333 ------------------ .../wildloaders/nms/NMSMappings_v1_19_R1.java | 144 -------- .../nms/v1_19_R1/ChunkLoaderNPC.java | 207 +++++++++++ .../nms/v1_19_R1/EntityHolograms.java | 245 +++++++++++++ .../wildloaders/nms/v1_19_R1/NMSAdapter.java | 200 +++++++++++ .../loader/TileEntityChunkLoader.java | 161 +++++++++ .../loader/TileEntityChunkLoaderTicker.java | 46 +++ .../nms/v1_19_R1/mappings/MappedObject.java | 15 + .../net/minecraft/core/BlockPosition.java | 40 +++ .../net/minecraft/nbt/NBTTagCompound.java | 77 ++++ .../net/minecraft/world/entity/Entity.java | 29 ++ .../net/minecraft/world/item/ItemStack.java | 29 ++ .../world/level/ChunkCoordIntPair.java | 36 ++ .../net/minecraft/world/level/World.java | 87 +++++ .../world/level/block/entity/TileEntity.java | 22 ++ .../world/level/block/state/IBlockData.java | 29 ++ .../minecraft/world/level/chunk/Chunk.java | 33 ++ .../ChunkLoaderNPC.java} | 7 +- .../NMSAdapter.java} | 76 +--- .../v1_7_R4/loader/TileEntityChunkLoader.java | 63 ++++ .../ChunkLoaderNPC.java} | 7 +- .../EntityHolograms.java} | 6 +- .../NMSAdapter.java} | 142 +------- .../v1_8_R3/loader/TileEntityChunkLoader.java | 129 +++++++ 78 files changed, 4352 insertions(+), 2920 deletions(-) rename v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/{ChunkLoaderNPC_v1_12_R1.java => v1_12_R1/ChunkLoaderNPC.java} (95%) rename v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/{EntityHolograms_v1_12_R1.java => v1_12_R1/EntityHolograms.java} (95%) rename v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/{NMSAdapter_v1_12_R1.java => v1_12_R1/NMSAdapter.java} (54%) create mode 100644 v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/loader/TileEntityChunkLoader.java rename v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/{ChunkLoaderNPC_v1_16_R3.java => v1_16_R3/ChunkLoaderNPC.java} (95%) rename v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/{EntityHolograms_v1_16_R3.java => v1_16_R3/EntityHolograms.java} (95%) rename v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/{NMSAdapter_v1_16_R3.java => v1_16_R3/NMSAdapter.java} (54%) create mode 100644 v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/loader/TileEntityChunkLoader.java rename v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/{ChunkLoaderNPC_v1_17_R1.java => v1_17_R1/ChunkLoaderNPC.java} (93%) rename v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/{EntityHolograms_v1_17_R1.java => v1_17_R1/EntityHolograms.java} (95%) rename v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/{NMSAdapter_v1_17_R1.java => v1_17_R1/NMSAdapter.java} (53%) create mode 100644 v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoader.java create mode 100644 v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoaderTicker.java delete mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R1.java delete mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R1.java delete mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R1.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/ChunkLoaderNPC.java rename v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/{EntityHolograms_v1_18_R1.java => v1_18_R1/EntityHolograms.java} (50%) create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/NMSAdapter.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoader.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoaderTicker.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/MappedObject.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/core/BlockPosition.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/nbt/NBTTagCompound.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/entity/Entity.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/item/ItemStack.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/World.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java create mode 100644 v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/chunk/Chunk.java delete mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R2.java delete mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R2.java delete mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R2.java delete mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R2.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/ChunkLoaderNPC.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/EntityHolograms.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/NMSAdapter.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoader.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoaderTicker.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/MappedObject.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/core/BlockPosition.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/nbt/NBTTagCompound.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/entity/Entity.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/item/ItemStack.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/ChunkCoordIntPair.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/World.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/entity/TileEntity.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/state/IBlockData.java create mode 100644 v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/chunk/Chunk.java delete mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_19_R1.java delete mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_19_R1.java delete mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_19_R1.java delete mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_19_R1.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/ChunkLoaderNPC.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/EntityHolograms.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/NMSAdapter.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoader.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoaderTicker.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/MappedObject.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/core/BlockPosition.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/nbt/NBTTagCompound.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/entity/Entity.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/item/ItemStack.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/World.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java create mode 100644 v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/chunk/Chunk.java rename v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/{ChunkLoaderNPC_v1_7_R4.java => v1_7_R4/ChunkLoaderNPC.java} (94%) rename v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/{NMSAdapter_v1_7_R4.java => v1_7_R4/NMSAdapter.java} (74%) create mode 100644 v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/loader/TileEntityChunkLoader.java rename v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/{ChunkLoaderNPC_v1_8_R3.java => v1_8_R3/ChunkLoaderNPC.java} (95%) rename v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/{EntityHolograms_v1_8_R3.java => v1_8_R3/EntityHolograms.java} (94%) rename v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/{NMSAdapter_v1_8_R3.java => v1_8_R3/NMSAdapter.java} (57%) create mode 100644 v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/loader/TileEntityChunkLoader.java diff --git a/src/main/java/com/bgsoftware/wildloaders/WildLoadersPlugin.java b/src/main/java/com/bgsoftware/wildloaders/WildLoadersPlugin.java index b297f5a..27968c0 100644 --- a/src/main/java/com/bgsoftware/wildloaders/WildLoadersPlugin.java +++ b/src/main/java/com/bgsoftware/wildloaders/WildLoadersPlugin.java @@ -41,13 +41,13 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders { loadNMSAdapter(); loadAPI(); - if(!shouldEnable) + if (!shouldEnable) log("&cThere was an error while loading the plugin."); } @Override public void onEnable() { - if(!shouldEnable) { + if (!shouldEnable) { Bukkit.getPluginManager().disablePlugin(this); return; } @@ -70,7 +70,7 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders { Locale.reload(); - if(Updater.isOutdated()) { + if (Updater.isOutdated()) { log(""); log("A new version is available (v" + Updater.getLatestVersion() + ")!"); log("Version's description: \"" + Updater.getVersionDescription() + "\""); @@ -82,29 +82,30 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders { @Override public void onDisable() { - if(shouldEnable) { + if (shouldEnable) { Database.stop(); loadersHandler.removeChunkLoaders(); npcHandler.killAllNPCs(); } } - private void loadNMSAdapter(){ + private void loadNMSAdapter() { String version = getServer().getClass().getPackage().getName().split("\\.")[3]; - try{ - nmsAdapter = (NMSAdapter) Class.forName("com.bgsoftware.wildloaders.nms.NMSAdapter_" + version).newInstance(); - } catch(ClassNotFoundException | InstantiationException | IllegalAccessException ex){ + try { + nmsAdapter = (NMSAdapter) Class.forName(String.format("com.bgsoftware.wildloaders.nms.%s.NMSAdapter", version)).newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { + shouldEnable = false; log("Couldn't load up with an adapter " + version + ". Please contact @Ome_R"); getServer().getPluginManager().disablePlugin(this); } } - private void loadAPI(){ - try{ + private void loadAPI() { + try { Field instance = WildLoadersAPI.class.getDeclaredField("instance"); instance.setAccessible(true); instance.set(null, this); - }catch(Exception ex){ + } catch (Exception ex) { log("Failed to set-up API - disabling plugin..."); ex.printStackTrace(); shouldEnable = false; @@ -138,11 +139,11 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders { return dataHandler; } - public static void log(String message){ + public static void log(String message) { plugin.getLogger().info(message); } - public static WildLoadersPlugin getPlugin(){ + public static WildLoadersPlugin getPlugin() { return plugin; } diff --git a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_12_R1.java b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/ChunkLoaderNPC.java similarity index 95% rename from v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_12_R1.java rename to v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/ChunkLoaderNPC.java index a9b1a16..cb9dd48 100644 --- a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_12_R1.java +++ b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/ChunkLoaderNPC.java @@ -1,6 +1,5 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_12_R1; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.handlers.NPCHandler; import com.bgsoftware.wildloaders.npc.DummyChannel; import com.mojang.authlib.GameProfile; @@ -32,11 +31,11 @@ import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.util.UUID; -public final class ChunkLoaderNPC_v1_12_R1 extends EntityPlayer implements ChunkLoaderNPC { +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - public ChunkLoaderNPC_v1_12_R1(Location location, UUID uuid){ + public ChunkLoaderNPC(Location location, UUID uuid){ super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(), new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())), diff --git a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_12_R1.java b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/EntityHolograms.java similarity index 95% rename from v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_12_R1.java rename to v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/EntityHolograms.java index 5c01ab4..5b3732e 100644 --- a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_12_R1.java +++ b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/EntityHolograms.java @@ -1,4 +1,4 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_12_R1; import com.bgsoftware.wildloaders.api.holograms.Hologram; import net.minecraft.server.v1_12_R1.AxisAlignedBB; @@ -18,9 +18,9 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.entity.Entity; @SuppressWarnings("unused") -public final class EntityHolograms_v1_12_R1 extends EntityArmorStand implements Hologram { +public final class EntityHolograms extends EntityArmorStand implements Hologram { - EntityHolograms_v1_12_R1(World world, double x, double y, double z){ + public EntityHolograms(World world, double x, double y, double z) { super(world, x, y, z); setInvisible(true); setSmall(true); diff --git a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/NMSAdapter.java similarity index 54% rename from v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java rename to v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/NMSAdapter.java index 7a3db0e..59318e9 100644 --- a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java +++ b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/NMSAdapter.java @@ -1,15 +1,13 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_12_R1; +import com.bgsoftware.common.reflection.ReflectMethod; import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_12_R1.loader.TileEntityChunkLoader; import net.minecraft.server.v1_12_R1.Block; import net.minecraft.server.v1_12_R1.BlockPosition; import net.minecraft.server.v1_12_R1.Chunk; -import net.minecraft.server.v1_12_R1.ITickable; import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.NBTTagCompound; import net.minecraft.server.v1_12_R1.NBTTagList; @@ -24,34 +22,21 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_12_R1.util.LongHash; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.UUID; @SuppressWarnings({"ConstantConditions", "unused"}) -public final class NMSAdapter_v1_12_R1 implements NMSAdapter { +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); - private static Method compoundLoadMethod = null; - static { - try{ - //noinspection JavaReflectionMemberAccess - compoundLoadMethod = TileEntity.class.getMethod("load", NBTTagCompound.class); - }catch (Exception ignored){} - } + private static final ReflectMethod TILE_ENTITY_LOAD = new ReflectMethod<>(TileEntity.class, "load", NBTTagCompound.class); @Override public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); - if(!tagCompound.hasKeyOfType(key, 8)) + if (!tagCompound.hasKeyOfType(key, 8)) return def; return tagCompound.getString(key); @@ -74,7 +59,7 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); - if(!tagCompound.hasKeyOfType(key, 4)) + if (!tagCompound.hasKeyOfType(key, 4)) return def; return tagCompound.getLong(key); @@ -120,8 +105,8 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { } @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_12_R1(location, uuid); + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(location, uuid); } @Override @@ -133,16 +118,15 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { NBTTagCompound nbtTagCompound = new NBTTagCompound(); tileEntity.save(nbtTagCompound); nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - - try { - compoundLoadMethod.invoke(tileEntity, nbtTagCompound); - } catch (Throwable ex) { + if (TILE_ENTITY_LOAD.isValid()) { + TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound); + } else { tileEntity.a(nbtTagCompound); } }); @@ -159,25 +143,24 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_12_R1::removeHologram); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); tileEntityChunkLoader.removed = true; world.tileEntityListTick.remove(tileEntityChunkLoader); } - if(spawnParticle) + if (spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { NBTTagCompound nbtTagCompound = new NBTTagCompound(); tileEntity.save(nbtTagCompound); nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - - try { - compoundLoadMethod.invoke(tileEntity, nbtTagCompound); - } catch (Throwable ex) { + if (TILE_ENTITY_LOAD.isValid()) { + TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound); + } else { tileEntity.a(nbtTagCompound); } }); @@ -193,120 +176,11 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { NBTTagCompound nbtTagCompound = new NBTTagCompound(); mobSpawner.save(nbtTagCompound); nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1)); - - try { - compoundLoadMethod.invoke(mobSpawner, nbtTagCompound); - }catch (Throwable ex){ + if (TILE_ENTITY_LOAD.isValid()) { + TILE_ENTITY_LOAD.invoke(mobSpawner, nbtTagCompound); + } else { mobSpawner.a(nbtTagCompound); } } - private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - this.chunkLoader = (WChunkLoader) chunkLoader; - - setPosition(blockPosition); - a(world); - - loaderBlock = world.getType(blockPosition).getBlock(); - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = position.getY() + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_12_R1 hologram = new EntityHolograms_v1_12_R1(world, position.getX() + 0.5, currentY, position.getZ() + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - world.addEntity(hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - @Override - public void e() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_12_R1 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - private void updateName(EntityHolograms_v1_12_R1 hologram, String line){ - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - } diff --git a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/loader/TileEntityChunkLoader.java b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..04685d2 --- /dev/null +++ b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_12_R1/loader/TileEntityChunkLoader.java @@ -0,0 +1,129 @@ +package com.bgsoftware.wildloaders.nms.v1_12_R1.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_12_R1.EntityHolograms; +import net.minecraft.server.v1_12_R1.Block; +import net.minecraft.server.v1_12_R1.BlockPosition; +import net.minecraft.server.v1_12_R1.ITickable; +import net.minecraft.server.v1_12_R1.TileEntity; +import net.minecraft.server.v1_12_R1.World; +import org.bukkit.craftbukkit.v1_12_R1.util.LongHash; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + this.chunkLoader = (WChunkLoader) chunkLoader; + + setPosition(blockPosition); + a(world); + + loaderBlock = world.getType(blockPosition).getBlock(); + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = position.getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world, position.getX() + 0.5, currentY, position.getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + @Override + public void e() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + if (chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + private void updateName(EntityHolograms hologram, String line) { + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} + diff --git a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_16_R3.java b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/ChunkLoaderNPC.java similarity index 95% rename from v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_16_R3.java rename to v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/ChunkLoaderNPC.java index 092dd83..6f5d386 100644 --- a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_16_R3.java +++ b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/ChunkLoaderNPC.java @@ -1,6 +1,5 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_16_R3; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.handlers.NPCHandler; import com.bgsoftware.wildloaders.npc.DummyChannel; import com.mojang.authlib.GameProfile; @@ -31,13 +30,13 @@ import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.util.UUID; -public final class ChunkLoaderNPC_v1_16_R3 extends EntityPlayer implements ChunkLoaderNPC { +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); private boolean dieCall = false; - public ChunkLoaderNPC_v1_16_R3(Location location, UUID uuid) { + public ChunkLoaderNPC(Location location, UUID uuid) { super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(), new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())), diff --git a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_16_R3.java b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/EntityHolograms.java similarity index 95% rename from v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_16_R3.java rename to v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/EntityHolograms.java index f887e02..07dec23 100644 --- a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_16_R3.java +++ b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/EntityHolograms.java @@ -1,4 +1,4 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_16_R3; import com.bgsoftware.wildloaders.api.holograms.Hologram; import net.minecraft.server.v1_16_R3.AxisAlignedBB; @@ -22,11 +22,11 @@ import org.bukkit.entity.Entity; import javax.annotation.Nullable; @SuppressWarnings("unused") -public final class EntityHolograms_v1_16_R3 extends EntityArmorStand implements Hologram { +public final class EntityHolograms extends EntityArmorStand implements Hologram { private CraftEntity bukkitEntity; - EntityHolograms_v1_16_R3(World world, double x, double y, double z){ + public EntityHolograms(World world, double x, double y, double z){ super(world, x, y, z); setInvisible(true); setSmall(true); diff --git a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R3.java b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/NMSAdapter.java similarity index 54% rename from v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R3.java rename to v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/NMSAdapter.java index a6afae9..fd84224 100644 --- a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R3.java +++ b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/NMSAdapter.java @@ -1,25 +1,20 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_16_R3; import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_16_R3.loader.TileEntityChunkLoader; import net.minecraft.server.v1_16_R3.Block; import net.minecraft.server.v1_16_R3.BlockPosition; import net.minecraft.server.v1_16_R3.Chunk; import net.minecraft.server.v1_16_R3.ChunkCoordIntPair; import net.minecraft.server.v1_16_R3.IBlockData; -import net.minecraft.server.v1_16_R3.ITickable; import net.minecraft.server.v1_16_R3.ItemStack; import net.minecraft.server.v1_16_R3.NBTTagCompound; import net.minecraft.server.v1_16_R3.NBTTagList; import net.minecraft.server.v1_16_R3.NBTTagLong; import net.minecraft.server.v1_16_R3.NBTTagString; -import net.minecraft.server.v1_16_R3.TileEntity; import net.minecraft.server.v1_16_R3.TileEntityMobSpawner; -import net.minecraft.server.v1_16_R3.TileEntityTypes; import net.minecraft.server.v1_16_R3.World; import net.minecraft.server.v1_16_R3.WorldServer; import org.bukkit.Location; @@ -27,16 +22,10 @@ import org.bukkit.craftbukkit.v1_16_R3.CraftChunk; import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.UUID; @SuppressWarnings("unused") -public final class NMSAdapter_v1_16_R3 implements NMSAdapter { +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); @@ -45,7 +34,7 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); - if(!tagCompound.hasKeyOfType(key, 8)) + if (!tagCompound.hasKeyOfType(key, 8)) return def; return tagCompound.getString(key); @@ -68,7 +57,7 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); - if(!tagCompound.hasKeyOfType(key, 4)) + if (!tagCompound.hasKeyOfType(key, 4)) return def; return tagCompound.getLong(key); @@ -114,8 +103,8 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter { } @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_16_R3(location, uuid); + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(location, uuid); } @Override @@ -128,7 +117,7 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); @@ -148,16 +137,16 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter { long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_16_R3::removeHologram); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); tileEntityChunkLoader.removed = true; world.tileEntityListTick.remove(tileEntityChunkLoader); } - if(spawnParticle) + if (spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); @@ -175,131 +164,10 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter { IBlockData blockData = world.getType(blockPosition); TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition); - if(mobSpawner == null) + if (mobSpawner == null) return; mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1; } - private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - super(TileEntityTypes.COMMAND_BLOCK); - - this.chunkLoader = (WChunkLoader) chunkLoader; - - setLocation(world, blockPosition); - - loaderBlock = world.getType(blockPosition).getBlock(); - - try { - // Not a method of Spigot - fixes https://github.com/OmerBenGera/WildLoaders/issues/2 - setCurrentChunk(world.getChunkAtWorldCoords(blockPosition)); - }catch (Throwable ignored){} - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = position.getY() + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_16_R3 hologram = new EntityHolograms_v1_16_R3(world, position.getX() + 0.5, currentY, position.getZ() + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - world.addEntity(hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - @Override - public void w() { - tick(); - } - - @Override - public void tick() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - assert world != null; - if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_16_R3 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - private void updateName(EntityHolograms_v1_16_R3 hologram, String line){ - assert chunkLoader.getWhoPlaced().getName() != null; - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - } diff --git a/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/loader/TileEntityChunkLoader.java b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..7b00e52 --- /dev/null +++ b/v1_16_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_16_R3/loader/TileEntityChunkLoader.java @@ -0,0 +1,144 @@ +package com.bgsoftware.wildloaders.nms.v1_16_R3.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_16_R3.EntityHolograms; +import net.minecraft.server.v1_16_R3.Block; +import net.minecraft.server.v1_16_R3.BlockPosition; +import net.minecraft.server.v1_16_R3.ChunkCoordIntPair; +import net.minecraft.server.v1_16_R3.ITickable; +import net.minecraft.server.v1_16_R3.TileEntity; +import net.minecraft.server.v1_16_R3.TileEntityTypes; +import net.minecraft.server.v1_16_R3.World; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + super(TileEntityTypes.COMMAND_BLOCK); + + this.chunkLoader = (WChunkLoader) chunkLoader; + + setLocation(world, blockPosition); + + loaderBlock = world.getType(blockPosition).getBlock(); + + try { + // Not a method of Spigot - fixes https://github.com/OmerBenGera/WildLoaders/issues/2 + setCurrentChunk(world.getChunkAtWorldCoords(blockPosition)); + } catch (Throwable ignored) { + } + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = position.getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world, position.getX() + 0.5, currentY, position.getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + @Override + public void w() { + tick(); + } + + @Override + public void tick() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + assert world != null; + if (chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + private void updateName(EntityHolograms hologram, String line) { + assert chunkLoader.getWhoPlaced().getName() != null; + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} + diff --git a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_17_R1.java b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/ChunkLoaderNPC.java similarity index 93% rename from v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_17_R1.java rename to v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/ChunkLoaderNPC.java index 5c50f16..1563fa2 100644 --- a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_17_R1.java +++ b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/ChunkLoaderNPC.java @@ -1,7 +1,6 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_17_R1; import com.bgsoftware.common.reflection.ReflectMethod; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.handlers.NPCHandler; import com.bgsoftware.wildloaders.npc.DummyChannel; import com.mojang.authlib.GameProfile; @@ -29,7 +28,7 @@ import org.bukkit.entity.Player; import java.util.UUID; -public final class ChunkLoaderNPC_v1_17_R1 extends EntityPlayer implements ChunkLoaderNPC { +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); @@ -38,7 +37,7 @@ public final class ChunkLoaderNPC_v1_17_R1 extends EntityPlayer implements Chunk private boolean dieCall = false; - public ChunkLoaderNPC_v1_17_R1(MinecraftServer minecraftServer, Location location, UUID uuid){ + public ChunkLoaderNPC(MinecraftServer minecraftServer, Location location, UUID uuid){ super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName()))); diff --git a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_17_R1.java b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/EntityHolograms.java similarity index 95% rename from v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_17_R1.java rename to v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/EntityHolograms.java index 9483180..87efb18 100644 --- a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_17_R1.java +++ b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/EntityHolograms.java @@ -1,4 +1,4 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_17_R1; import com.bgsoftware.wildloaders.api.holograms.Hologram; import net.minecraft.nbt.NBTTagCompound; @@ -24,13 +24,13 @@ import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; import javax.annotation.Nullable; @SuppressWarnings("unused") -public final class EntityHolograms_v1_17_R1 extends EntityArmorStand implements Hologram { +public final class EntityHolograms extends EntityArmorStand implements Hologram { private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); private CraftEntity bukkitEntity; - public EntityHolograms_v1_17_R1(World world, double x, double y, double z){ + public EntityHolograms(World world, double x, double y, double z){ super(world, x, y, z); setInvisible(true); setSmall(true); diff --git a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_17_R1.java b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/NMSAdapter.java similarity index 53% rename from v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_17_R1.java rename to v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/NMSAdapter.java index 164bc4a..1dad0c2 100644 --- a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_17_R1.java +++ b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/NMSAdapter.java @@ -1,12 +1,10 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_17_R1; import com.bgsoftware.common.reflection.ReflectMethod; import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_17_R1.loader.TileEntityChunkLoader; import net.minecraft.core.BlockPosition; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -21,7 +19,6 @@ import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.TickingBlockEntity; import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.chunk.Chunk; import org.bukkit.Bukkit; @@ -31,16 +28,10 @@ import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.UUID; @SuppressWarnings("unused") -public final class NMSAdapter_v1_17_R1 implements NMSAdapter { +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); @@ -52,7 +43,7 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); - if(!tagCompound.hasKeyOfType(key, 8)) + if (!tagCompound.hasKeyOfType(key, 8)) return def; return tagCompound.getString(key); @@ -75,7 +66,7 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); - if(!tagCompound.hasKeyOfType(key, 4)) + if (!tagCompound.hasKeyOfType(key, 4)) return def; return tagCompound.getLong(key); @@ -121,8 +112,8 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter { } @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_17_R1(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); } @Override @@ -135,7 +126,7 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.a(tileEntityChunkLoader.ticker); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.l.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().n = -1); @@ -155,15 +146,15 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter { long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_17_R1::removeHologram); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); tileEntityChunkLoader.removed = true; } - if(spawnParticle) + if (spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.l.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().n = 16); @@ -181,152 +172,10 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter { IBlockData blockData = world.getType(blockPosition); TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition); - if(mobSpawner == null) + if (mobSpawner == null) return; mobSpawner.getSpawner().n = reset ? 16 : -1; } - private static final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - private final TileEntityChunkLoaderTicker ticker; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - super(TileEntityTypes.v, blockPosition, world.getType(blockPosition)); - - this.chunkLoader = (WChunkLoader) chunkLoader; - this.ticker = new TileEntityChunkLoaderTicker(this); - - setWorld(world); - - loaderBlock = world.getType(blockPosition).getBlock(); - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = getPosition().getY() + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_17_R1 hologram = new EntityHolograms_v1_17_R1(world, - getPosition().getX() + 0.5, currentY, getPosition().getZ() + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - world.addEntity(hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - public void tick() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - assert this.n != null; - if(chunkLoader.isNotActive() || this.n.getType(getPosition()).getBlock() != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_17_R1 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - @Override - public boolean isRemoved() { - return removed || super.isRemoved(); - } - - private void updateName(EntityHolograms_v1_17_R1 hologram, String line){ - assert chunkLoader.getWhoPlaced().getName() != null; - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - - private record TileEntityChunkLoaderTicker( - TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { - - @Override - public void a() { - tileEntityChunkLoader.tick(); - } - - @Override - public boolean b() { - return tileEntityChunkLoader.isRemoved(); - } - - @Override - public BlockPosition c() { - return tileEntityChunkLoader.getPosition(); - } - - @Override - public String d() { - return TileEntityTypes.a(tileEntityChunkLoader.getTileType()) + ""; - } - } - } diff --git a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoader.java b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..bb2e28a --- /dev/null +++ b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoader.java @@ -0,0 +1,140 @@ +package com.bgsoftware.wildloaders.nms.v1_17_R1.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_17_R1.EntityHolograms; +import com.bgsoftware.wildloaders.nms.v1_17_R1.NMSAdapter; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.World; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + public final TileEntityChunkLoaderTicker ticker; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + super(TileEntityTypes.v, blockPosition, world.getType(blockPosition)); + + this.chunkLoader = (WChunkLoader) chunkLoader; + this.ticker = new TileEntityChunkLoaderTicker(this); + + setWorld(world); + + loaderBlock = world.getType(blockPosition).getBlock(); + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = getPosition().getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world, + getPosition().getX() + 0.5, currentY, getPosition().getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + public void tick() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + assert this.n != null; + if (chunkLoader.isNotActive() || this.n.getType(getPosition()).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + @Override + public boolean isRemoved() { + return removed || super.isRemoved(); + } + + private void updateName(EntityHolograms hologram, String line) { + assert chunkLoader.getWhoPlaced().getName() != null; + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} + diff --git a/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoaderTicker.java b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoaderTicker.java new file mode 100644 index 0000000..d01867a --- /dev/null +++ b/v1_17_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_17_R1/loader/TileEntityChunkLoaderTicker.java @@ -0,0 +1,28 @@ +package com.bgsoftware.wildloaders.nms.v1_17_R1.loader; + +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +public record TileEntityChunkLoaderTicker(TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { + + @Override + public void a() { + tileEntityChunkLoader.tick(); + } + + @Override + public boolean b() { + return tileEntityChunkLoader.isRemoved(); + } + + @Override + public BlockPosition c() { + return tileEntityChunkLoader.getPosition(); + } + + @Override + public String d() { + return TileEntityTypes.a(tileEntityChunkLoader.getTileType()) + ""; + } +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R1.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R1.java deleted file mode 100644 index 0cf539a..0000000 --- a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R1.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import com.bgsoftware.wildloaders.handlers.NPCHandler; -import com.bgsoftware.wildloaders.npc.DummyChannel; -import com.mojang.authlib.GameProfile; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.protocol.EnumProtocolDirection; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.PacketPlayInBlockDig; -import net.minecraft.network.protocol.game.PacketPlayInBlockPlace; -import net.minecraft.network.protocol.game.PacketPlayInChat; -import net.minecraft.network.protocol.game.PacketPlayInFlying; -import net.minecraft.network.protocol.game.PacketPlayInHeldItemSlot; -import net.minecraft.network.protocol.game.PacketPlayInUpdateSign; -import net.minecraft.network.protocol.game.PacketPlayInWindowClick; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.AxisAlignedBB; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; -import org.bukkit.entity.Player; - -import java.util.UUID; - -import static com.bgsoftware.wildloaders.nms.NMSMappings_v1_18_R1.*; - -public final class ChunkLoaderNPC_v1_18_R1 extends EntityPlayer implements ChunkLoaderNPC { - - private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - - private boolean dieCall = false; - - public ChunkLoaderNPC_v1_18_R1(MinecraftServer minecraftServer, Location location, UUID uuid) { - super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), - new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName()))); - - this.b = new DummyPlayerConnection(minecraftServer, this); - - NMSMappings_v1_18_R1.setGameMode(this.d, EnumGamemode.b); - clientViewDistance = 1; - - fauxSleeping = true; - - spawnIn(getWorld(this)); - setLocation(this, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - - addPlayerJoin(getWorldServer(this), this); - - super.a(EMPTY_BOUND); - } - - @Override - public UUID getUniqueId() { - return super.cm(); - } - - @Override - public void die() { - ah(); - } - - @Override - public AxisAlignedBB cx() { - return EMPTY_BOUND; - } - - @Override - public void a(RemovalReason removalReason) { - if (!dieCall) { - dieCall = true; - removePlayer(getWorldServer(this), this); - dieCall = false; - } else { - super.a(removalReason); - } - } - - @Override - public Location getLocation() { - return getBukkitEntity().getLocation(); - } - - @Override - public Player getPlayer() { - return getBukkitEntity(); - } - - private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer) { - worldServer.a(entityPlayer, RemovalReason.d); - } - - public static class DummyNetworkManager extends NetworkManager { - - DummyNetworkManager() { - super(EnumProtocolDirection.a); - this.k = new DummyChannel(); - this.l = null; - } - - } - - public static class DummyPlayerConnection extends PlayerConnection { - - DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) { - super(minecraftServer, new DummyNetworkManager(), entityPlayer); - } - - public void a(PacketPlayInWindowClick packetPlayInWindowClick) { - - } - - public void a(PacketPlayInFlying packetPlayInFlying) { - - } - - public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) { - - } - - public void a(PacketPlayInBlockDig packetPlayInBlockDig) { - - } - - public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) { - - } - - public void disconnect(String s) { - - } - - public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) { - - } - - public void a(PacketPlayInChat packetPlayInChat) { - - } - - public void a(Packet packet) { - - } - - } - -} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R1.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R1.java deleted file mode 100644 index acdae53..0000000 --- a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R1.java +++ /dev/null @@ -1,333 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.common.reflection.ReflectMethod; -import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; -import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagLong; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityTicker; -import net.minecraft.world.level.block.entity.TickingBlockEntity; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.Chunk; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_18_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_18_R1.CraftServer; -import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.bgsoftware.wildloaders.nms.NMSMappings_v1_18_R1.*; - -@SuppressWarnings("unused") -public final class NMSAdapter_v1_18_R1 implements NMSAdapter { - - private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); - - private static final ReflectMethod CREATE_TICKING_BLOCK = new ReflectMethod<>( - Chunk.class, "a", TileEntity.class, BlockEntityTicker.class); - - @Override - public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - if(!hasKeyOfType(tagCompound, key, 8)) - return def; - - return getString(tagCompound, key); - } - - @Override - public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - set(tagCompound, key, NBTTagString.a(value)); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - if(!hasKeyOfType(tagCompound, key, 4)) - return def; - - return getLong(tagCompound, key); - } - - @Override - public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - set(tagCompound, key, NBTTagLong.a(value)); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - - NBTTagCompound nbtTagCompound = getOrCreateTag(nmsItem); - - NBTTagCompound skullOwner = hasKey(nbtTagCompound, "SkullOwner") ? - getCompound(nbtTagCompound, "SkullOwner") : new NBTTagCompound(); - - NBTTagCompound properties = new NBTTagCompound(); - - NBTTagList textures = new NBTTagList(); - NBTTagCompound signature = new NBTTagCompound(); - setString(signature, "Value", texture); - textures.add(signature); - - set(properties, "textures", textures); - - set(skullOwner, "Properties", properties); - setString(skullOwner,"Id", UUID.randomUUID().toString()); - - set(nbtTagCompound, "SkullOwner", skullOwner); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_18_R1(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); - } - - @Override - public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) { - Location loaderLoc = chunkLoader.getLocation(); - assert loaderLoc.getWorld() != null; - WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); - - TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); - world.a(tileEntityChunkLoader.ticker); - - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { - Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); - getTileEntities(chunk).values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> getSpawner((TileEntityMobSpawner) tileEntity).m = -1); - - ChunkCoordIntPair chunkCoords = getPos(chunk); - - setForceLoaded(world, chunkCoords.c, chunkCoords.d, true); - } - - return tileEntityChunkLoader; - } - - @Override - public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) { - Location loaderLoc = chunkLoader.getLocation(); - assert loaderLoc.getWorld() != null; - WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); - - long tileEntityLong = ChunkCoordIntPair.a(getX(blockPosition) >> 4, getZ(blockPosition) >> 4); - TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_18_R1::removeHologram); - tileEntityChunkLoader.removed = true; - } - - if(spawnParticle) - world.a(null, 2001, blockPosition, getCombinedId(getType(world, blockPosition))); - - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { - Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); - getTileEntities(chunk).values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> getSpawner((TileEntityMobSpawner) tileEntity).m = 16); - - ChunkCoordIntPair chunkCoords = getPos(chunk); - - setForceLoaded(world, chunkCoords.c, chunkCoords.d, false); - } - } - - @Override - public void updateSpawner(Location location, boolean reset) { - assert location.getWorld() != null; - World world = ((CraftWorld) location.getWorld()).getHandle(); - - BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ()); - IBlockData blockData = getType(world, blockPosition); - TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) getTileEntity(world, blockPosition); - - if(mobSpawner == null) - return; - - getSpawner(mobSpawner).m = reset ? 16 : -1; - } - - private static final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - private final TileEntityChunkLoaderTicker ticker; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - super(TileEntityTypes.v, blockPosition, getType(world, blockPosition)); - - this.chunkLoader = (WChunkLoader) chunkLoader; - this.ticker = new TileEntityChunkLoaderTicker(this); - - a(world); - - loaderBlock = getBlock(getType(world, blockPosition)); - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(ChunkCoordIntPair.a(getX(blockPosition) >> 4, getZ(blockPosition) >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = getY(getPosition(this)) + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_18_R1 hologram = new EntityHolograms_v1_18_R1(world, - getX(getPosition(this)) + 0.5, currentY, getZ(getPosition(this)) + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - addEntity(world, hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - public void tick() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - assert this.n != null; - if(chunkLoader.isNotActive() || getBlock(getType(this.n, getPosition(this))) != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_18_R1 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - @Override - public boolean r() { - return removed || super.r(); - } - - private void updateName(EntityHolograms_v1_18_R1 hologram, String line){ - assert chunkLoader.getWhoPlaced().getName() != null; - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - - private record TileEntityChunkLoaderTicker( - TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { - - @Override - public void a() { - tileEntityChunkLoader.tick(); - } - - @Override - public boolean b() { - return tileEntityChunkLoader.r(); - } - - @Override - public BlockPosition c() { - return getPosition(tileEntityChunkLoader); - } - - @Override - public String d() { - return TileEntityTypes.a(getTileType(tileEntityChunkLoader)) + ""; - } - } - -} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R1.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R1.java deleted file mode 100644 index 407c8b2..0000000 --- a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R1.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.common.reflection.ReflectMethod; -import net.minecraft.core.BaseBlockPosition; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.PlayerInteractManager; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.level.MobSpawnerAbstract; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; - -import java.util.Map; - -public final class NMSMappings_v1_18_R1 { - - private static final ReflectMethod SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class, - 1, EnumGamemode.class, EnumGamemode.class); - - private NMSMappings_v1_18_R1() { - - } - - public static NBTTagCompound getOrCreateTag(ItemStack itemStack) { - return itemStack.t(); - } - - public static boolean hasKeyOfType(NBTTagCompound nbtTagCompound, String key, int type) { - return nbtTagCompound.b(key, type); - } - - public static String getString(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.l(key); - } - - public static void set(NBTTagCompound nbtTagCompound, String key, NBTBase nbtBase) { - nbtTagCompound.a(key, nbtBase); - } - - public static long getLong(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.i(key); - } - - public static boolean hasKey(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.e(key); - } - - public static NBTTagCompound getCompound(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.p(key); - } - - public static void setString(NBTTagCompound nbtTagCompound, String key, String value) { - nbtTagCompound.a(key, value); - } - - public static Map getTileEntities(IChunkAccess chunkAccess) { - return chunkAccess.i; - } - - public static MobSpawnerAbstract getSpawner(TileEntityMobSpawner tileEntityMobSpawner) { - return tileEntityMobSpawner.d(); - } - - public static void setForceLoaded(WorldServer worldServer, int chunkX, int chunkZ, boolean load) { - worldServer.a(chunkX, chunkZ, load); - } - - public static ChunkCoordIntPair getPos(IChunkAccess chunk) { - return chunk.f(); - } - - public static int getCombinedId(IBlockData blockData) { - return Block.i(blockData); - } - - public static int getX(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.u(); - } - - public static int getY(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.v(); - } - - public static int getZ(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.w(); - } - - public static IBlockData getType(World world, BlockPosition blockPosition) { - return world.a_(blockPosition); - } - - public static TileEntity getTileEntity(World world, BlockPosition blockPosition) { - return world.c_(blockPosition); - } - - public static Block getBlock(IBlockData blockData) { - return blockData.b(); - } - - public static BlockPosition getPosition(TileEntity tileEntity) { - return tileEntity.p(); - } - - public static void addEntity(World world, Entity entity) { - world.b(entity); - } - - public static TileEntityTypes getTileType(TileEntity tileEntity) { - return tileEntity.u(); - } - - public static void setGameMode(PlayerInteractManager playerInteractManager, EnumGamemode gamemode) { - SET_GAMEMODE.invoke(playerInteractManager, gamemode, null); - } - - public static World getWorld(Entity entity) { - return entity.cA(); - } - - public static void setLocation(Entity entity, double x, double y, double z, float yaw, float pitch) { - entity.a(x, y, z, yaw, pitch); - } - - public static void addPlayerJoin(WorldServer worldServer, EntityPlayer entityPlayer) { - worldServer.c(entityPlayer); - } - - public static WorldServer getWorldServer(EntityPlayer entityPlayer) { - return entityPlayer.x(); - } - -} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/ChunkLoaderNPC.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/ChunkLoaderNPC.java new file mode 100644 index 0000000..6de00cc --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/ChunkLoaderNPC.java @@ -0,0 +1,207 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1; + +import com.bgsoftware.common.reflection.ReflectMethod; +import com.bgsoftware.wildloaders.handlers.NPCHandler; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.entity.Entity; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.World; +import com.bgsoftware.wildloaders.npc.DummyChannel; +import com.mojang.authlib.GameProfile; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.protocol.EnumProtocolDirection; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayInBlockDig; +import net.minecraft.network.protocol.game.PacketPlayInBlockPlace; +import net.minecraft.network.protocol.game.PacketPlayInChat; +import net.minecraft.network.protocol.game.PacketPlayInFlying; +import net.minecraft.network.protocol.game.PacketPlayInHeldItemSlot; +import net.minecraft.network.protocol.game.PacketPlayInUpdateSign; +import net.minecraft.network.protocol.game.PacketPlayInWindowClick; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.PlayerInteractManager; +import net.minecraft.server.network.PlayerConnection; +import net.minecraft.world.level.EnumGamemode; +import net.minecraft.world.phys.AxisAlignedBB; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { + + private static final ReflectMethod SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class, + 1, EnumGamemode.class, EnumGamemode.class); + + private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); + + private final World world; + + private boolean dieCall = false; + + @Remap(classPath = "net.minecraft.server.level.ServerPlayer", name = "gameMode", type = Remap.Type.FIELD, remappedName = "d") + public ChunkLoaderNPC(MinecraftServer minecraftServer, Location location, UUID uuid) { + super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), + new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName()))); + + Entity entity = new Entity(this); + this.world = entity.getWorld(); + + this.b = new DummyPlayerConnection(minecraftServer, this); + + SET_GAMEMODE.invoke(this.d, EnumGamemode.b); + clientViewDistance = 1; + + fauxSleeping = true; + + spawnIn(this.world.getHandle()); + entity.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + + this.world.addNewPlayer(this); + + super.a(EMPTY_BOUND); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getUUID", + type = Remap.Type.METHOD, + remappedName = "cm") + @Override + public UUID getUniqueId() { + return super.cm(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "discard", + type = Remap.Type.METHOD, + remappedName = "ah") + @Override + public void die() { + ah(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getBoundingBoxForCulling", + type = Remap.Type.METHOD, + remappedName = "cx") + @Override + public AxisAlignedBB cx() { + return EMPTY_BOUND; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(RemovalReason removalReason) { + if (!dieCall) { + dieCall = true; + this.world.removePlayer(this, RemovalReason.d); + dieCall = false; + } else { + super.a(removalReason); + } + } + + @Override + public Location getLocation() { + return getBukkitEntity().getLocation(); + } + + @Override + public Player getPlayer() { + return getBukkitEntity(); + } + + public static class DummyNetworkManager extends NetworkManager { + + @Remap(classPath = "net.minecraft.network.protocol.PacketFlow", name = "SERVERBOUND", type = Remap.Type.FIELD, remappedName = "a") + @Remap(classPath = "net.minecraft.network.Connection", name = "channel", type = Remap.Type.FIELD, remappedName = "k") + @Remap(classPath = "net.minecraft.network.Connection", name = "address", type = Remap.Type.FIELD, remappedName = "l") + DummyNetworkManager() { + super(EnumProtocolDirection.a); + this.k = new DummyChannel(); + this.l = null; + } + + } + + public static class DummyPlayerConnection extends PlayerConnection { + + DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) { + super(minecraftServer, new DummyNetworkManager(), entityPlayer); + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleContainerClick", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInWindowClick packetPlayInWindowClick) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleMovePlayer", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInFlying packetPlayInFlying) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleSignUpdate", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handlePlayerAction", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInBlockDig packetPlayInBlockDig) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleUseItem", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) { + + } + + public void disconnect(String s) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleSetCarriedItem", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleChat", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInChat packetPlayInChat) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "send", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(Packet packet) { + + } + + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R1.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/EntityHolograms.java similarity index 50% rename from v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R1.java rename to v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/EntityHolograms.java index 788d0bd..c64edf0 100644 --- a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R1.java +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/EntityHolograms.java @@ -1,6 +1,7 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_18_R1; import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.nms.mapping.Remap; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.sounds.SoundEffect; @@ -21,13 +22,21 @@ import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage; @SuppressWarnings("unused") -public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements Hologram { +public final class EntityHolograms extends EntityArmorStand implements Hologram { private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); private CraftEntity bukkitEntity; - public EntityHolograms_v1_18_R1(World world, double x, double y, double z){ + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setInvisible", type = Remap.Type.METHOD, remappedName = "j") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setSmall", type = Remap.Type.METHOD, remappedName = "a") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setShowArms", type = Remap.Type.METHOD, remappedName = "r") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setNoGravity", type = Remap.Type.METHOD, remappedName = "e") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setNoBasePlate", type = Remap.Type.METHOD, remappedName = "s") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setMarker", type = Remap.Type.METHOD, remappedName = "t") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setCustomNameVisible", type = Remap.Type.METHOD, remappedName = "n") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setBoundingBox", type = Remap.Type.METHOD, remappedName = "a") + public EntityHolograms(World world, double x, double y, double z){ super(world, x, y, z); j(true); // Invisible a(true); // Small @@ -40,11 +49,19 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements super.a(EMPTY_BOUND); } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomName", + type = Remap.Type.METHOD, + remappedName = "a") @Override public void setHologramName(String name) { - super.a(CraftChatMessage.fromString(name)[0]); + super.a(CraftChatMessage.fromStringOrNull(name)); } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") @Override public void removeHologram() { super.a(RemovalReason.b); @@ -55,6 +72,10 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements return getBukkitEntity(); } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "tick", + type = Remap.Type.METHOD, + remappedName = "k") @Override public void k() { // Disable normal ticking for this entity. @@ -65,6 +86,10 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements } } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "onGround", + type = Remap.Type.FIELD, + remappedName = "z") @Override public void inactiveTick() { // Disable normal ticking for this entity. @@ -75,33 +100,57 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements } } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "addAdditionalSaveData", + type = Remap.Type.METHOD, + remappedName = "b") @Override public void b(NBTTagCompound nbttagcompound) { // Do not save NBT. } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "saveAsPassenger", + type = Remap.Type.METHOD, + remappedName = "d") @Override public boolean d(NBTTagCompound nbttagcompound) { // Do not save NBT. return false; } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "saveWithoutId", + type = Remap.Type.METHOD, + remappedName = "f") @Override public NBTTagCompound f(NBTTagCompound nbttagcompound) { // Do not save NBT. return nbttagcompound; } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "readAdditionalSaveData", + type = Remap.Type.METHOD, + remappedName = "a") @Override public void a(NBTTagCompound nbttagcompound) { // Do not load NBT. } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "load", + type = Remap.Type.METHOD, + remappedName = "g") @Override public void g(NBTTagCompound nbttagcompound) { // Do not load NBT. } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "isInvulnerableTo", + type = Remap.Type.METHOD, + remappedName = "b") @Override public boolean b(DamageSource source) { /* @@ -112,21 +161,37 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements return true; } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "repositionEntityAfterLoad", + type = Remap.Type.METHOD, + remappedName = "bj") @Override - public boolean bi() { + public boolean bj() { return false; } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomName", + type = Remap.Type.METHOD, + remappedName = "a") @Override public void a(IChatBaseComponent ichatbasecomponent) { // Locks the custom name. } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomNameVisible", + type = Remap.Type.METHOD, + remappedName = "n") @Override public void n(boolean flag) { // Locks the custom name. } + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", + name = "interactAt", + type = Remap.Type.METHOD, + remappedName = "a") @Override public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { // Prevent stand being equipped @@ -138,6 +203,10 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements // Prevent stand being equipped } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getBoundingBoxForCulling", + type = Remap.Type.METHOD, + remappedName = "cx") @Override public AxisAlignedBB cx() { return EMPTY_BOUND; @@ -147,11 +216,19 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements super.a(boundingBox); } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "playSound", + type = Remap.Type.METHOD, + remappedName = "a") @Override public void a(SoundEffect soundeffect, float f, float f1) { // Remove sounds. } + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") @Override public void a(RemovalReason entity_removalreason) { // Prevent being killed. diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/NMSAdapter.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/NMSAdapter.java new file mode 100644 index 0000000..56ecf76 --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/NMSAdapter.java @@ -0,0 +1,200 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1; + +import com.bgsoftware.common.reflection.ReflectMethod; +import com.bgsoftware.wildloaders.WildLoadersPlugin; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.loader.TileEntityChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.core.BlockPosition; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.nbt.NBTTagCompound; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.item.ItemStack; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.World; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.block.entity.TileEntity; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.block.state.IBlockData; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.chunk.Chunk; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagLong; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R1.CraftChunk; +import org.bukkit.craftbukkit.v1_18_R1.CraftServer; +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; + +import java.util.UUID; + +@SuppressWarnings("unused") +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { + + private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); + + @Remap(classPath = "net.minecraft.world.level.chunk.LevelChunk", name = "createTicker", type = Remap.Type.METHOD) + private static final ReflectMethod CREATE_TICKING_BLOCK = new ReflectMethod<>( + net.minecraft.world.level.chunk.Chunk.class, "a", + net.minecraft.world.level.block.entity.TileEntity.class, BlockEntityTicker.class); + + @Override + public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getTag(); + + if (tagCompound == null || !tagCompound.contains(key, 8)) + return def; + + return tagCompound.getString(key); + } + + @Override + public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + tagCompound.put(key, NBTTagString.a(value)); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getTag(); + + if (tagCompound == null || !tagCompound.contains(key, 4)) + return def; + + return tagCompound.getLong(key); + } + + @Override + public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + tagCompound.put(key, NBTTagLong.a(value)); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + NBTTagCompound skullOwner = tagCompound.contains("SkullOwner") ? + tagCompound.getCompound("SkullOwner") : new NBTTagCompound(); + + NBTTagCompound properties = new NBTTagCompound(); + + NBTTagList textures = new NBTTagList(); + NBTTagCompound signature = new NBTTagCompound(); + signature.putString("Value", texture); + textures.add(signature.getHandle()); + + properties.put("textures", textures); + + skullOwner.put("Properties", properties.getHandle()); + skullOwner.putString("Id", UUID.randomUUID().toString()); + + tagCompound.put("SkullOwner", skullOwner.getHandle()); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) { + Location loaderLoc = chunkLoader.getLocation(); + assert loaderLoc.getWorld() != null; + + World world = new World(((CraftWorld) loaderLoc.getWorld()).getHandle()); + BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); + + TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); + world.addBlockEntityTicker(tileEntityChunkLoader.ticker); + + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = new Chunk(((CraftChunk) bukkitChunk).getHandle()); + chunk.getBlockEntities().values().stream() + .filter(nmsTileEntity -> nmsTileEntity instanceof TileEntityMobSpawner) + .forEach(nmsTileEntity -> { + TileEntity tileEntity = new TileEntity(nmsTileEntity); + tileEntity.getSpawner().m = -1; + }); + + ChunkCoordIntPair chunkCoords = chunk.getPos(); + + world.setChunkForced(chunkCoords.getX(), chunkCoords.getZ(), true); + } + + return tileEntityChunkLoader; + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) { + Location loaderLoc = chunkLoader.getLocation(); + assert loaderLoc.getWorld() != null; + + World world = new World(((CraftWorld) loaderLoc.getWorld()).getHandle()); + BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); + + long tileEntityLong = ChunkCoordIntPair.asLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); + TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); + tileEntityChunkLoader.removed = true; + } + + if (spawnParticle) { + world.levelEvent(null, 2001, blockPosition.getHandle(), + IBlockData.getId(world.getBlockStateNoMappings(blockPosition.getHandle()))); + } + + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = new Chunk(((CraftChunk) bukkitChunk).getHandle()); + chunk.getBlockEntities().values().stream() + .filter(nmsTileEntity -> nmsTileEntity instanceof TileEntityMobSpawner) + .forEach(nmsTileEntity -> { + TileEntity tileEntity = new TileEntity(nmsTileEntity); + tileEntity.getSpawner().m = 16; + }); + + ChunkCoordIntPair chunkCoords = chunk.getPos(); + + world.setChunkForced(chunkCoords.getX(), chunkCoords.getZ(), false); + } + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public void updateSpawner(Location location, boolean reset) { + assert location.getWorld() != null; + World world = new World(((CraftWorld) location.getWorld()).getHandle()); + + BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ()); + TileEntity mobSpawner = new TileEntity(world.getBlockEntity(blockPosition.getHandle())); + + mobSpawner.getSpawner().m = reset ? 16 : -1; + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoader.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..1117c05 --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoader.java @@ -0,0 +1,161 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.EntityHolograms; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.core.BlockPosition; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.World; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + public final TileEntityChunkLoaderTicker ticker; + public final BlockPosition tilePosition; + private final World world; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntityType", name = "COMMAND_BLOCK", type = Remap.Type.FIELD, remappedName = "v") + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", name = "setLevel", type = Remap.Type.METHOD, remappedName = "a") + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + super(TileEntityTypes.v, blockPosition.getHandle(), world.getBlockStateNoMappings(blockPosition.getHandle())); + + this.chunkLoader = (WChunkLoader) chunkLoader; + this.ticker = new TileEntityChunkLoaderTicker(this); + this.tilePosition = blockPosition; + this.world = world; + + a(world.getHandle()); + + loaderBlock = world.getBlockState(blockPosition.getHandle()).getBlock(); + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(ChunkCoordIntPair.asLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = this.tilePosition.getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world.getHandle(), + this.tilePosition.getX() + 0.5, currentY, this.tilePosition.getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addFreshEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", + name = "getType", + type = Remap.Type.METHOD, + remappedName = "u") + public TileEntityTypes getType() { + return super.u(); + } + + public void tick() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + if (chunkLoader.isNotActive() || this.world.getBlockState(this.tilePosition.getHandle()).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", + name = "isRemoved", + type = Remap.Type.METHOD, + remappedName = "r") + @Override + public boolean r() { + return isRemoved(); + } + + public boolean isRemoved() { + return removed || super.r(); + } + + private void updateName(EntityHolograms hologram, String line) { + assert chunkLoader.getWhoPlaced().getName() != null; + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} + diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoaderTicker.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoaderTicker.java new file mode 100644 index 0000000..1c5f16f --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/loader/TileEntityChunkLoaderTicker.java @@ -0,0 +1,46 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.loader; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +public record TileEntityChunkLoaderTicker(TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "tick", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a() { + tileEntityChunkLoader.tick(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "isRemoved", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public boolean b() { + return tileEntityChunkLoader.isRemoved(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "getPos", + type = Remap.Type.METHOD, + remappedName = "c") + @Override + public BlockPosition c() { + return tileEntityChunkLoader.tilePosition.getHandle(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "getType", + type = Remap.Type.METHOD, + remappedName = "d") + @Override + public String d() { + return TileEntityTypes.a(tileEntityChunkLoader.getType()) + ""; + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/MappedObject.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/MappedObject.java new file mode 100644 index 0000000..c1c618f --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/MappedObject.java @@ -0,0 +1,15 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings; + +public abstract class MappedObject { + + protected final E handle; + + protected MappedObject(E handle) { + this.handle = handle; + } + + public E getHandle() { + return handle; + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/core/BlockPosition.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/core/BlockPosition.java new file mode 100644 index 0000000..6495c6e --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/core/BlockPosition.java @@ -0,0 +1,40 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.core; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; + +public class BlockPosition extends MappedObject { + + public BlockPosition(double x, double y, double z) { + this(new net.minecraft.core.BlockPosition(x, y, z)); + } + + public BlockPosition(net.minecraft.core.BlockPosition handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getX", + type = Remap.Type.METHOD, + remappedName = "u") + public int getX() { + return handle.u(); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getY", + type = Remap.Type.METHOD, + remappedName = "v") + public int getY() { + return handle.v(); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getZ", + type = Remap.Type.METHOD, + remappedName = "w") + public int getZ() { + return handle.w(); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/nbt/NBTTagCompound.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/nbt/NBTTagCompound.java new file mode 100644 index 0000000..c11b065 --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/nbt/NBTTagCompound.java @@ -0,0 +1,77 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.nbt; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import net.minecraft.nbt.NBTBase; + +public class NBTTagCompound extends MappedObject { + + public static NBTTagCompound ofNullable(net.minecraft.nbt.NBTTagCompound handle) { + return handle == null ? null : new NBTTagCompound(handle); + } + + public NBTTagCompound() { + this(new net.minecraft.nbt.NBTTagCompound()); + } + + public NBTTagCompound(net.minecraft.nbt.NBTTagCompound handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "contains", + type = Remap.Type.METHOD, + remappedName = "b") + public boolean contains(String key, int type) { + return handle.b(key, type); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getString", + type = Remap.Type.METHOD, + remappedName = "l") + public String getString(String key) { + return handle.l(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "put", + type = Remap.Type.METHOD, + remappedName = "a") + public void put(String key, NBTBase nbtBase) { + handle.a(key, nbtBase); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getLong", + type = Remap.Type.METHOD, + remappedName = "i") + public long getLong(String key) { + return handle.i(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "contains", + type = Remap.Type.METHOD, + remappedName = "e") + public boolean contains(String key) { + return handle.e(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getCompound", + type = Remap.Type.METHOD, + remappedName = "p") + public NBTTagCompound getCompound(String key) { + return new NBTTagCompound(handle.p(key)); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "putString", + type = Remap.Type.METHOD, + remappedName = "a") + public void putString(String key, String value) { + handle.a(key, value); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/entity/Entity.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/entity/Entity.java new file mode 100644 index 0000000..23464cd --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/entity/Entity.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.entity; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.World; + +public class Entity extends MappedObject { + + public Entity(net.minecraft.world.entity.Entity handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getLevel", + type = Remap.Type.METHOD, + remappedName = "W") + public World getWorld() { + return new World(handle.W()); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "moveTo", + type = Remap.Type.METHOD, + remappedName = "b") + public void moveTo(double x, double y, double z, float yaw, float pitch) { + handle.b(x, y, z, yaw, pitch); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/item/ItemStack.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/item/ItemStack.java new file mode 100644 index 0000000..2e96c9d --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/item/ItemStack.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.item; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.nbt.NBTTagCompound; + +public class ItemStack extends MappedObject { + + public ItemStack(net.minecraft.world.item.ItemStack handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.item.ItemStack", + name = "getOrCreateTag", + type = Remap.Type.METHOD, + remappedName = "t") + public NBTTagCompound getOrCreateTag() { + return new NBTTagCompound(handle.t()); + } + + @Remap(classPath = "net.minecraft.world.item.ItemStack", + name = "getTag", + type = Remap.Type.METHOD, + remappedName = "s") + public NBTTagCompound getTag() { + return NBTTagCompound.ofNullable(handle.s()); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java new file mode 100644 index 0000000..87b611f --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java @@ -0,0 +1,36 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; + +public class ChunkCoordIntPair extends MappedObject { + + public ChunkCoordIntPair(net.minecraft.world.level.ChunkCoordIntPair handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "x", + type = Remap.Type.FIELD, + remappedName = "c") + public int getX() { + return handle.c; + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "z", + type = Remap.Type.FIELD, + remappedName = "d") + public int getZ() { + return handle.d; + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "asLong", + type = Remap.Type.METHOD, + remappedName = "a") + public static long asLong(int x, int z) { + return net.minecraft.world.level.ChunkCoordIntPair.a(x, z); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/World.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/World.java new file mode 100644 index 0000000..0d849a6 --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/World.java @@ -0,0 +1,87 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.core.BlockPosition; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntity; + +public class World extends MappedObject { + + public World(net.minecraft.world.level.World handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "setChunkForced", + type = Remap.Type.METHOD, + remappedName = "a") + public void setChunkForced(int chunkX, int chunkZ, boolean load) { + ((WorldServer) handle).a(chunkX, chunkZ, load); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "addNewPlayer", + type = Remap.Type.METHOD, + remappedName = "c") + public void addNewPlayer(EntityPlayer entityPlayer) { + ((WorldServer) handle).c(entityPlayer); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "removePlayerImmediately", + type = Remap.Type.METHOD, + remappedName = "a") + public void removePlayer(EntityPlayer entityPlayer, Entity.RemovalReason removalReason) { + ((WorldServer) handle).a(entityPlayer, removalReason); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "getBlockState", + type = Remap.Type.METHOD, + remappedName = "a_") + public net.minecraft.world.level.block.state.IBlockData getBlockStateNoMappings(BlockPosition blockPosition) { + return handle.a_(blockPosition); + } + + public IBlockData getBlockState(BlockPosition blockPosition) { + return new IBlockData(getBlockStateNoMappings(blockPosition)); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "getBlockEntity", + type = Remap.Type.METHOD, + remappedName = "c_") + public TileEntity getBlockEntity(BlockPosition blockPosition) { + return handle.c_(blockPosition); + } + + @Remap(classPath = "net.minecraft.world.level.LevelWriter", + name = "addFreshEntity", + type = Remap.Type.METHOD, + remappedName = "b") + public void addFreshEntity(Entity entity) { + handle.b(entity); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "addBlockEntityTicker", + type = Remap.Type.METHOD, + remappedName = "a") + public void addBlockEntityTicker(TickingBlockEntity blockEntityTicker) { + handle.a(blockEntityTicker); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "levelEvent", + type = Remap.Type.METHOD, + remappedName = "a") + public void levelEvent(EntityPlayer entityPlayer, int i, BlockPosition blockPosition, int j) { + handle.a(entityPlayer, i, blockPosition, j); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java new file mode 100644 index 0000000..0187f4d --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java @@ -0,0 +1,22 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.block.entity; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import net.minecraft.world.level.MobSpawnerAbstract; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; + +public class TileEntity extends MappedObject { + + public TileEntity(net.minecraft.world.level.block.entity.TileEntity handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.SpawnerBlockEntity", + name = "getSpawner", + type = Remap.Type.METHOD, + remappedName = "d") + public MobSpawnerAbstract getSpawner() { + return ((TileEntityMobSpawner) handle).d(); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java new file mode 100644 index 0000000..bbd8f87 --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.block.state; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import net.minecraft.world.level.block.Block; + +public class IBlockData extends MappedObject { + + public IBlockData(net.minecraft.world.level.block.state.IBlockData handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase", + name = "getBlock", + type = Remap.Type.METHOD, + remappedName = "b") + public Block getBlock() { + return handle.b(); + } + + @Remap(classPath = "net.minecraft.world.level.block.Block", + name = "getId", + type = Remap.Type.METHOD, + remappedName = "i") + public static int getId(net.minecraft.world.level.block.state.IBlockData blockData) { + return Block.i(blockData); + } + +} diff --git a/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/chunk/Chunk.java b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/chunk/Chunk.java new file mode 100644 index 0000000..f2f0f58 --- /dev/null +++ b/v1_18_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R1/mappings/net/minecraft/world/level/chunk/Chunk.java @@ -0,0 +1,33 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.chunk; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R1.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TileEntity; + +import java.util.Map; + +public class Chunk extends MappedObject { + + public Chunk(net.minecraft.world.level.chunk.Chunk handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.chunk.LevelChunk", + name = "getBlockEntities", + type = Remap.Type.METHOD, + remappedName = "E") + public Map getBlockEntities() { + return handle.E(); + } + + @Remap(classPath = "net.minecraft.world.level.chunk.ChunkAccess", + name = "getPos", + type = Remap.Type.METHOD, + remappedName = "f") + public ChunkCoordIntPair getPos() { + return new ChunkCoordIntPair(handle.f()); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R2.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R2.java deleted file mode 100644 index d62b044..0000000 --- a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_18_R2.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import com.bgsoftware.wildloaders.handlers.NPCHandler; -import com.bgsoftware.wildloaders.npc.DummyChannel; -import com.mojang.authlib.GameProfile; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.protocol.EnumProtocolDirection; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.PacketPlayInBlockDig; -import net.minecraft.network.protocol.game.PacketPlayInBlockPlace; -import net.minecraft.network.protocol.game.PacketPlayInChat; -import net.minecraft.network.protocol.game.PacketPlayInFlying; -import net.minecraft.network.protocol.game.PacketPlayInHeldItemSlot; -import net.minecraft.network.protocol.game.PacketPlayInUpdateSign; -import net.minecraft.network.protocol.game.PacketPlayInWindowClick; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.AxisAlignedBB; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.entity.Player; - -import java.util.UUID; - -import static com.bgsoftware.wildloaders.nms.NMSMappings_v1_18_R2.*; - -public final class ChunkLoaderNPC_v1_18_R2 extends EntityPlayer implements ChunkLoaderNPC { - - private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - - private boolean dieCall = false; - - public ChunkLoaderNPC_v1_18_R2(MinecraftServer minecraftServer, Location location, UUID uuid) { - super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), - new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName()))); - - this.b = new DummyPlayerConnection(minecraftServer, this); - - NMSMappings_v1_18_R2.setGameModeForPlayer(this.d, EnumGamemode.b); - clientViewDistance = 1; - - fauxSleeping = true; - - spawnIn(getWorld(this)); - moveTo(this, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - - addNewPlayer(getLevel(this), this); - - super.a(EMPTY_BOUND); - } - - @Override - public UUID getUniqueId() { - return super.cm(); - } - - @Override - public void die() { - ah(); - } - - @Override - public AxisAlignedBB cx() { - return EMPTY_BOUND; - } - - @Override - public void a(RemovalReason removalReason) { - if (!dieCall) { - dieCall = true; - removePlayer(getLevel(this), this); - dieCall = false; - } else { - super.a(removalReason); - } - } - - @Override - public Location getLocation() { - return getBukkitEntity().getLocation(); - } - - @Override - public Player getPlayer() { - return getBukkitEntity(); - } - - private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer) { - worldServer.a(entityPlayer, RemovalReason.d); - } - - public static class DummyNetworkManager extends NetworkManager { - - DummyNetworkManager() { - super(EnumProtocolDirection.a); - this.m = new DummyChannel(); - this.n = null; - } - - } - - public static class DummyPlayerConnection extends PlayerConnection { - - DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) { - super(minecraftServer, new DummyNetworkManager(), entityPlayer); - } - - public void a(PacketPlayInWindowClick packetPlayInWindowClick) { - - } - - public void a(PacketPlayInFlying packetPlayInFlying) { - - } - - public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) { - - } - - public void a(PacketPlayInBlockDig packetPlayInBlockDig) { - - } - - public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) { - - } - - public void disconnect(String s) { - - } - - public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) { - - } - - public void a(PacketPlayInChat packetPlayInChat) { - - } - - public void a(Packet packet) { - - } - - } - -} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R2.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R2.java deleted file mode 100644 index 8ee7c6a..0000000 --- a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_18_R2.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.wildloaders.api.holograms.Hologram; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.sounds.SoundEffect; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.AxisAlignedBB; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftArmorStand; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_18_R2.util.CraftChatMessage; - -@SuppressWarnings("unused") -public final class EntityHolograms_v1_18_R2 extends EntityArmorStand implements Hologram { - - private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - - private CraftEntity bukkitEntity; - - public EntityHolograms_v1_18_R2(World world, double x, double y, double z){ - super(world, x, y, z); - j(true); // Invisible - a(true); // Small - r(false); // Arms - e(true); // No Gravity - s(true); // Base Plate - t(true); // Marker - super.collides = false; - super.n(true); // Custom name visible - super.a(EMPTY_BOUND); - } - - @Override - public void setHologramName(String name) { - super.a(CraftChatMessage.fromString(name)[0]); - } - - @Override - public void removeHologram() { - super.a(RemovalReason.b); - } - - @Override - public org.bukkit.entity.Entity getEntity() { - return getBukkitEntity(); - } - - @Override - public void k() { - // Disable normal ticking for this entity. - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. - if (this.z) { - this.z = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity. - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. - if (this.z) { - this.z = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } - - @Override - public NBTTagCompound f(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return nbttagcompound; - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT. - } - - @Override - public void g(NBTTagCompound nbttagcompound) { - // Do not load NBT. - } - - @Override - public boolean b(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean bi() { - return false; - } - - @Override - public void a(IChatBaseComponent ichatbasecomponent) { - // Locks the custom name. - } - - @Override - public void n(boolean flag) { - // Locks the custom name. - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.d; - } - - @Override - public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean flag) { - // Prevent stand being equipped - } - - @Override - public AxisAlignedBB cx() { - return EMPTY_BOUND; - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void a(RemovalReason entity_removalreason) { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (bukkitEntity == null) { - bukkitEntity = new CraftArmorStand((CraftServer) Bukkit.getServer(), this); - } - return bukkitEntity; - } - -} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R2.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R2.java deleted file mode 100644 index 3008047..0000000 --- a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_18_R2.java +++ /dev/null @@ -1,333 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.common.reflection.ReflectMethod; -import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; -import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagLong; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityTicker; -import net.minecraft.world.level.block.entity.TickingBlockEntity; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.Chunk; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_18_R2.CraftChunk; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.bgsoftware.wildloaders.nms.NMSMappings_v1_18_R2.*; - -@SuppressWarnings("unused") -public final class NMSAdapter_v1_18_R2 implements NMSAdapter { - - private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); - - private static final ReflectMethod CREATE_TICKING_BLOCK = new ReflectMethod<>( - Chunk.class, "a", TileEntity.class, BlockEntityTicker.class); - - @Override - public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - if(!contains(tagCompound, key, 8)) - return def; - - return getString(tagCompound, key); - } - - @Override - public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - put(tagCompound, key, NBTTagString.a(value)); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - if(!contains(tagCompound, key, 4)) - return def; - - return getLong(tagCompound, key); - } - - @Override - public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - put(tagCompound, key, NBTTagLong.a(value)); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - - NBTTagCompound nbtTagCompound = getOrCreateTag(nmsItem); - - NBTTagCompound skullOwner = NMSMappings_v1_18_R2.contains(nbtTagCompound, "SkullOwner") ? - getCompound(nbtTagCompound, "SkullOwner") : new NBTTagCompound(); - - NBTTagCompound properties = new NBTTagCompound(); - - NBTTagList textures = new NBTTagList(); - NBTTagCompound signature = new NBTTagCompound(); - putString(signature, "Value", texture); - textures.add(signature); - - put(properties, "textures", textures); - - put(skullOwner, "Properties", properties); - putString(skullOwner,"Id", UUID.randomUUID().toString()); - - put(nbtTagCompound, "SkullOwner", skullOwner); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_18_R2(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); - } - - @Override - public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) { - Location loaderLoc = chunkLoader.getLocation(); - assert loaderLoc.getWorld() != null; - WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); - - TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); - world.a(tileEntityChunkLoader.ticker); - - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { - Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); - getBlockEntities(chunk).values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> getSpawner((TileEntityMobSpawner) tileEntity).m = -1); - - ChunkCoordIntPair chunkCoords = getPos(chunk); - - setChunkForced(world, chunkCoords.c, chunkCoords.d, true); - } - - return tileEntityChunkLoader; - } - - @Override - public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) { - Location loaderLoc = chunkLoader.getLocation(); - assert loaderLoc.getWorld() != null; - WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); - - long tileEntityLong = ChunkCoordIntPair.a(getX(blockPosition) >> 4, getZ(blockPosition) >> 4); - TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_18_R2::removeHologram); - tileEntityChunkLoader.removed = true; - } - - if(spawnParticle) - world.a(null, 2001, blockPosition, getId(getBlockState(world, blockPosition))); - - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { - Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); - getBlockEntities(chunk).values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> getSpawner((TileEntityMobSpawner) tileEntity).m = 16); - - ChunkCoordIntPair chunkCoords = getPos(chunk); - - setChunkForced(world, chunkCoords.c, chunkCoords.d, false); - } - } - - @Override - public void updateSpawner(Location location, boolean reset) { - assert location.getWorld() != null; - World world = ((CraftWorld) location.getWorld()).getHandle(); - - BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ()); - IBlockData blockData = getBlockState(world, blockPosition); - TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) getBlockEntity(world, blockPosition); - - if(mobSpawner == null) - return; - - getSpawner(mobSpawner).m = reset ? 16 : -1; - } - - private static final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - private final TileEntityChunkLoaderTicker ticker; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - super(TileEntityTypes.v, blockPosition, getBlockState(world, blockPosition)); - - this.chunkLoader = (WChunkLoader) chunkLoader; - this.ticker = new TileEntityChunkLoaderTicker(this); - - a(world); - - loaderBlock = getBlock(getBlockState(world, blockPosition)); - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(ChunkCoordIntPair.a(getX(blockPosition) >> 4, getZ(blockPosition) >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = getY(getBlockPos(this)) + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_18_R2 hologram = new EntityHolograms_v1_18_R2(world, - getX(getBlockPos(this)) + 0.5, currentY, getZ(getBlockPos(this)) + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - addFreshEntity(world, hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - public void tick() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - assert this.n != null; - if(chunkLoader.isNotActive() || getBlock(getBlockState(this.n, getBlockPos(this))) != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_18_R2 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - @Override - public boolean r() { - return removed || super.r(); - } - - private void updateName(EntityHolograms_v1_18_R2 hologram, String line){ - assert chunkLoader.getWhoPlaced().getName() != null; - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - - private record TileEntityChunkLoaderTicker( - TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { - - @Override - public void a() { - tileEntityChunkLoader.tick(); - } - - @Override - public boolean b() { - return tileEntityChunkLoader.r(); - } - - @Override - public BlockPosition c() { - return getBlockPos(tileEntityChunkLoader); - } - - @Override - public String d() { - return TileEntityTypes.a(getType(tileEntityChunkLoader)) + ""; - } - } - -} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R2.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R2.java deleted file mode 100644 index f1c9752..0000000 --- a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_18_R2.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.common.reflection.ReflectMethod; -import net.minecraft.core.BaseBlockPosition; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.PlayerInteractManager; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.level.IWorldWriter; -import net.minecraft.world.level.MobSpawnerAbstract; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; - -import java.util.Map; - -public final class NMSMappings_v1_18_R2 { - - private static final ReflectMethod SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class, - 1, EnumGamemode.class, EnumGamemode.class); - - private NMSMappings_v1_18_R2() { - - } - - public static NBTTagCompound getOrCreateTag(ItemStack itemStack) { - return itemStack.u(); - } - - public static boolean contains(NBTTagCompound nbtTagCompound, String key, int type) { - return nbtTagCompound.b(key, type); - } - - public static String getString(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.l(key); - } - - public static void put(NBTTagCompound nbtTagCompound, String key, NBTBase nbtBase) { - nbtTagCompound.a(key, nbtBase); - } - - public static long getLong(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.i(key); - } - - public static boolean contains(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.e(key); - } - - public static NBTTagCompound getCompound(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.p(key); - } - - public static void putString(NBTTagCompound nbtTagCompound, String key, String value) { - nbtTagCompound.a(key, value); - } - - public static Map getBlockEntities(IChunkAccess chunkAccess) { - return chunkAccess.i; - } - - public static ChunkCoordIntPair getPos(IChunkAccess chunk) { - return chunk.f(); - } - - public static MobSpawnerAbstract getSpawner(TileEntityMobSpawner tileEntityMobSpawner) { - return tileEntityMobSpawner.d(); - } - - public static void setChunkForced(WorldServer worldServer, int chunkX, int chunkZ, boolean load) { - worldServer.a(chunkX, chunkZ, load); - } - - public static void addNewPlayer(WorldServer worldServer, EntityPlayer entityPlayer) { - worldServer.c(entityPlayer); - } - - public static int getId(IBlockData blockData) { - return Block.i(blockData); - } - - public static Block getBlock(IBlockData blockData) { - return blockData.b(); - } - - public static int getX(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.u(); - } - - public static int getY(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.v(); - } - - public static int getZ(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.w(); - } - - public static IBlockData getBlockState(World world, BlockPosition blockPosition) { - return world.a_(blockPosition); - } - - public static TileEntity getBlockEntity(World world, BlockPosition blockPosition) { - return world.c_(blockPosition); - } - - public static void addFreshEntity(IWorldWriter worldWriter, Entity entity) { - worldWriter.b(entity); - } - - public static BlockPosition getBlockPos(TileEntity tileEntity) { - return tileEntity.p(); - } - - public static TileEntityTypes getType(TileEntity tileEntity) { - return tileEntity.u(); - } - - public static void setGameModeForPlayer(PlayerInteractManager playerInteractManager, EnumGamemode gamemode) { - SET_GAMEMODE.invoke(playerInteractManager, gamemode, null); - } - - public static World getWorld(Entity entity) { - return entity.W(); - } - - public static void moveTo(Entity entity, double x, double y, double z, float yaw, float pitch) { - entity.b(x, y, z, yaw, pitch); - } - - public static WorldServer getLevel(EntityPlayer entityPlayer) { - return entityPlayer.x(); - } - -} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/ChunkLoaderNPC.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/ChunkLoaderNPC.java new file mode 100644 index 0000000..c25d132 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/ChunkLoaderNPC.java @@ -0,0 +1,207 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2; + +import com.bgsoftware.common.reflection.ReflectMethod; +import com.bgsoftware.wildloaders.handlers.NPCHandler; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.entity.Entity; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.World; +import com.bgsoftware.wildloaders.npc.DummyChannel; +import com.mojang.authlib.GameProfile; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.protocol.EnumProtocolDirection; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayInBlockDig; +import net.minecraft.network.protocol.game.PacketPlayInBlockPlace; +import net.minecraft.network.protocol.game.PacketPlayInChat; +import net.minecraft.network.protocol.game.PacketPlayInFlying; +import net.minecraft.network.protocol.game.PacketPlayInHeldItemSlot; +import net.minecraft.network.protocol.game.PacketPlayInUpdateSign; +import net.minecraft.network.protocol.game.PacketPlayInWindowClick; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.PlayerInteractManager; +import net.minecraft.server.network.PlayerConnection; +import net.minecraft.world.level.EnumGamemode; +import net.minecraft.world.phys.AxisAlignedBB; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { + + private static final ReflectMethod SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class, + 1, EnumGamemode.class, EnumGamemode.class); + + private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); + + private final World world; + + private boolean dieCall = false; + + @Remap(classPath = "net.minecraft.server.level.ServerPlayer", name = "gameMode", type = Remap.Type.FIELD, remappedName = "d") + public ChunkLoaderNPC(MinecraftServer minecraftServer, Location location, UUID uuid) { + super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), + new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName()))); + + Entity entity = new Entity(this); + this.world = entity.getWorld(); + + this.b = new DummyPlayerConnection(minecraftServer, this); + + SET_GAMEMODE.invoke(this.d, EnumGamemode.b); + clientViewDistance = 1; + + fauxSleeping = true; + + spawnIn(this.world.getHandle()); + entity.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + + this.world.addNewPlayer(this); + + super.a(EMPTY_BOUND); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getUUID", + type = Remap.Type.METHOD, + remappedName = "cm") + @Override + public UUID getUniqueId() { + return super.cm(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "discard", + type = Remap.Type.METHOD, + remappedName = "ah") + @Override + public void die() { + ah(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getBoundingBoxForCulling", + type = Remap.Type.METHOD, + remappedName = "cx") + @Override + public AxisAlignedBB cx() { + return EMPTY_BOUND; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(RemovalReason removalReason) { + if (!dieCall) { + dieCall = true; + this.world.removePlayer(this, RemovalReason.d); + dieCall = false; + } else { + super.a(removalReason); + } + } + + @Override + public Location getLocation() { + return getBukkitEntity().getLocation(); + } + + @Override + public Player getPlayer() { + return getBukkitEntity(); + } + + public static class DummyNetworkManager extends NetworkManager { + + @Remap(classPath = "net.minecraft.network.protocol.PacketFlow", name = "SERVERBOUND", type = Remap.Type.FIELD, remappedName = "a") + @Remap(classPath = "net.minecraft.network.Connection", name = "channel", type = Remap.Type.FIELD, remappedName = "m") + @Remap(classPath = "net.minecraft.network.Connection", name = "address", type = Remap.Type.FIELD, remappedName = "n") + DummyNetworkManager() { + super(EnumProtocolDirection.a); + this.m = new DummyChannel(); + this.n = null; + } + + } + + public static class DummyPlayerConnection extends PlayerConnection { + + DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) { + super(minecraftServer, new DummyNetworkManager(), entityPlayer); + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleContainerClick", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInWindowClick packetPlayInWindowClick) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleMovePlayer", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInFlying packetPlayInFlying) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleSignUpdate", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handlePlayerAction", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInBlockDig packetPlayInBlockDig) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleUseItem", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) { + + } + + public void disconnect(String s) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleSetCarriedItem", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleChat", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInChat packetPlayInChat) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "send", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(Packet packet) { + + } + + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/EntityHolograms.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/EntityHolograms.java new file mode 100644 index 0000000..998bc1a --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/EntityHolograms.java @@ -0,0 +1,245 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.sounds.SoundEffect; +import net.minecraft.world.EnumHand; +import net.minecraft.world.EnumInteractionResult; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.EnumItemSlot; +import net.minecraft.world.entity.decoration.EntityArmorStand; +import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.World; +import net.minecraft.world.phys.AxisAlignedBB; +import net.minecraft.world.phys.Vec3D; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftArmorStand; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_18_R2.util.CraftChatMessage; + +@SuppressWarnings("unused") +public final class EntityHolograms extends EntityArmorStand implements Hologram { + + private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); + + private CraftEntity bukkitEntity; + + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setInvisible", type = Remap.Type.METHOD, remappedName = "j") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setSmall", type = Remap.Type.METHOD, remappedName = "a") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setShowArms", type = Remap.Type.METHOD, remappedName = "r") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setNoGravity", type = Remap.Type.METHOD, remappedName = "e") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setNoBasePlate", type = Remap.Type.METHOD, remappedName = "s") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setMarker", type = Remap.Type.METHOD, remappedName = "t") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setCustomNameVisible", type = Remap.Type.METHOD, remappedName = "n") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setBoundingBox", type = Remap.Type.METHOD, remappedName = "a") + public EntityHolograms(World world, double x, double y, double z){ + super(world, x, y, z); + j(true); // Invisible + a(true); // Small + r(false); // Arms + e(true); // No Gravity + s(true); // Base Plate + t(true); // Marker + super.collides = false; + super.n(true); // Custom name visible + super.a(EMPTY_BOUND); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomName", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void setHologramName(String name) { + super.a(CraftChatMessage.fromStringOrNull(name)); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void removeHologram() { + super.a(RemovalReason.b); + } + + @Override + public org.bukkit.entity.Entity getEntity() { + return getBukkitEntity(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "tick", + type = Remap.Type.METHOD, + remappedName = "k") + @Override + public void k() { + // Disable normal ticking for this entity. + + // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. + if (this.y) { + this.y = false; + } + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "onGround", + type = Remap.Type.FIELD, + remappedName = "y") + @Override + public void inactiveTick() { + // Disable normal ticking for this entity. + + // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. + if (this.y) { + this.y = false; + } + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "addAdditionalSaveData", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public void b(NBTTagCompound nbttagcompound) { + // Do not save NBT. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "saveAsPassenger", + type = Remap.Type.METHOD, + remappedName = "d") + @Override + public boolean d(NBTTagCompound nbttagcompound) { + // Do not save NBT. + return false; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "saveWithoutId", + type = Remap.Type.METHOD, + remappedName = "f") + @Override + public NBTTagCompound f(NBTTagCompound nbttagcompound) { + // Do not save NBT. + return nbttagcompound; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "readAdditionalSaveData", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(NBTTagCompound nbttagcompound) { + // Do not load NBT. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "load", + type = Remap.Type.METHOD, + remappedName = "g") + @Override + public void g(NBTTagCompound nbttagcompound) { + // Do not load NBT. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "isInvulnerableTo", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public boolean b(DamageSource source) { + /* + * The field Entity.invulnerable is private. + * It's only used while saving NBTTags, but since the entity would be killed + * on chunk unload, we prefer to override isInvulnerable(). + */ + return true; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "repositionEntityAfterLoad", + type = Remap.Type.METHOD, + remappedName = "bj") + @Override + public boolean bj() { + return false; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomName", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomNameVisible", + type = Remap.Type.METHOD, + remappedName = "n") + @Override + public void n(boolean flag) { + // Locks the custom name. + } + + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", + name = "interactAt", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.d; + } + + @Override + public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean flag) { + // Prevent stand being equipped + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getBoundingBoxForCulling", + type = Remap.Type.METHOD, + remappedName = "cx") + @Override + public AxisAlignedBB cx() { + return EMPTY_BOUND; + } + + public void forceSetBoundingBox(AxisAlignedBB boundingBox) { + super.a(boundingBox); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "playSound", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(RemovalReason entity_removalreason) { + // Prevent being killed. + } + + @Override + public CraftEntity getBukkitEntity() { + if (bukkitEntity == null) { + bukkitEntity = new CraftArmorStand((CraftServer) Bukkit.getServer(), this); + } + return bukkitEntity; + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/NMSAdapter.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/NMSAdapter.java new file mode 100644 index 0000000..fc9ed4a --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/NMSAdapter.java @@ -0,0 +1,200 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2; + +import com.bgsoftware.common.reflection.ReflectMethod; +import com.bgsoftware.wildloaders.WildLoadersPlugin; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.loader.TileEntityChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.core.BlockPosition; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.nbt.NBTTagCompound; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.item.ItemStack; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.World; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.block.entity.TileEntity; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.block.state.IBlockData; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.chunk.Chunk; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagLong; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R2.CraftChunk; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; + +import java.util.UUID; + +@SuppressWarnings("unused") +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { + + private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); + + @Remap(classPath = "net.minecraft.world.level.chunk.LevelChunk", name = "createTicker", type = Remap.Type.METHOD) + private static final ReflectMethod CREATE_TICKING_BLOCK = new ReflectMethod<>( + net.minecraft.world.level.chunk.Chunk.class, "a", + net.minecraft.world.level.block.entity.TileEntity.class, BlockEntityTicker.class); + + @Override + public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getTag(); + + if (tagCompound == null || !tagCompound.contains(key, 8)) + return def; + + return tagCompound.getString(key); + } + + @Override + public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + tagCompound.put(key, NBTTagString.a(value)); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getTag(); + + if (tagCompound == null || !tagCompound.contains(key, 4)) + return def; + + return tagCompound.getLong(key); + } + + @Override + public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + tagCompound.put(key, NBTTagLong.a(value)); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + NBTTagCompound skullOwner = tagCompound.contains("SkullOwner") ? + tagCompound.getCompound("SkullOwner") : new NBTTagCompound(); + + NBTTagCompound properties = new NBTTagCompound(); + + NBTTagList textures = new NBTTagList(); + NBTTagCompound signature = new NBTTagCompound(); + signature.putString("Value", texture); + textures.add(signature.getHandle()); + + properties.put("textures", textures); + + skullOwner.put("Properties", properties.getHandle()); + skullOwner.putString("Id", UUID.randomUUID().toString()); + + tagCompound.put("SkullOwner", skullOwner.getHandle()); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) { + Location loaderLoc = chunkLoader.getLocation(); + assert loaderLoc.getWorld() != null; + + World world = new World(((CraftWorld) loaderLoc.getWorld()).getHandle()); + BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); + + TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); + world.addBlockEntityTicker(tileEntityChunkLoader.ticker); + + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = new Chunk(((CraftChunk) bukkitChunk).getHandle()); + chunk.getBlockEntities().values().stream() + .filter(nmsTileEntity -> nmsTileEntity instanceof TileEntityMobSpawner) + .forEach(nmsTileEntity -> { + TileEntity tileEntity = new TileEntity(nmsTileEntity); + tileEntity.getSpawner().m = -1; + }); + + ChunkCoordIntPair chunkCoords = chunk.getPos(); + + world.setChunkForced(chunkCoords.getX(), chunkCoords.getZ(), true); + } + + return tileEntityChunkLoader; + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) { + Location loaderLoc = chunkLoader.getLocation(); + assert loaderLoc.getWorld() != null; + + World world = new World(((CraftWorld) loaderLoc.getWorld()).getHandle()); + BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); + + long tileEntityLong = ChunkCoordIntPair.asLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); + TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); + tileEntityChunkLoader.removed = true; + } + + if (spawnParticle) { + world.levelEvent(null, 2001, blockPosition.getHandle(), + IBlockData.getId(world.getBlockStateNoMappings(blockPosition.getHandle()))); + } + + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = new Chunk(((CraftChunk) bukkitChunk).getHandle()); + chunk.getBlockEntities().values().stream() + .filter(nmsTileEntity -> nmsTileEntity instanceof TileEntityMobSpawner) + .forEach(nmsTileEntity -> { + TileEntity tileEntity = new TileEntity(nmsTileEntity); + tileEntity.getSpawner().m = 16; + }); + + ChunkCoordIntPair chunkCoords = chunk.getPos(); + + world.setChunkForced(chunkCoords.getX(), chunkCoords.getZ(), false); + } + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public void updateSpawner(Location location, boolean reset) { + assert location.getWorld() != null; + World world = new World(((CraftWorld) location.getWorld()).getHandle()); + + BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ()); + TileEntity mobSpawner = new TileEntity(world.getBlockEntity(blockPosition.getHandle())); + + mobSpawner.getSpawner().m = reset ? 16 : -1; + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoader.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..22872c2 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoader.java @@ -0,0 +1,161 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.EntityHolograms; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.core.BlockPosition; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.World; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + public final TileEntityChunkLoaderTicker ticker; + public final BlockPosition tilePosition; + private final World world; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntityType", name = "COMMAND_BLOCK", type = Remap.Type.FIELD, remappedName = "v") + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", name = "setLevel", type = Remap.Type.METHOD, remappedName = "a") + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + super(TileEntityTypes.v, blockPosition.getHandle(), world.getBlockStateNoMappings(blockPosition.getHandle())); + + this.chunkLoader = (WChunkLoader) chunkLoader; + this.ticker = new TileEntityChunkLoaderTicker(this); + this.tilePosition = blockPosition; + this.world = world; + + a(world.getHandle()); + + loaderBlock = world.getBlockState(blockPosition.getHandle()).getBlock(); + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(ChunkCoordIntPair.asLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = this.tilePosition.getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world.getHandle(), + this.tilePosition.getX() + 0.5, currentY, this.tilePosition.getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addFreshEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", + name = "getType", + type = Remap.Type.METHOD, + remappedName = "u") + public TileEntityTypes getType() { + return super.u(); + } + + public void tick() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + if (chunkLoader.isNotActive() || this.world.getBlockState(this.tilePosition.getHandle()).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", + name = "isRemoved", + type = Remap.Type.METHOD, + remappedName = "r") + @Override + public boolean r() { + return isRemoved(); + } + + public boolean isRemoved() { + return removed || super.r(); + } + + private void updateName(EntityHolograms hologram, String line) { + assert chunkLoader.getWhoPlaced().getName() != null; + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} + diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoaderTicker.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoaderTicker.java new file mode 100644 index 0000000..def0454 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/loader/TileEntityChunkLoaderTicker.java @@ -0,0 +1,46 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.loader; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +public record TileEntityChunkLoaderTicker(TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "tick", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a() { + tileEntityChunkLoader.tick(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "isRemoved", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public boolean b() { + return tileEntityChunkLoader.isRemoved(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "getPos", + type = Remap.Type.METHOD, + remappedName = "c") + @Override + public BlockPosition c() { + return tileEntityChunkLoader.tilePosition.getHandle(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "getType", + type = Remap.Type.METHOD, + remappedName = "d") + @Override + public String d() { + return TileEntityTypes.a(tileEntityChunkLoader.getType()) + ""; + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/MappedObject.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/MappedObject.java new file mode 100644 index 0000000..aeedbef --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/MappedObject.java @@ -0,0 +1,15 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings; + +public abstract class MappedObject { + + protected final E handle; + + protected MappedObject(E handle) { + this.handle = handle; + } + + public E getHandle() { + return handle; + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/core/BlockPosition.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/core/BlockPosition.java new file mode 100644 index 0000000..230b955 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/core/BlockPosition.java @@ -0,0 +1,40 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.core; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; + +public class BlockPosition extends MappedObject { + + public BlockPosition(double x, double y, double z) { + this(new net.minecraft.core.BlockPosition(x, y, z)); + } + + public BlockPosition(net.minecraft.core.BlockPosition handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getX", + type = Remap.Type.METHOD, + remappedName = "u") + public int getX() { + return handle.u(); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getY", + type = Remap.Type.METHOD, + remappedName = "v") + public int getY() { + return handle.v(); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getZ", + type = Remap.Type.METHOD, + remappedName = "w") + public int getZ() { + return handle.w(); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/nbt/NBTTagCompound.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/nbt/NBTTagCompound.java new file mode 100644 index 0000000..850944f --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/nbt/NBTTagCompound.java @@ -0,0 +1,77 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.nbt; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import net.minecraft.nbt.NBTBase; + +public class NBTTagCompound extends MappedObject { + + public static NBTTagCompound ofNullable(net.minecraft.nbt.NBTTagCompound handle) { + return handle == null ? null : new NBTTagCompound(handle); + } + + public NBTTagCompound() { + this(new net.minecraft.nbt.NBTTagCompound()); + } + + public NBTTagCompound(net.minecraft.nbt.NBTTagCompound handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "contains", + type = Remap.Type.METHOD, + remappedName = "b") + public boolean contains(String key, int type) { + return handle.b(key, type); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getString", + type = Remap.Type.METHOD, + remappedName = "l") + public String getString(String key) { + return handle.l(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "put", + type = Remap.Type.METHOD, + remappedName = "a") + public void put(String key, NBTBase nbtBase) { + handle.a(key, nbtBase); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getLong", + type = Remap.Type.METHOD, + remappedName = "i") + public long getLong(String key) { + return handle.i(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "contains", + type = Remap.Type.METHOD, + remappedName = "e") + public boolean contains(String key) { + return handle.e(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getCompound", + type = Remap.Type.METHOD, + remappedName = "p") + public NBTTagCompound getCompound(String key) { + return new NBTTagCompound(handle.p(key)); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "putString", + type = Remap.Type.METHOD, + remappedName = "a") + public void putString(String key, String value) { + handle.a(key, value); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/entity/Entity.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/entity/Entity.java new file mode 100644 index 0000000..1307af7 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/entity/Entity.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.entity; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.World; + +public class Entity extends MappedObject { + + public Entity(net.minecraft.world.entity.Entity handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getLevel", + type = Remap.Type.METHOD, + remappedName = "W") + public World getWorld() { + return new World(handle.W()); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "moveTo", + type = Remap.Type.METHOD, + remappedName = "b") + public void moveTo(double x, double y, double z, float yaw, float pitch) { + handle.b(x, y, z, yaw, pitch); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/item/ItemStack.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/item/ItemStack.java new file mode 100644 index 0000000..71d6fb4 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/item/ItemStack.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.item; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.nbt.NBTTagCompound; + +public class ItemStack extends MappedObject { + + public ItemStack(net.minecraft.world.item.ItemStack handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.item.ItemStack", + name = "getOrCreateTag", + type = Remap.Type.METHOD, + remappedName = "u") + public NBTTagCompound getOrCreateTag() { + return new NBTTagCompound(handle.u()); + } + + @Remap(classPath = "net.minecraft.world.item.ItemStack", + name = "getTag", + type = Remap.Type.METHOD, + remappedName = "t") + public NBTTagCompound getTag() { + return NBTTagCompound.ofNullable(handle.t()); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/ChunkCoordIntPair.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/ChunkCoordIntPair.java new file mode 100644 index 0000000..99a5163 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/ChunkCoordIntPair.java @@ -0,0 +1,36 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; + +public class ChunkCoordIntPair extends MappedObject { + + public ChunkCoordIntPair(net.minecraft.world.level.ChunkCoordIntPair handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "x", + type = Remap.Type.FIELD, + remappedName = "c") + public int getX() { + return handle.c; + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "z", + type = Remap.Type.FIELD, + remappedName = "d") + public int getZ() { + return handle.d; + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "asLong", + type = Remap.Type.METHOD, + remappedName = "a") + public static long asLong(int x, int z) { + return net.minecraft.world.level.ChunkCoordIntPair.a(x, z); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/World.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/World.java new file mode 100644 index 0000000..2261747 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/World.java @@ -0,0 +1,87 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.core.BlockPosition; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntity; + +public class World extends MappedObject { + + public World(net.minecraft.world.level.World handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "setChunkForced", + type = Remap.Type.METHOD, + remappedName = "a") + public void setChunkForced(int chunkX, int chunkZ, boolean load) { + ((WorldServer) handle).a(chunkX, chunkZ, load); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "addNewPlayer", + type = Remap.Type.METHOD, + remappedName = "c") + public void addNewPlayer(EntityPlayer entityPlayer) { + ((WorldServer) handle).c(entityPlayer); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "removePlayerImmediately", + type = Remap.Type.METHOD, + remappedName = "a") + public void removePlayer(EntityPlayer entityPlayer, Entity.RemovalReason removalReason) { + ((WorldServer) handle).a(entityPlayer, removalReason); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "getBlockState", + type = Remap.Type.METHOD, + remappedName = "a_") + public net.minecraft.world.level.block.state.IBlockData getBlockStateNoMappings(BlockPosition blockPosition) { + return handle.a_(blockPosition); + } + + public IBlockData getBlockState(BlockPosition blockPosition) { + return new IBlockData(getBlockStateNoMappings(blockPosition)); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "getBlockEntity", + type = Remap.Type.METHOD, + remappedName = "c_") + public TileEntity getBlockEntity(BlockPosition blockPosition) { + return handle.c_(blockPosition); + } + + @Remap(classPath = "net.minecraft.world.level.LevelWriter", + name = "addFreshEntity", + type = Remap.Type.METHOD, + remappedName = "b") + public void addFreshEntity(Entity entity) { + handle.b(entity); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "addBlockEntityTicker", + type = Remap.Type.METHOD, + remappedName = "a") + public void addBlockEntityTicker(TickingBlockEntity blockEntityTicker) { + handle.a(blockEntityTicker); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "levelEvent", + type = Remap.Type.METHOD, + remappedName = "a") + public void levelEvent(EntityPlayer entityPlayer, int i, BlockPosition blockPosition, int j) { + handle.a(entityPlayer, i, blockPosition, j); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/entity/TileEntity.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/entity/TileEntity.java new file mode 100644 index 0000000..47abbe9 --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/entity/TileEntity.java @@ -0,0 +1,22 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.block.entity; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import net.minecraft.world.level.MobSpawnerAbstract; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; + +public class TileEntity extends MappedObject { + + public TileEntity(net.minecraft.world.level.block.entity.TileEntity handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.SpawnerBlockEntity", + name = "getSpawner", + type = Remap.Type.METHOD, + remappedName = "d") + public MobSpawnerAbstract getSpawner() { + return ((TileEntityMobSpawner) handle).d(); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/state/IBlockData.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/state/IBlockData.java new file mode 100644 index 0000000..aa2b47a --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/block/state/IBlockData.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.block.state; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import net.minecraft.world.level.block.Block; + +public class IBlockData extends MappedObject { + + public IBlockData(net.minecraft.world.level.block.state.IBlockData handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase", + name = "getBlock", + type = Remap.Type.METHOD, + remappedName = "b") + public Block getBlock() { + return handle.b(); + } + + @Remap(classPath = "net.minecraft.world.level.block.Block", + name = "getId", + type = Remap.Type.METHOD, + remappedName = "i") + public static int getId(net.minecraft.world.level.block.state.IBlockData blockData) { + return Block.i(blockData); + } + +} diff --git a/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/chunk/Chunk.java b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/chunk/Chunk.java new file mode 100644 index 0000000..51e10ec --- /dev/null +++ b/v1_18_R2/src/main/java/com/bgsoftware/wildloaders/nms/v1_18_R2/mappings/net/minecraft/world/level/chunk/Chunk.java @@ -0,0 +1,33 @@ +package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.chunk; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_18_R2.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TileEntity; + +import java.util.Map; + +public class Chunk extends MappedObject { + + public Chunk(net.minecraft.world.level.chunk.Chunk handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.chunk.LevelChunk", + name = "getBlockEntities", + type = Remap.Type.METHOD, + remappedName = "E") + public Map getBlockEntities() { + return handle.E(); + } + + @Remap(classPath = "net.minecraft.world.level.chunk.ChunkAccess", + name = "getPos", + type = Remap.Type.METHOD, + remappedName = "f") + public ChunkCoordIntPair getPos() { + return new ChunkCoordIntPair(handle.f()); + } + +} diff --git a/v1_19_R1/build.gradle b/v1_19_R1/build.gradle index 30f29c8..ccaa4db 100644 --- a/v1_19_R1/build.gradle +++ b/v1_19_R1/build.gradle @@ -12,7 +12,7 @@ repositories { } dependencies { - compileOnly "org.spigotmc:v1_19_R1-Paper:git-02b5ec4" + compileOnly "org.spigotmc:v1_19_R1-Paper:git-4a4ee79" compileOnly 'io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT' diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_19_R1.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_19_R1.java deleted file mode 100644 index 31a4680..0000000 --- a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_19_R1.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import com.bgsoftware.wildloaders.handlers.NPCHandler; -import com.bgsoftware.wildloaders.npc.DummyChannel; -import com.mojang.authlib.GameProfile; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.protocol.EnumProtocolDirection; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.PacketPlayInBlockDig; -import net.minecraft.network.protocol.game.PacketPlayInBlockPlace; -import net.minecraft.network.protocol.game.PacketPlayInChat; -import net.minecraft.network.protocol.game.PacketPlayInFlying; -import net.minecraft.network.protocol.game.PacketPlayInHeldItemSlot; -import net.minecraft.network.protocol.game.PacketPlayInUpdateSign; -import net.minecraft.network.protocol.game.PacketPlayInWindowClick; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.AxisAlignedBB; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.entity.Player; - -import java.util.UUID; - -import static com.bgsoftware.wildloaders.nms.NMSMappings_v1_19_R1.*; - -public final class ChunkLoaderNPC_v1_19_R1 extends EntityPlayer implements ChunkLoaderNPC { - - private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - - private boolean dieCall = false; - - public ChunkLoaderNPC_v1_19_R1(MinecraftServer minecraftServer, Location location, UUID uuid) { - super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), - new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())), null); - - this.b = new DummyPlayerConnection(minecraftServer, this); - - NMSMappings_v1_19_R1.setGameModeForPlayer(this.d, EnumGamemode.b); - clientViewDistance = 1; - - fauxSleeping = true; - - spawnIn(getWorld(this)); - moveTo(this, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - - addNewPlayer(getLevel(this), this); - - super.a(EMPTY_BOUND); - } - - @Override - public UUID getUniqueId() { - return super.cp(); - } - - @Override - public void die() { - ah(); - } - - @Override - public AxisAlignedBB cA() { - return EMPTY_BOUND; - } - - @Override - public void a(RemovalReason removalReason) { - if (!dieCall) { - dieCall = true; - removePlayer(getLevel(this), this); - dieCall = false; - } else { - super.a(removalReason); - } - } - - @Override - public Location getLocation() { - return getBukkitEntity().getLocation(); - } - - @Override - public Player getPlayer() { - return getBukkitEntity(); - } - - private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer) { - worldServer.a(entityPlayer, RemovalReason.d); - } - - public static class DummyNetworkManager extends NetworkManager { - - DummyNetworkManager() { - super(EnumProtocolDirection.a); - this.m = new DummyChannel(); - this.n = null; - } - - } - - public static class DummyPlayerConnection extends PlayerConnection { - - DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) { - super(minecraftServer, new DummyNetworkManager(), entityPlayer); - } - - public void a(PacketPlayInWindowClick packetPlayInWindowClick) { - - } - - public void a(PacketPlayInFlying packetPlayInFlying) { - - } - - public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) { - - } - - public void a(PacketPlayInBlockDig packetPlayInBlockDig) { - - } - - public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) { - - } - - public void disconnect(String s) { - - } - - public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) { - - } - - public void a(PacketPlayInChat packetPlayInChat) { - - } - - public void a(Packet packet) { - - } - - } - -} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_19_R1.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_19_R1.java deleted file mode 100644 index e46280f..0000000 --- a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_19_R1.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.wildloaders.api.holograms.Hologram; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.sounds.SoundEffect; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.AxisAlignedBB; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R1.CraftServer; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftArmorStand; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage; - -@SuppressWarnings("unused") -public final class EntityHolograms_v1_19_R1 extends EntityArmorStand implements Hologram { - - private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - - private CraftEntity bukkitEntity; - - public EntityHolograms_v1_19_R1(World world, double x, double y, double z){ - super(world, x, y, z); - j(true); // Invisible - a(true); // Small - r(false); // Arms - e(true); // No Gravity - s(true); // Base Plate - t(true); // Marker - super.collides = false; - super.n(true); // Custom name visible - super.a(EMPTY_BOUND); - } - - @Override - public void setHologramName(String name) { - super.b(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public void removeHologram() { - super.a(RemovalReason.b); - } - - @Override - public org.bukkit.entity.Entity getEntity() { - return getBukkitEntity(); - } - - @Override - public void k() { - // Disable normal ticking for this entity. - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. - if (this.z) { - this.z = false; - } - } - - @Override - public void inactiveTick() { - // Disable normal ticking for this entity. - - // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. - if (this.z) { - this.z = false; - } - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - // Do not save NBT. - } - - @Override - public boolean d(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return false; - } - - @Override - public NBTTagCompound f(NBTTagCompound nbttagcompound) { - // Do not save NBT. - return nbttagcompound; - } - - @Override - public void a(NBTTagCompound nbttagcompound) { - // Do not load NBT. - } - - @Override - public void g(NBTTagCompound nbttagcompound) { - // Do not load NBT. - } - - @Override - public boolean b(DamageSource source) { - /* - * The field Entity.invulnerable is private. - * It's only used while saving NBTTags, but since the entity would be killed - * on chunk unload, we prefer to override isInvulnerable(). - */ - return true; - } - - @Override - public boolean bm() { - return false; - } - - @Override - public void a(IChatBaseComponent ichatbasecomponent) { - // Locks the custom name. - } - - @Override - public void n(boolean flag) { - // Locks the custom name. - } - - @Override - public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { - // Prevent stand being equipped - return EnumInteractionResult.d; - } - - @Override - public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean flag) { - // Prevent stand being equipped - } - - @Override - public AxisAlignedBB cA() { - return EMPTY_BOUND; - } - - public void forceSetBoundingBox(AxisAlignedBB boundingBox) { - super.a(boundingBox); - } - - @Override - public void a(SoundEffect soundeffect, float f, float f1) { - // Remove sounds. - } - - @Override - public void a(RemovalReason entity_removalreason) { - // Prevent being killed. - } - - @Override - public CraftEntity getBukkitEntity() { - if (bukkitEntity == null) { - bukkitEntity = new CraftArmorStand((CraftServer) Bukkit.getServer(), this); - } - return bukkitEntity; - } - -} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_19_R1.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_19_R1.java deleted file mode 100644 index 0660f50..0000000 --- a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_19_R1.java +++ /dev/null @@ -1,333 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.common.reflection.ReflectMethod; -import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; -import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagLong; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityTicker; -import net.minecraft.world.level.block.entity.TickingBlockEntity; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.Chunk; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_19_R1.CraftServer; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.bgsoftware.wildloaders.nms.NMSMappings_v1_19_R1.*; - -@SuppressWarnings("unused") -public final class NMSAdapter_v1_19_R1 implements NMSAdapter { - - private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); - - private static final ReflectMethod CREATE_TICKING_BLOCK = new ReflectMethod<>( - Chunk.class, "a", TileEntity.class, BlockEntityTicker.class); - - @Override - public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - if(!contains(tagCompound, key, 8)) - return def; - - return getString(tagCompound, key); - } - - @Override - public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - put(tagCompound, key, NBTTagString.a(value)); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - if(!contains(tagCompound, key, 4)) - return def; - - return getLong(tagCompound, key); - } - - @Override - public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound tagCompound = getOrCreateTag(nmsItem); - - put(tagCompound, key, NBTTagLong.a(value)); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) { - ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); - - NBTTagCompound nbtTagCompound = getOrCreateTag(nmsItem); - - NBTTagCompound skullOwner = NMSMappings_v1_19_R1.contains(nbtTagCompound, "SkullOwner") ? - getCompound(nbtTagCompound, "SkullOwner") : new NBTTagCompound(); - - NBTTagCompound properties = new NBTTagCompound(); - - NBTTagList textures = new NBTTagList(); - NBTTagCompound signature = new NBTTagCompound(); - putString(signature, "Value", texture); - textures.add(signature); - - put(properties, "textures", textures); - - put(skullOwner, "Properties", properties); - putString(skullOwner,"Id", UUID.randomUUID().toString()); - - put(nbtTagCompound, "SkullOwner", skullOwner); - - return CraftItemStack.asBukkitCopy(nmsItem); - } - - @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_19_R1(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); - } - - @Override - public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) { - Location loaderLoc = chunkLoader.getLocation(); - assert loaderLoc.getWorld() != null; - WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); - - TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); - world.a(tileEntityChunkLoader.ticker); - - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { - Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); - getBlockEntities(chunk).values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> getSpawner((TileEntityMobSpawner) tileEntity).m = -1); - - ChunkCoordIntPair chunkCoords = getPos(chunk); - - setChunkForced(world, chunkCoords.e, chunkCoords.f, true); - } - - return tileEntityChunkLoader; - } - - @Override - public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) { - Location loaderLoc = chunkLoader.getLocation(); - assert loaderLoc.getWorld() != null; - WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); - - long tileEntityLong = ChunkCoordIntPair.c(getX(blockPosition) >> 4, getZ(blockPosition) >> 4); - TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_19_R1::removeHologram); - tileEntityChunkLoader.removed = true; - } - - if(spawnParticle) - world.a(null, 2001, blockPosition, getId(getBlockState(world, blockPosition))); - - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { - Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); - getBlockEntities(chunk).values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> getSpawner((TileEntityMobSpawner) tileEntity).m = 16); - - ChunkCoordIntPair chunkCoords = getPos(chunk); - - setChunkForced(world, chunkCoords.e, chunkCoords.f, false); - } - } - - @Override - public void updateSpawner(Location location, boolean reset) { - assert location.getWorld() != null; - World world = ((CraftWorld) location.getWorld()).getHandle(); - - BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ()); - IBlockData blockData = getBlockState(world, blockPosition); - TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) getBlockEntity(world, blockPosition); - - if(mobSpawner == null) - return; - - getSpawner(mobSpawner).m = reset ? 16 : -1; - } - - private static final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - private final TileEntityChunkLoaderTicker ticker; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - super(TileEntityTypes.v, blockPosition, getBlockState(world, blockPosition)); - - this.chunkLoader = (WChunkLoader) chunkLoader; - this.ticker = new TileEntityChunkLoaderTicker(this); - - a(world); - - loaderBlock = getBlock(getBlockState(world, blockPosition)); - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(ChunkCoordIntPair.c(getX(blockPosition) >> 4, getZ(blockPosition) >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = getY(getBlockPos(this)) + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_19_R1 hologram = new EntityHolograms_v1_19_R1(world, - getX(getBlockPos(this)) + 0.5, currentY, getZ(getBlockPos(this)) + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - addFreshEntity(world, hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - public void tick() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - assert this.n != null; - if(chunkLoader.isNotActive() || getBlock(getBlockState(this.n, getBlockPos(this))) != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_19_R1 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - @Override - public boolean r() { - return removed || super.r(); - } - - private void updateName(EntityHolograms_v1_19_R1 hologram, String line){ - assert chunkLoader.getWhoPlaced().getName() != null; - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - - private record TileEntityChunkLoaderTicker( - TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { - - @Override - public void a() { - tileEntityChunkLoader.tick(); - } - - @Override - public boolean b() { - return tileEntityChunkLoader.r(); - } - - @Override - public BlockPosition c() { - return getBlockPos(tileEntityChunkLoader); - } - - @Override - public String d() { - return TileEntityTypes.a(getType(tileEntityChunkLoader)) + ""; - } - } - -} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_19_R1.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_19_R1.java deleted file mode 100644 index ccac3fc..0000000 --- a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSMappings_v1_19_R1.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.bgsoftware.wildloaders.nms; - -import com.bgsoftware.common.reflection.ReflectMethod; -import net.minecraft.core.BaseBlockPosition; -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.PlayerInteractManager; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.level.IWorldWriter; -import net.minecraft.world.level.MobSpawnerAbstract; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; - -import java.util.Map; - -public final class NMSMappings_v1_19_R1 { - - private static final ReflectMethod SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class, - 1, EnumGamemode.class, EnumGamemode.class); - - private NMSMappings_v1_19_R1() { - - } - - public static NBTTagCompound getOrCreateTag(ItemStack itemStack) { - return itemStack.v(); - } - - public static boolean contains(NBTTagCompound nbtTagCompound, String key, int type) { - return nbtTagCompound.b(key, type); - } - - public static String getString(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.l(key); - } - - public static void put(NBTTagCompound nbtTagCompound, String key, NBTBase nbtBase) { - nbtTagCompound.a(key, nbtBase); - } - - public static long getLong(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.i(key); - } - - public static boolean contains(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.e(key); - } - - public static NBTTagCompound getCompound(NBTTagCompound nbtTagCompound, String key) { - return nbtTagCompound.p(key); - } - - public static void putString(NBTTagCompound nbtTagCompound, String key, String value) { - nbtTagCompound.a(key, value); - } - - public static Map getBlockEntities(IChunkAccess chunkAccess) { - return chunkAccess.i; - } - - public static ChunkCoordIntPair getPos(IChunkAccess chunk) { - return chunk.f(); - } - - public static MobSpawnerAbstract getSpawner(TileEntityMobSpawner tileEntityMobSpawner) { - return tileEntityMobSpawner.d(); - } - - public static void setChunkForced(WorldServer worldServer, int chunkX, int chunkZ, boolean load) { - worldServer.a(chunkX, chunkZ, load); - } - - public static void addNewPlayer(WorldServer worldServer, EntityPlayer entityPlayer) { - worldServer.c(entityPlayer); - } - - public static int getId(IBlockData blockData) { - return Block.i(blockData); - } - - public static Block getBlock(IBlockData blockData) { - return blockData.b(); - } - - public static int getX(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.u(); - } - - public static int getY(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.v(); - } - - public static int getZ(BaseBlockPosition baseBlockPosition) { - return baseBlockPosition.w(); - } - - public static IBlockData getBlockState(World world, BlockPosition blockPosition) { - return world.a_(blockPosition); - } - - public static TileEntity getBlockEntity(World world, BlockPosition blockPosition) { - return world.c_(blockPosition); - } - - public static void addFreshEntity(IWorldWriter worldWriter, Entity entity) { - worldWriter.b(entity); - } - - public static BlockPosition getBlockPos(TileEntity tileEntity) { - return tileEntity.p(); - } - - public static TileEntityTypes getType(TileEntity tileEntity) { - return tileEntity.v(); - } - - public static void setGameModeForPlayer(PlayerInteractManager playerInteractManager, EnumGamemode gamemode) { - SET_GAMEMODE.invoke(playerInteractManager, gamemode, null); - } - - public static World getWorld(Entity entity) { - return entity.W(); - } - - public static void moveTo(Entity entity, double x, double y, double z, float yaw, float pitch) { - entity.b(x, y, z, yaw, pitch); - } - - public static WorldServer getLevel(EntityPlayer entityPlayer) { - return entityPlayer.x(); - } - -} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/ChunkLoaderNPC.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/ChunkLoaderNPC.java new file mode 100644 index 0000000..a95ccb5 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/ChunkLoaderNPC.java @@ -0,0 +1,207 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1; + +import com.bgsoftware.common.reflection.ReflectMethod; +import com.bgsoftware.wildloaders.handlers.NPCHandler; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.entity.Entity; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.World; +import com.bgsoftware.wildloaders.npc.DummyChannel; +import com.mojang.authlib.GameProfile; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.protocol.EnumProtocolDirection; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.PacketPlayInBlockDig; +import net.minecraft.network.protocol.game.PacketPlayInBlockPlace; +import net.minecraft.network.protocol.game.PacketPlayInChat; +import net.minecraft.network.protocol.game.PacketPlayInFlying; +import net.minecraft.network.protocol.game.PacketPlayInHeldItemSlot; +import net.minecraft.network.protocol.game.PacketPlayInUpdateSign; +import net.minecraft.network.protocol.game.PacketPlayInWindowClick; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.PlayerInteractManager; +import net.minecraft.server.network.PlayerConnection; +import net.minecraft.world.level.EnumGamemode; +import net.minecraft.world.phys.AxisAlignedBB; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { + + private static final ReflectMethod SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class, + 1, EnumGamemode.class, EnumGamemode.class); + + private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); + + private final World world; + + private boolean dieCall = false; + + @Remap(classPath = "net.minecraft.server.level.ServerPlayer", name = "gameMode", type = Remap.Type.FIELD, remappedName = "d") + public ChunkLoaderNPC(MinecraftServer minecraftServer, Location location, UUID uuid) { + super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(), + new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())), null); + + Entity entity = new Entity(this); + this.world = entity.getWorld(); + + this.b = new DummyPlayerConnection(minecraftServer, this); + + SET_GAMEMODE.invoke(this.d, EnumGamemode.b); + clientViewDistance = 1; + + fauxSleeping = true; + + spawnIn(this.world.getHandle()); + entity.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + + this.world.addNewPlayer(this); + + super.a(EMPTY_BOUND); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getUUID", + type = Remap.Type.METHOD, + remappedName = "co") + @Override + public UUID getUniqueId() { + return super.co(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "discard", + type = Remap.Type.METHOD, + remappedName = "ah") + @Override + public void die() { + ah(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getBoundingBoxForCulling", + type = Remap.Type.METHOD, + remappedName = "cz") + @Override + public AxisAlignedBB cz() { + return EMPTY_BOUND; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(RemovalReason removalReason) { + if (!dieCall) { + dieCall = true; + this.world.removePlayer(this, RemovalReason.d); + dieCall = false; + } else { + super.a(removalReason); + } + } + + @Override + public Location getLocation() { + return getBukkitEntity().getLocation(); + } + + @Override + public Player getPlayer() { + return getBukkitEntity(); + } + + public static class DummyNetworkManager extends NetworkManager { + + @Remap(classPath = "net.minecraft.network.protocol.PacketFlow", name = "SERVERBOUND", type = Remap.Type.FIELD, remappedName = "a") + @Remap(classPath = "net.minecraft.network.Connection", name = "channel", type = Remap.Type.FIELD, remappedName = "m") + @Remap(classPath = "net.minecraft.network.Connection", name = "address", type = Remap.Type.FIELD, remappedName = "n") + DummyNetworkManager() { + super(EnumProtocolDirection.a); + this.m = new DummyChannel(); + this.n = null; + } + + } + + public static class DummyPlayerConnection extends PlayerConnection { + + DummyPlayerConnection(MinecraftServer minecraftServer, EntityPlayer entityPlayer) { + super(minecraftServer, new DummyNetworkManager(), entityPlayer); + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleContainerClick", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInWindowClick packetPlayInWindowClick) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleMovePlayer", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInFlying packetPlayInFlying) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleSignUpdate", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInUpdateSign packetPlayInUpdateSign) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handlePlayerAction", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInBlockDig packetPlayInBlockDig) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleUseItem", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInBlockPlace packetPlayInBlockPlace) { + + } + + public void disconnect(String s) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleSetCarriedItem", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInHeldItemSlot packetPlayInHeldItemSlot) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "handleChat", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(PacketPlayInChat packetPlayInChat) { + + } + + @Remap(classPath = "net.minecraft.server.network.ServerGamePacketListenerImpl", + name = "send", + type = Remap.Type.METHOD, + remappedName = "a") + public void a(Packet packet) { + + } + + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/EntityHolograms.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/EntityHolograms.java new file mode 100644 index 0000000..e1b7017 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/EntityHolograms.java @@ -0,0 +1,245 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.sounds.SoundEffect; +import net.minecraft.world.EnumHand; +import net.minecraft.world.EnumInteractionResult; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.EnumItemSlot; +import net.minecraft.world.entity.decoration.EntityArmorStand; +import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.World; +import net.minecraft.world.phys.AxisAlignedBB; +import net.minecraft.world.phys.Vec3D; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_19_R1.CraftServer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftArmorStand; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage; + +@SuppressWarnings("unused") +public final class EntityHolograms extends EntityArmorStand implements Hologram { + + private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); + + private CraftEntity bukkitEntity; + + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setInvisible", type = Remap.Type.METHOD, remappedName = "j") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setSmall", type = Remap.Type.METHOD, remappedName = "a") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setShowArms", type = Remap.Type.METHOD, remappedName = "r") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setNoGravity", type = Remap.Type.METHOD, remappedName = "e") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setNoBasePlate", type = Remap.Type.METHOD, remappedName = "s") + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", name = "setMarker", type = Remap.Type.METHOD, remappedName = "t") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setCustomNameVisible", type = Remap.Type.METHOD, remappedName = "n") + @Remap(classPath = "net.minecraft.world.entity.Entity", name = "setBoundingBox", type = Remap.Type.METHOD, remappedName = "a") + public EntityHolograms(World world, double x, double y, double z){ + super(world, x, y, z); + j(true); // Invisible + a(true); // Small + r(false); // Arms + e(true); // No Gravity + s(true); // Base Plate + t(true); // Marker + super.collides = false; + super.n(true); // Custom name visible + super.a(EMPTY_BOUND); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomName", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public void setHologramName(String name) { + super.b(CraftChatMessage.fromStringOrNull(name)); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void removeHologram() { + super.a(RemovalReason.b); + } + + @Override + public org.bukkit.entity.Entity getEntity() { + return getBukkitEntity(); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "tick", + type = Remap.Type.METHOD, + remappedName = "k") + @Override + public void k() { + // Disable normal ticking for this entity. + + // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. + if (this.y) { + this.y = false; + } + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "onGround", + type = Remap.Type.FIELD, + remappedName = "y") + @Override + public void inactiveTick() { + // Disable normal ticking for this entity. + + // Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity. + if (this.y) { + this.y = false; + } + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "addAdditionalSaveData", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public void b(NBTTagCompound nbttagcompound) { + // Do not save NBT. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "saveAsPassenger", + type = Remap.Type.METHOD, + remappedName = "d") + @Override + public boolean d(NBTTagCompound nbttagcompound) { + // Do not save NBT. + return false; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "saveWithoutId", + type = Remap.Type.METHOD, + remappedName = "f") + @Override + public NBTTagCompound f(NBTTagCompound nbttagcompound) { + // Do not save NBT. + return nbttagcompound; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "readAdditionalSaveData", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(NBTTagCompound nbttagcompound) { + // Do not load NBT. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "load", + type = Remap.Type.METHOD, + remappedName = "g") + @Override + public void g(NBTTagCompound nbttagcompound) { + // Do not load NBT. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "isInvulnerableTo", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public boolean b(DamageSource source) { + /* + * The field Entity.invulnerable is private. + * It's only used while saving NBTTags, but since the entity would be killed + * on chunk unload, we prefer to override isInvulnerable(). + */ + return true; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "repositionEntityAfterLoad", + type = Remap.Type.METHOD, + remappedName = "bm") + @Override + public boolean bm() { + return false; + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomName", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public void b(IChatBaseComponent ichatbasecomponent) { + // Locks the custom name. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "setCustomNameVisible", + type = Remap.Type.METHOD, + remappedName = "n") + @Override + public void n(boolean flag) { + // Locks the custom name. + } + + @Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand", + name = "interactAt", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) { + // Prevent stand being equipped + return EnumInteractionResult.d; + } + + @Override + public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean flag) { + // Prevent stand being equipped + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getBoundingBoxForCulling", + type = Remap.Type.METHOD, + remappedName = "cz") + @Override + public AxisAlignedBB cz() { + return EMPTY_BOUND; + } + + public void forceSetBoundingBox(AxisAlignedBB boundingBox) { + super.a(boundingBox); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "playSound", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(SoundEffect soundeffect, float f, float f1) { + // Remove sounds. + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "remove", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a(RemovalReason entity_removalreason) { + // Prevent being killed. + } + + @Override + public CraftEntity getBukkitEntity() { + if (bukkitEntity == null) { + bukkitEntity = new CraftArmorStand((CraftServer) Bukkit.getServer(), this); + } + return bukkitEntity; + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/NMSAdapter.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/NMSAdapter.java new file mode 100644 index 0000000..05c5906 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/NMSAdapter.java @@ -0,0 +1,200 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1; + +import com.bgsoftware.common.reflection.ReflectMethod; +import com.bgsoftware.wildloaders.WildLoadersPlugin; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.loader.TileEntityChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.core.BlockPosition; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.nbt.NBTTagCompound; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.item.ItemStack; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.World; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.block.entity.TileEntity; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.block.state.IBlockData; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.chunk.Chunk; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagLong; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.CraftChunk; +import org.bukkit.craftbukkit.v1_19_R1.CraftServer; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; + +import java.util.UUID; + +@SuppressWarnings("unused") +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { + + private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); + + @Remap(classPath = "net.minecraft.world.level.chunk.LevelChunk", name = "createTicker", type = Remap.Type.METHOD) + private static final ReflectMethod CREATE_TICKING_BLOCK = new ReflectMethod<>( + net.minecraft.world.level.chunk.Chunk.class, "a", + net.minecraft.world.level.block.entity.TileEntity.class, BlockEntityTicker.class); + + @Override + public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getTag(); + + if (tagCompound == null || !tagCompound.contains(key, 8)) + return def; + + return tagCompound.getString(key); + } + + @Override + public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, String value) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + tagCompound.put(key, NBTTagString.a(value)); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public long getTag(org.bukkit.inventory.ItemStack itemStack, String key, long def) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getTag(); + + if (tagCompound == null || !tagCompound.contains(key, 4)) + return def; + + return tagCompound.getLong(key); + } + + @Override + public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack itemStack, String key, long value) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + tagCompound.put(key, NBTTagLong.a(value)); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) { + ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack)); + NBTTagCompound tagCompound = nmsItem.getOrCreateTag(); + + NBTTagCompound skullOwner = tagCompound.contains("SkullOwner") ? + tagCompound.getCompound("SkullOwner") : new NBTTagCompound(); + + NBTTagCompound properties = new NBTTagCompound(); + + NBTTagList textures = new NBTTagList(); + NBTTagCompound signature = new NBTTagCompound(); + signature.putString("Value", texture); + textures.add(signature.getHandle()); + + properties.put("textures", textures); + + skullOwner.put("Properties", properties.getHandle()); + skullOwner.putString("Id", UUID.randomUUID().toString()); + + tagCompound.put("SkullOwner", skullOwner.getHandle()); + + return CraftItemStack.asBukkitCopy(nmsItem.getHandle()); + } + + @Override + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(((CraftServer) Bukkit.getServer()).getServer(), location, uuid); + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) { + Location loaderLoc = chunkLoader.getLocation(); + assert loaderLoc.getWorld() != null; + + World world = new World(((CraftWorld) loaderLoc.getWorld()).getHandle()); + BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); + + TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); + world.addBlockEntityTicker(tileEntityChunkLoader.ticker); + + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = new Chunk(((CraftChunk) bukkitChunk).getHandle()); + chunk.getBlockEntities().values().stream() + .filter(nmsTileEntity -> nmsTileEntity instanceof TileEntityMobSpawner) + .forEach(nmsTileEntity -> { + TileEntity tileEntity = new TileEntity(nmsTileEntity); + tileEntity.getSpawner().m = -1; + }); + + ChunkCoordIntPair chunkCoords = chunk.getPos(); + + world.setChunkForced(chunkCoords.getX(), chunkCoords.getZ(), true); + } + + return tileEntityChunkLoader; + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) { + Location loaderLoc = chunkLoader.getLocation(); + assert loaderLoc.getWorld() != null; + + World world = new World(((CraftWorld) loaderLoc.getWorld()).getHandle()); + BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ()); + + long tileEntityLong = ChunkCoordIntPair.asLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); + TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); + tileEntityChunkLoader.removed = true; + } + + if (spawnParticle) { + world.levelEvent(null, 2001, blockPosition.getHandle(), + IBlockData.getId(world.getBlockStateNoMappings(blockPosition.getHandle()))); + } + + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = new Chunk(((CraftChunk) bukkitChunk).getHandle()); + chunk.getBlockEntities().values().stream() + .filter(nmsTileEntity -> nmsTileEntity instanceof TileEntityMobSpawner) + .forEach(nmsTileEntity -> { + TileEntity tileEntity = new TileEntity(nmsTileEntity); + tileEntity.getSpawner().m = 16; + }); + + ChunkCoordIntPair chunkCoords = chunk.getPos(); + + world.setChunkForced(chunkCoords.getX(), chunkCoords.getZ(), false); + } + } + + @Remap(classPath = "net.minecraft.world.level.BaseSpawner", + name = "requiredPlayerRange", + type = Remap.Type.FIELD, + remappedName = "m") + @Override + public void updateSpawner(Location location, boolean reset) { + assert location.getWorld() != null; + World world = new World(((CraftWorld) location.getWorld()).getHandle()); + + BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ()); + TileEntity mobSpawner = new TileEntity(world.getBlockEntity(blockPosition.getHandle())); + + mobSpawner.getSpawner().m = reset ? 16 : -1; + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoader.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..ca5d648 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoader.java @@ -0,0 +1,161 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.EntityHolograms; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.core.BlockPosition; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.World; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + public final TileEntityChunkLoaderTicker ticker; + public final BlockPosition tilePosition; + private final World world; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntityType", name = "COMMAND_BLOCK", type = Remap.Type.FIELD, remappedName = "v") + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", name = "setLevel", type = Remap.Type.METHOD, remappedName = "a") + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + super(TileEntityTypes.v, blockPosition.getHandle(), world.getBlockStateNoMappings(blockPosition.getHandle())); + + this.chunkLoader = (WChunkLoader) chunkLoader; + this.ticker = new TileEntityChunkLoaderTicker(this); + this.tilePosition = blockPosition; + this.world = world; + + a(world.getHandle()); + + loaderBlock = world.getBlockState(blockPosition.getHandle()).getBlock(); + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(ChunkCoordIntPair.asLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = this.tilePosition.getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world.getHandle(), + this.tilePosition.getX() + 0.5, currentY, this.tilePosition.getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addFreshEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", + name = "getType", + type = Remap.Type.METHOD, + remappedName = "v") + public TileEntityTypes getType() { + return super.v(); + } + + public void tick() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + if (chunkLoader.isNotActive() || this.world.getBlockState(this.tilePosition.getHandle()).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.BlockEntity", + name = "isRemoved", + type = Remap.Type.METHOD, + remappedName = "r") + @Override + public boolean r() { + return isRemoved(); + } + + public boolean isRemoved() { + return removed || super.r(); + } + + private void updateName(EntityHolograms hologram, String line) { + assert chunkLoader.getWhoPlaced().getName() != null; + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} + diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoaderTicker.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoaderTicker.java new file mode 100644 index 0000000..99ded6b --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/loader/TileEntityChunkLoaderTicker.java @@ -0,0 +1,46 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.loader; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntityTypes; + +public record TileEntityChunkLoaderTicker(TileEntityChunkLoader tileEntityChunkLoader) implements TickingBlockEntity { + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "tick", + type = Remap.Type.METHOD, + remappedName = "a") + @Override + public void a() { + tileEntityChunkLoader.tick(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "isRemoved", + type = Remap.Type.METHOD, + remappedName = "b") + @Override + public boolean b() { + return tileEntityChunkLoader.isRemoved(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "getPos", + type = Remap.Type.METHOD, + remappedName = "c") + @Override + public BlockPosition c() { + return tileEntityChunkLoader.tilePosition.getHandle(); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.TickingBlockEntity", + name = "getType", + type = Remap.Type.METHOD, + remappedName = "d") + @Override + public String d() { + return TileEntityTypes.a(tileEntityChunkLoader.getType()) + ""; + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/MappedObject.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/MappedObject.java new file mode 100644 index 0000000..1124457 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/MappedObject.java @@ -0,0 +1,15 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings; + +public abstract class MappedObject { + + protected final E handle; + + protected MappedObject(E handle) { + this.handle = handle; + } + + public E getHandle() { + return handle; + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/core/BlockPosition.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/core/BlockPosition.java new file mode 100644 index 0000000..a4428a9 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/core/BlockPosition.java @@ -0,0 +1,40 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.core; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; + +public class BlockPosition extends MappedObject { + + public BlockPosition(double x, double y, double z) { + this(new net.minecraft.core.BlockPosition(x, y, z)); + } + + public BlockPosition(net.minecraft.core.BlockPosition handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getX", + type = Remap.Type.METHOD, + remappedName = "u") + public int getX() { + return handle.u(); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getY", + type = Remap.Type.METHOD, + remappedName = "v") + public int getY() { + return handle.v(); + } + + @Remap(classPath = "net.minecraft.core.Vec3i", + name = "getZ", + type = Remap.Type.METHOD, + remappedName = "w") + public int getZ() { + return handle.w(); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/nbt/NBTTagCompound.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/nbt/NBTTagCompound.java new file mode 100644 index 0000000..4d79cef --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/nbt/NBTTagCompound.java @@ -0,0 +1,77 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.nbt; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import net.minecraft.nbt.NBTBase; + +public class NBTTagCompound extends MappedObject { + + public static NBTTagCompound ofNullable(net.minecraft.nbt.NBTTagCompound handle) { + return handle == null ? null : new NBTTagCompound(handle); + } + + public NBTTagCompound() { + this(new net.minecraft.nbt.NBTTagCompound()); + } + + public NBTTagCompound(net.minecraft.nbt.NBTTagCompound handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "contains", + type = Remap.Type.METHOD, + remappedName = "b") + public boolean contains(String key, int type) { + return handle.b(key, type); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getString", + type = Remap.Type.METHOD, + remappedName = "l") + public String getString(String key) { + return handle.l(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "put", + type = Remap.Type.METHOD, + remappedName = "a") + public void put(String key, NBTBase nbtBase) { + handle.a(key, nbtBase); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getLong", + type = Remap.Type.METHOD, + remappedName = "i") + public long getLong(String key) { + return handle.i(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "contains", + type = Remap.Type.METHOD, + remappedName = "e") + public boolean contains(String key) { + return handle.e(key); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "getCompound", + type = Remap.Type.METHOD, + remappedName = "p") + public NBTTagCompound getCompound(String key) { + return new NBTTagCompound(handle.p(key)); + } + + @Remap(classPath = "net.minecraft.nbt.CompoundTag", + name = "putString", + type = Remap.Type.METHOD, + remappedName = "a") + public void putString(String key, String value) { + handle.a(key, value); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/entity/Entity.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/entity/Entity.java new file mode 100644 index 0000000..d99ae30 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/entity/Entity.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.entity; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.World; + +public class Entity extends MappedObject { + + public Entity(net.minecraft.world.entity.Entity handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "getLevel", + type = Remap.Type.METHOD, + remappedName = "W") + public World getWorld() { + return new World(handle.W()); + } + + @Remap(classPath = "net.minecraft.world.entity.Entity", + name = "moveTo", + type = Remap.Type.METHOD, + remappedName = "b") + public void moveTo(double x, double y, double z, float yaw, float pitch) { + handle.b(x, y, z, yaw, pitch); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/item/ItemStack.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/item/ItemStack.java new file mode 100644 index 0000000..a06146c --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/item/ItemStack.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.item; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.nbt.NBTTagCompound; + +public class ItemStack extends MappedObject { + + public ItemStack(net.minecraft.world.item.ItemStack handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.item.ItemStack", + name = "getOrCreateTag", + type = Remap.Type.METHOD, + remappedName = "v") + public NBTTagCompound getOrCreateTag() { + return new NBTTagCompound(handle.v()); + } + + @Remap(classPath = "net.minecraft.world.item.ItemStack", + name = "getTag", + type = Remap.Type.METHOD, + remappedName = "u") + public NBTTagCompound getTag() { + return NBTTagCompound.ofNullable(handle.u()); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java new file mode 100644 index 0000000..5129405 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/ChunkCoordIntPair.java @@ -0,0 +1,36 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; + +public class ChunkCoordIntPair extends MappedObject { + + public ChunkCoordIntPair(net.minecraft.world.level.ChunkCoordIntPair handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "x", + type = Remap.Type.FIELD, + remappedName = "e") + public int getX() { + return handle.e; + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "z", + type = Remap.Type.FIELD, + remappedName = "f") + public int getZ() { + return handle.f; + } + + @Remap(classPath = "net.minecraft.world.level.ChunkPos", + name = "asLong", + type = Remap.Type.METHOD, + remappedName = "c") + public static long asLong(int x, int z) { + return net.minecraft.world.level.ChunkCoordIntPair.c(x, z); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/World.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/World.java new file mode 100644 index 0000000..269b705 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/World.java @@ -0,0 +1,87 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.core.BlockPosition; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.entity.TickingBlockEntity; +import net.minecraft.world.level.block.entity.TileEntity; + +public class World extends MappedObject { + + public World(net.minecraft.world.level.World handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "setChunkForced", + type = Remap.Type.METHOD, + remappedName = "a") + public void setChunkForced(int chunkX, int chunkZ, boolean load) { + ((WorldServer) handle).a(chunkX, chunkZ, load); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "addNewPlayer", + type = Remap.Type.METHOD, + remappedName = "c") + public void addNewPlayer(EntityPlayer entityPlayer) { + ((WorldServer) handle).c(entityPlayer); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "removePlayerImmediately", + type = Remap.Type.METHOD, + remappedName = "a") + public void removePlayer(EntityPlayer entityPlayer, Entity.RemovalReason removalReason) { + ((WorldServer) handle).a(entityPlayer, removalReason); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "getBlockState", + type = Remap.Type.METHOD, + remappedName = "a_") + public net.minecraft.world.level.block.state.IBlockData getBlockStateNoMappings(BlockPosition blockPosition) { + return handle.a_(blockPosition); + } + + public IBlockData getBlockState(BlockPosition blockPosition) { + return new IBlockData(getBlockStateNoMappings(blockPosition)); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "getBlockEntity", + type = Remap.Type.METHOD, + remappedName = "c_") + public TileEntity getBlockEntity(BlockPosition blockPosition) { + return handle.c_(blockPosition); + } + + @Remap(classPath = "net.minecraft.world.level.LevelWriter", + name = "addFreshEntity", + type = Remap.Type.METHOD, + remappedName = "b") + public void addFreshEntity(Entity entity) { + handle.b(entity); + } + + @Remap(classPath = "net.minecraft.world.level.Level", + name = "addBlockEntityTicker", + type = Remap.Type.METHOD, + remappedName = "a") + public void addBlockEntityTicker(TickingBlockEntity blockEntityTicker) { + handle.a(blockEntityTicker); + } + + @Remap(classPath = "net.minecraft.server.level.ServerLevel", + name = "levelEvent", + type = Remap.Type.METHOD, + remappedName = "a") + public void levelEvent(EntityPlayer entityPlayer, int i, BlockPosition blockPosition, int j) { + handle.a(entityPlayer, i, blockPosition, j); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java new file mode 100644 index 0000000..c9f84c2 --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/entity/TileEntity.java @@ -0,0 +1,22 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.block.entity; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import net.minecraft.world.level.MobSpawnerAbstract; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; + +public class TileEntity extends MappedObject { + + public TileEntity(net.minecraft.world.level.block.entity.TileEntity handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.block.entity.SpawnerBlockEntity", + name = "getSpawner", + type = Remap.Type.METHOD, + remappedName = "d") + public MobSpawnerAbstract getSpawner() { + return ((TileEntityMobSpawner) handle).d(); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java new file mode 100644 index 0000000..be05d9c --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/block/state/IBlockData.java @@ -0,0 +1,29 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.block.state; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import net.minecraft.world.level.block.Block; + +public class IBlockData extends MappedObject { + + public IBlockData(net.minecraft.world.level.block.state.IBlockData handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase", + name = "getBlock", + type = Remap.Type.METHOD, + remappedName = "b") + public Block getBlock() { + return handle.b(); + } + + @Remap(classPath = "net.minecraft.world.level.block.Block", + name = "getId", + type = Remap.Type.METHOD, + remappedName = "i") + public static int getId(net.minecraft.world.level.block.state.IBlockData blockData) { + return Block.i(blockData); + } + +} diff --git a/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/chunk/Chunk.java b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/chunk/Chunk.java new file mode 100644 index 0000000..3d66eab --- /dev/null +++ b/v1_19_R1/src/main/java/com/bgsoftware/wildloaders/nms/v1_19_R1/mappings/net/minecraft/world/level/chunk/Chunk.java @@ -0,0 +1,33 @@ +package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.chunk; + +import com.bgsoftware.wildloaders.nms.mapping.Remap; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.MappedObject; +import com.bgsoftware.wildloaders.nms.v1_19_R1.mappings.net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TileEntity; + +import java.util.Map; + +public class Chunk extends MappedObject { + + public Chunk(net.minecraft.world.level.chunk.Chunk handle) { + super(handle); + } + + @Remap(classPath = "net.minecraft.world.level.chunk.LevelChunk", + name = "getBlockEntities", + type = Remap.Type.METHOD, + remappedName = "E") + public Map getBlockEntities() { + return handle.E(); + } + + @Remap(classPath = "net.minecraft.world.level.chunk.ChunkAccess", + name = "getPos", + type = Remap.Type.METHOD, + remappedName = "f") + public ChunkCoordIntPair getPos() { + return new ChunkCoordIntPair(handle.f()); + } + +} diff --git a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_7_R4.java b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/ChunkLoaderNPC.java similarity index 94% rename from v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_7_R4.java rename to v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/ChunkLoaderNPC.java index e04338c..c465bf6 100644 --- a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_7_R4.java +++ b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/ChunkLoaderNPC.java @@ -1,6 +1,5 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_7_R4; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.handlers.NPCHandler; import com.bgsoftware.wildloaders.npc.DummyChannel; import net.minecraft.server.v1_7_R4.DamageSource; @@ -30,9 +29,9 @@ import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.util.UUID; -public final class ChunkLoaderNPC_v1_7_R4 extends EntityPlayer implements ChunkLoaderNPC { +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { - public ChunkLoaderNPC_v1_7_R4(Location location, UUID uuid) { + public ChunkLoaderNPC(Location location, UUID uuid) { super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(), new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())), diff --git a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/NMSAdapter.java similarity index 74% rename from v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java rename to v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/NMSAdapter.java index 370a428..068effe 100644 --- a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java +++ b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/NMSAdapter.java @@ -1,14 +1,11 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_7_R4; import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_7_R4.loader.TileEntityChunkLoader; import net.minecraft.server.v1_7_R4.Block; import net.minecraft.server.v1_7_R4.Chunk; -import net.minecraft.server.v1_7_R4.IUpdatePlayerListBox; import net.minecraft.server.v1_7_R4.ItemStack; import net.minecraft.server.v1_7_R4.NBTTagCompound; import net.minecraft.server.v1_7_R4.NBTTagList; @@ -23,14 +20,10 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_7_R4.util.LongHash; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; @SuppressWarnings("unused") -public final class NMSAdapter_v1_7_R4 implements NMSAdapter { +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); @@ -39,7 +32,7 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); - if(!tagCompound.hasKeyOfType(key, 8)) + if (!tagCompound.hasKeyOfType(key, 8)) return def; return tagCompound.getString(key); @@ -62,7 +55,7 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); - if(!tagCompound.hasKeyOfType(key, 4)) + if (!tagCompound.hasKeyOfType(key, 4)) return def; return tagCompound.getLong(key); @@ -108,8 +101,8 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { } @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_7_R4(location, uuid); + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(location, uuid); } @Override @@ -122,7 +115,7 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { //noinspection unchecked world.tileEntityList.add(tileEntityChunkLoader); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); //noinspection unchecked chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { @@ -144,15 +137,15 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { long tileEntityLong = LongHash.toLong(x >> 4, z >> 4); TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { + if (tileEntityChunkLoader != null) { tileEntityChunkLoader.removed = true; world.tileEntityList.remove(tileEntityChunkLoader); } - if(spawnParticle) + if (spawnParticle) world.a(null, 2001, x, y, z, Block.getId(world.getType(x, y, z)) + (world.getData(x, y, z) << 12)); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); //noinspection unchecked chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { @@ -177,51 +170,4 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { mobSpawner.a(nbtTagCompound); } - private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader { - - private static final Collection EMPTY_CONTAINER = Collections.emptyList(); - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - - private short currentTick = 20; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, int x, int y, int z){ - this.chunkLoader = (WChunkLoader) chunkLoader; - - this.x = x; - this.y = y; - this.z = z; - a(world); - - loaderBlock = world.getType(x, y, z); - - tileEntityChunkLoaderMap.put(LongHash.toLong(x >> 4, z >> 4), this); - } - - @Override - public void a() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - if(chunkLoader.isNotActive() || world.getType(x, y, z) != loaderBlock){ - chunkLoader.remove(); - return; - } - - chunkLoader.tick(); - } - - @Override - public Collection getHolograms() { - return EMPTY_CONTAINER; - } - - } - } diff --git a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/loader/TileEntityChunkLoader.java b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..62d4b17 --- /dev/null +++ b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/v1_7_R4/loader/TileEntityChunkLoader.java @@ -0,0 +1,63 @@ +package com.bgsoftware.wildloaders.nms.v1_7_R4.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import net.minecraft.server.v1_7_R4.Block; +import net.minecraft.server.v1_7_R4.IUpdatePlayerListBox; +import net.minecraft.server.v1_7_R4.TileEntity; +import net.minecraft.server.v1_7_R4.World; +import org.bukkit.craftbukkit.v1_7_R4.util.LongHash; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader { + + private static final Collection EMPTY_CONTAINER = Collections.emptyList(); + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + + private short currentTick = 20; + public boolean removed = false; + + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, int x, int y, int z) { + this.chunkLoader = (WChunkLoader) chunkLoader; + + this.x = x; + this.y = y; + this.z = z; + a(world); + + loaderBlock = world.getType(x, y, z); + + tileEntityChunkLoaderMap.put(LongHash.toLong(x >> 4, z >> 4), this); + } + + @Override + public void a() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + if (chunkLoader.isNotActive() || world.getType(x, y, z) != loaderBlock) { + chunkLoader.remove(); + return; + } + + chunkLoader.tick(); + } + + @Override + public Collection getHolograms() { + return EMPTY_CONTAINER; + } + +} diff --git a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_8_R3.java b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/ChunkLoaderNPC.java similarity index 95% rename from v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_8_R3.java rename to v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/ChunkLoaderNPC.java index 9bc705d..05ddfe3 100644 --- a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/ChunkLoaderNPC_v1_8_R3.java +++ b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/ChunkLoaderNPC.java @@ -1,6 +1,5 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_8_R3; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.handlers.NPCHandler; import com.bgsoftware.wildloaders.npc.DummyChannel; import com.mojang.authlib.GameProfile; @@ -32,11 +31,11 @@ import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.util.UUID; -public final class ChunkLoaderNPC_v1_8_R3 extends EntityPlayer implements ChunkLoaderNPC { +public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC { private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D); - public ChunkLoaderNPC_v1_8_R3(Location location, UUID uuid) { + public ChunkLoaderNPC(Location location, UUID uuid) { super(((CraftServer) Bukkit.getServer()).getServer(), ((CraftWorld) location.getWorld()).getHandle(), new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())), diff --git a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_8_R3.java b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/EntityHolograms.java similarity index 94% rename from v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_8_R3.java rename to v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/EntityHolograms.java index 7337abb..8382d7e 100644 --- a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/EntityHolograms_v1_8_R3.java +++ b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/EntityHolograms.java @@ -1,4 +1,4 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_8_R3; import com.bgsoftware.wildloaders.api.holograms.Hologram; import net.minecraft.server.v1_8_R3.AxisAlignedBB; @@ -14,9 +14,9 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.entity.Entity; @SuppressWarnings("unused") -public final class EntityHolograms_v1_8_R3 extends EntityArmorStand implements Hologram { +public final class EntityHolograms extends EntityArmorStand implements Hologram { - EntityHolograms_v1_8_R3(World world, double x, double y, double z){ + public EntityHolograms(World world, double x, double y, double z) { super(world, x, y, z); setInvisible(true); setSmall(true); diff --git a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/NMSAdapter.java similarity index 57% rename from v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java rename to v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/NMSAdapter.java index b8f2214..a985c8c 100644 --- a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java +++ b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/NMSAdapter.java @@ -1,21 +1,17 @@ -package com.bgsoftware.wildloaders.nms; +package com.bgsoftware.wildloaders.nms.v1_8_R3; import com.bgsoftware.wildloaders.WildLoadersPlugin; -import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; -import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; -import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_8_R3.loader.TileEntityChunkLoader; import net.minecraft.server.v1_8_R3.Block; import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.Chunk; -import net.minecraft.server.v1_8_R3.IUpdatePlayerListBox; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.NBTTagList; import net.minecraft.server.v1_8_R3.NBTTagLong; import net.minecraft.server.v1_8_R3.NBTTagString; -import net.minecraft.server.v1_8_R3.TileEntity; import net.minecraft.server.v1_8_R3.TileEntityMobSpawner; import net.minecraft.server.v1_8_R3.World; import org.bukkit.Location; @@ -24,16 +20,10 @@ import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.UUID; @SuppressWarnings("unused") -public final class NMSAdapter_v1_8_R3 implements NMSAdapter { +public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapter { private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); @@ -42,7 +32,7 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); - if(!tagCompound.hasKeyOfType(key, 8)) + if (!tagCompound.hasKeyOfType(key, 8)) return def; return tagCompound.getString(key); @@ -65,7 +55,7 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound tagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); - if(!tagCompound.hasKeyOfType(key, 4)) + if (!tagCompound.hasKeyOfType(key, 4)) return def; return tagCompound.getLong(key); @@ -111,8 +101,8 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { } @Override - public ChunkLoaderNPC createNPC(Location location, UUID uuid) { - return new ChunkLoaderNPC_v1_8_R3(location, uuid); + public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) { + return new ChunkLoaderNPC(location, uuid); } @Override @@ -124,7 +114,7 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityList.add(tileEntityChunkLoader); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { NBTTagCompound nbtTagCompound = new NBTTagCompound(); @@ -145,16 +135,16 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4); TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong); - if(tileEntityChunkLoader != null) { - tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R3::removeHologram); + if (tileEntityChunkLoader != null) { + tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram); tileEntityChunkLoader.removed = true; world.tileEntityList.remove(tileEntityChunkLoader); } - if(spawnParticle) + if (spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { NBTTagCompound nbtTagCompound = new NBTTagCompound(); @@ -178,112 +168,4 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { mobSpawner.a(nbtTagCompound); } - private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader { - - private static final Map tileEntityChunkLoaderMap = new HashMap<>(); - - private final List holograms = new ArrayList<>(); - private final WChunkLoader chunkLoader; - private final Block loaderBlock; - - private short currentTick = 20; - private short daysAmount, hoursAmount, minutesAmount, secondsAmount; - private boolean removed = false; - - TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition){ - this.chunkLoader = (WChunkLoader) chunkLoader; - - a(blockPosition); - a(world); - - loaderBlock = world.getType(blockPosition).getBlock(); - - if(!this.chunkLoader.isInfinite()) { - long timeLeft = chunkLoader.getTimeLeft(); - - daysAmount = (short) (timeLeft / 86400); - timeLeft = timeLeft % 86400; - - hoursAmount = (short) (timeLeft / 3600); - timeLeft = timeLeft % 3600; - - minutesAmount = (short) (timeLeft / 60); - timeLeft = timeLeft % 60; - - secondsAmount = (short) timeLeft; - } - - tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); - - List hologramLines = this.chunkLoader.getHologramLines(); - - double currentY = position.getY() + 1; - for(int i = hologramLines.size(); i > 0; i--){ - EntityHolograms_v1_8_R3 hologram = new EntityHolograms_v1_8_R3(world, position.getX() + 0.5, currentY, position.getZ() + 0.5); - updateName(hologram, hologramLines.get(i - 1)); - world.addEntity(hologram); - currentY += 0.23; - holograms.add(hologram); - } - } - - @Override - public void c() { - if(removed || ++currentTick <= 20) - return; - - currentTick = 0; - - if(chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock){ - chunkLoader.remove(); - return; - } - - if(chunkLoader.isInfinite()) - return; - - List hologramLines = chunkLoader.getHologramLines(); - - int hologramsAmount = holograms.size(); - for (int i = hologramsAmount; i > 0; i--) { - EntityHolograms_v1_8_R3 hologram = holograms.get(hologramsAmount - i); - updateName(hologram, hologramLines.get(i - 1)); - } - - chunkLoader.tick(); - - if(!removed) { - secondsAmount--; - if (secondsAmount < 0) { - secondsAmount = 59; - minutesAmount--; - if (minutesAmount < 0) { - minutesAmount = 59; - hoursAmount--; - if (hoursAmount < 0) { - hoursAmount = 23; - daysAmount--; - } - } - } - } - } - - @Override - public Collection getHolograms() { - return Collections.unmodifiableList(holograms); - } - - private void updateName(EntityHolograms_v1_8_R3 hologram, String line){ - hologram.setHologramName(line - .replace("{0}", chunkLoader.getWhoPlaced().getName()) - .replace("{1}", daysAmount + "") - .replace("{2}", hoursAmount + "") - .replace("{3}", minutesAmount + "") - .replace("{4}", secondsAmount + "") - ); - } - - } - } diff --git a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/loader/TileEntityChunkLoader.java b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/loader/TileEntityChunkLoader.java new file mode 100644 index 0000000..bfb6751 --- /dev/null +++ b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/v1_8_R3/loader/TileEntityChunkLoader.java @@ -0,0 +1,129 @@ +package com.bgsoftware.wildloaders.nms.v1_8_R3.loader; + +import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; +import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader; +import com.bgsoftware.wildloaders.loaders.WChunkLoader; +import com.bgsoftware.wildloaders.nms.v1_8_R3.EntityHolograms; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.IUpdatePlayerListBox; +import net.minecraft.server.v1_8_R3.TileEntity; +import net.minecraft.server.v1_8_R3.World; +import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader { + + public static final Map tileEntityChunkLoaderMap = new HashMap<>(); + + public final List holograms = new ArrayList<>(); + private final WChunkLoader chunkLoader; + private final Block loaderBlock; + + private short currentTick = 20; + private short daysAmount, hoursAmount, minutesAmount, secondsAmount; + public boolean removed = false; + + public TileEntityChunkLoader(ChunkLoader chunkLoader, World world, BlockPosition blockPosition) { + this.chunkLoader = (WChunkLoader) chunkLoader; + + a(blockPosition); + a(world); + + loaderBlock = world.getType(blockPosition).getBlock(); + + if (!this.chunkLoader.isInfinite()) { + long timeLeft = chunkLoader.getTimeLeft(); + + daysAmount = (short) (timeLeft / 86400); + timeLeft = timeLeft % 86400; + + hoursAmount = (short) (timeLeft / 3600); + timeLeft = timeLeft % 3600; + + minutesAmount = (short) (timeLeft / 60); + timeLeft = timeLeft % 60; + + secondsAmount = (short) timeLeft; + } + + tileEntityChunkLoaderMap.put(LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4), this); + + List hologramLines = this.chunkLoader.getHologramLines(); + + double currentY = position.getY() + 1; + for (int i = hologramLines.size(); i > 0; i--) { + EntityHolograms hologram = new EntityHolograms(world, position.getX() + 0.5, currentY, position.getZ() + 0.5); + updateName(hologram, hologramLines.get(i - 1)); + world.addEntity(hologram); + currentY += 0.23; + holograms.add(hologram); + } + } + + @Override + public void c() { + if (removed || ++currentTick <= 20) + return; + + currentTick = 0; + + if (chunkLoader.isNotActive() || world.getType(position).getBlock() != loaderBlock) { + chunkLoader.remove(); + return; + } + + if (chunkLoader.isInfinite()) + return; + + List hologramLines = chunkLoader.getHologramLines(); + + int hologramsAmount = holograms.size(); + for (int i = hologramsAmount; i > 0; i--) { + EntityHolograms hologram = holograms.get(hologramsAmount - i); + updateName(hologram, hologramLines.get(i - 1)); + } + + chunkLoader.tick(); + + if (!removed) { + secondsAmount--; + if (secondsAmount < 0) { + secondsAmount = 59; + minutesAmount--; + if (minutesAmount < 0) { + minutesAmount = 59; + hoursAmount--; + if (hoursAmount < 0) { + hoursAmount = 23; + daysAmount--; + } + } + } + } + } + + @Override + public Collection getHolograms() { + return Collections.unmodifiableList(holograms); + } + + private void updateName(EntityHolograms hologram, String line) { + hologram.setHologramName(line + .replace("{0}", chunkLoader.getWhoPlaced().getName()) + .replace("{1}", daysAmount + "") + .replace("{2}", hoursAmount + "") + .replace("{3}", minutesAmount + "") + .replace("{4}", secondsAmount + "") + ); + } + +} +