mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2024-12-21 16:38:42 +01:00
Removed support to 1.20-1.20.3
This commit is contained in:
parent
a01ad50d4e
commit
eeb2f4957c
@ -1,36 +0,0 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1"
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
group 'NMS:v1_20_1'
|
||||
|
||||
dependencies {
|
||||
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = "${project.name}-exclude.jar"
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
tasks {
|
||||
reobfJar {
|
||||
File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar")
|
||||
outputJar.set(layout.buildDirectory.file(outputFile.getPath()))
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('nms.compile_v1_20') && !Boolean.valueOf(project.findProperty("nms.compile_v1_20").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -1,247 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_1;
|
||||
|
||||
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;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.ServerAdvancementManager;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoaderNPC {
|
||||
|
||||
private static final ReflectMethod<Void> SET_GAMEMODE = new ReflectMethod<>(ServerPlayerGameMode.class,
|
||||
1, GameType.class, GameType.class);
|
||||
|
||||
private final ServerLevel serverLevel;
|
||||
private final AABB boundingBox;
|
||||
private final PlayerAdvancements advancements;
|
||||
|
||||
private boolean dieCall = false;
|
||||
|
||||
public ChunkLoaderNPCImpl(MinecraftServer minecraftServer, Location location, UUID uuid) {
|
||||
super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(),
|
||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())));
|
||||
|
||||
this.serverLevel = serverLevel();
|
||||
this.boundingBox = new AABB(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
|
||||
this.connection = new DummyServerGamePacketListenerImpl(minecraftServer, this);
|
||||
|
||||
this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
|
||||
|
||||
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
clientViewDistance = 0;
|
||||
|
||||
try {
|
||||
// Paper
|
||||
setLoadViewDistance(2);
|
||||
setTickViewDistance(2);
|
||||
setSendViewDistance(2);
|
||||
affectsSpawning = true;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
spawnIn(this.serverLevel);
|
||||
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
||||
this.serverLevel.addNewPlayer(this);
|
||||
|
||||
super.setBoundingBox(this.boundingBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return super.getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling() {
|
||||
return this.boundingBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(RemovalReason removalReason) {
|
||||
if (!dieCall) {
|
||||
dieCall = true;
|
||||
this.serverLevel.removePlayerImmediately(this, RemovalReason.UNLOADED_WITH_PLAYER);
|
||||
dieCall = false;
|
||||
} else {
|
||||
super.remove(removalReason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerAdvancements getAdvancements() {
|
||||
return this.advancements;
|
||||
}
|
||||
|
||||
public static class DummyConnection extends Connection {
|
||||
|
||||
DummyConnection() {
|
||||
super(PacketFlow.SERVERBOUND);
|
||||
this.channel = new DummyChannel();
|
||||
this.address = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DummyServerGamePacketListenerImpl extends ServerGamePacketListenerImpl {
|
||||
|
||||
DummyServerGamePacketListenerImpl(MinecraftServer minecraftServer, ServerPlayer serverPlayer) {
|
||||
super(minecraftServer, new DummyConnection(), serverPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleContainerClick(ServerboundContainerClickPacket containerClickPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMovePlayer(ServerboundMovePlayerPacket movePlayerPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSignUpdate(ServerboundSignUpdatePacket signUpdatePacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePlayerAction(ServerboundPlayerActionPacket playerActionPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUseItem(ServerboundUseItemPacket useItemPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket setCarriedItemPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChat(ServerboundChatPacket chatPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String s) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public void send(Packet<?> packet) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class DummyPlayerAdvancements extends PlayerAdvancements {
|
||||
|
||||
DummyPlayerAdvancements(MinecraftServer server, ServerPlayer serverPlayer) {
|
||||
super(server.getFixerUpper(), server.getPlayerList(), server.getAdvancements(),
|
||||
getAdvancementsFile(server, serverPlayer), serverPlayer);
|
||||
}
|
||||
|
||||
private static Path getAdvancementsFile(MinecraftServer server, ServerPlayer serverPlayer) {
|
||||
File advancementsDir = server.getWorldPath(LevelResource.PLAYER_ADVANCEMENTS_DIR).toFile();
|
||||
return new File(advancementsDir, serverPlayer.getUUID() + ".json").toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(ServerPlayer owner) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListening() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(ServerAdvancementManager advancementLoader) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean award(Advancement advancement, String criterionName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revoke(Advancement advancement, String criterionName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushDirty(ServerPlayer player) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedTab(@Nullable Advancement advancement) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdvancementProgress getOrStartProgress(Advancement advancement) {
|
||||
return new AdvancementProgress();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_1;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftArmorStand;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.util.CraftChatMessage;
|
||||
|
||||
public final class EntityHologram extends ArmorStand implements Hologram {
|
||||
|
||||
private static final AABB EMPTY_BOUND = new AABB(0D, 0D, 0D, 0D, 0D, 0D);
|
||||
|
||||
private CraftEntity bukkitEntity;
|
||||
|
||||
public EntityHologram(ServerLevel serverLevel, double x, double y, double z) {
|
||||
super(serverLevel, x, y, z);
|
||||
|
||||
setInvisible(true);
|
||||
setSmall(true);
|
||||
setShowArms(false);
|
||||
setNoGravity(true);
|
||||
setNoBasePlate(true);
|
||||
setMarker(true);
|
||||
|
||||
super.collides = false;
|
||||
super.setCustomNameVisible(true); // Custom name visible
|
||||
super.setBoundingBox(EMPTY_BOUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHologramName(String name) {
|
||||
super.setCustomName(CraftChatMessage.fromStringOrNull(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHologram() {
|
||||
super.remove(RemovalReason.DISCARDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getEntity() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = 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.onGround) {
|
||||
this.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdditionalSaveData(CompoundTag compoundTag) {
|
||||
// Do not save NBT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveAsPassenger(CompoundTag compoundTag) {
|
||||
// Do not save NBT.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag saveWithoutId(CompoundTag compoundTag) {
|
||||
// Do not save NBT.
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag compoundTag) {
|
||||
// Do not load NBT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag compoundTag) {
|
||||
// Do not load NBT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerableTo(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 repositionEntityAfterLoad() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(Component component) {
|
||||
// Locks the custom name.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomNameVisible(boolean visible) {
|
||||
// Locks the custom name.
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult interactAt(Player player, Vec3 hitPos, InteractionHand hand) {
|
||||
// Prevent stand being equipped
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemSlot(EquipmentSlot equipmentSlot, ItemStack itemStack, boolean silent) {
|
||||
// Prevent stand being equipped
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling() {
|
||||
return EMPTY_BOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(SoundEvent soundEvent, float volume, float pitch) {
|
||||
// Remove sounds.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(RemovalReason removalReason) {
|
||||
// Prevent being killed.
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null) {
|
||||
bukkitEntity = new CraftArmorStand((CraftServer) Bukkit.getServer(), this);
|
||||
}
|
||||
return bukkitEntity;
|
||||
}
|
||||
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_1;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
||||
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_20_1.loader.ChunkLoaderBlockEntity;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class NMSAdapterImpl implements NMSAdapter {
|
||||
|
||||
@Override
|
||||
public String getTag(org.bukkit.inventory.ItemStack bukkitItem, String key, String def) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getTag();
|
||||
return compoundTag == null || !compoundTag.contains(key, 8) ? def : compoundTag.getString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack bukkitItem, String key, String value) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
|
||||
compoundTag.putString(key, value);
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTag(org.bukkit.inventory.ItemStack bukkitItem, String key, long def) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getTag();
|
||||
return compoundTag == null || !compoundTag.contains(key, 4) ? def : compoundTag.getLong(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack bukkitItem, String key, long value) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
|
||||
compoundTag.putLong(key, value);
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack bukkitItem, String texture) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
|
||||
CompoundTag skullOwner = compoundTag.contains("SkullOwner") ?
|
||||
compoundTag.getCompound("SkullOwner") : new CompoundTag();
|
||||
|
||||
CompoundTag properties = new CompoundTag();
|
||||
ListTag textures = new ListTag();
|
||||
CompoundTag signature = new CompoundTag();
|
||||
|
||||
signature.putString("Value", texture);
|
||||
textures.add(signature);
|
||||
|
||||
properties.put("textures", textures);
|
||||
|
||||
skullOwner.put("Properties", properties);
|
||||
skullOwner.putString("Id", UUID.randomUUID().toString());
|
||||
|
||||
compoundTag.put("SkullOwner", skullOwner);
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||
return new ChunkLoaderNPCImpl(((CraftServer) Bukkit.getServer()).getServer(), location, uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
|
||||
Location loaderLoc = chunkLoader.getLocation();
|
||||
World bukkitWorld = loaderLoc.getWorld();
|
||||
|
||||
if (bukkitWorld == null)
|
||||
throw new IllegalArgumentException("Cannot create loader in null world.");
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
||||
BlockPos blockPos = new BlockPos(loaderLoc.getBlockX(), loaderLoc.getBlockY(), loaderLoc.getBlockZ());
|
||||
|
||||
ChunkLoaderBlockEntity ChunkLoaderBlockEntity = new ChunkLoaderBlockEntity(chunkLoader, serverLevel, blockPos);
|
||||
serverLevel.addBlockEntityTicker(ChunkLoaderBlockEntity.getTicker());
|
||||
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, true));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, true);
|
||||
}
|
||||
|
||||
return ChunkLoaderBlockEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
|
||||
Location loaderLoc = chunkLoader.getLocation();
|
||||
World bukkitWorld = loaderLoc.getWorld();
|
||||
|
||||
if (bukkitWorld == null)
|
||||
throw new IllegalArgumentException("Cannot remove loader in null world.");
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
||||
BlockPos blockPos = new BlockPos(loaderLoc.getBlockX(), loaderLoc.getBlockY(), loaderLoc.getBlockZ());
|
||||
|
||||
long chunkPosLong = ChunkPos.asLong(blockPos.getX() >> 4, blockPos.getZ() >> 4);
|
||||
ChunkLoaderBlockEntity chunkLoaderBlockEntity = ChunkLoaderBlockEntity.chunkLoaderBlockEntityMap.remove(chunkPosLong);
|
||||
|
||||
if (chunkLoaderBlockEntity != null) {
|
||||
chunkLoaderBlockEntity.holograms.forEach(EntityHologram::removeHologram);
|
||||
chunkLoaderBlockEntity.removed = true;
|
||||
}
|
||||
|
||||
if (spawnParticle)
|
||||
serverLevel.levelEvent(null, 2001, blockPos, Block.getId(serverLevel.getBlockState(blockPos)));
|
||||
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, false));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setChunksForcedForLoader(ChunkLoader chunkLoader, ServerLevel serverLevel, boolean forced) {
|
||||
int requiredPlayerRange = forced ? -1 : 16;
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
LevelChunk levelChunk = serverLevel.getChunk(bukkitChunk.getX(), bukkitChunk.getZ());
|
||||
|
||||
for (BlockEntity blockEntity : levelChunk.getBlockEntities().values()) {
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = requiredPlayerRange;
|
||||
}
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, forced);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSpawner(Location location, boolean reset) {
|
||||
World bukkitWorld = location.getWorld();
|
||||
|
||||
if (bukkitWorld == null)
|
||||
throw new IllegalArgumentException("Cannot remove loader in null world.");
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
||||
BlockPos blockPos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockEntity blockEntity = serverLevel.getBlockEntity(blockPos);
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = reset ? 16 : -1;
|
||||
}
|
||||
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_1.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_20_1.EntityHologram;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
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.Optional;
|
||||
|
||||
public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEntityChunkLoader {
|
||||
|
||||
public static final Map<Long, ChunkLoaderBlockEntity> chunkLoaderBlockEntityMap = new HashMap<>();
|
||||
|
||||
public final List<EntityHologram> holograms = new ArrayList<>();
|
||||
private final WChunkLoader chunkLoader;
|
||||
private final Block loaderBlock;
|
||||
private final ChunkLoaderBlockEntityTicker ticker;
|
||||
private final ServerLevel serverLevel;
|
||||
private final BlockPos blockPos;
|
||||
private final String cachedPlacerName;
|
||||
|
||||
private short currentTick = 20;
|
||||
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
|
||||
public boolean removed = false;
|
||||
|
||||
public ChunkLoaderBlockEntity(ChunkLoader chunkLoader, ServerLevel serverLevel, BlockPos blockPos) {
|
||||
super(BlockEntityType.COMMAND_BLOCK, blockPos, serverLevel.getBlockState(blockPos));
|
||||
|
||||
this.chunkLoader = (WChunkLoader) chunkLoader;
|
||||
this.ticker = new ChunkLoaderBlockEntityTicker(this);
|
||||
this.blockPos = blockPos;
|
||||
this.serverLevel = serverLevel;
|
||||
|
||||
setLevel(serverLevel);
|
||||
|
||||
loaderBlock = serverLevel.getBlockState(blockPos).getBlock();
|
||||
|
||||
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
long chunkPosLong = ChunkPos.asLong(blockPos.getX() >> 4, blockPos.getZ() >> 4);
|
||||
chunkLoaderBlockEntityMap.put(chunkPosLong, this);
|
||||
|
||||
List<String> hologramLines = this.chunkLoader.getHologramLines();
|
||||
|
||||
double currentY = blockPos.getY() + 1;
|
||||
for (int i = hologramLines.size(); i > 0; i--) {
|
||||
EntityHologram hologram = new EntityHologram(serverLevel, blockPos.getX() + 0.5, currentY, blockPos.getZ() + 0.5);
|
||||
updateName(hologram, hologramLines.get(i - 1));
|
||||
serverLevel.addFreshEntity(hologram);
|
||||
currentY += 0.23;
|
||||
holograms.add(hologram);
|
||||
}
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if (removed || ++currentTick <= 20)
|
||||
return;
|
||||
|
||||
currentTick = 0;
|
||||
|
||||
if (chunkLoader.isNotActive() || this.serverLevel.getBlockState(this.blockPos).getBlock() != loaderBlock) {
|
||||
chunkLoader.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunkLoader.isInfinite())
|
||||
return;
|
||||
|
||||
List<String> hologramLines = chunkLoader.getHologramLines();
|
||||
|
||||
int hologramsAmount = holograms.size();
|
||||
for (int i = hologramsAmount; i > 0; i--) {
|
||||
EntityHologram 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<Hologram> getHolograms() {
|
||||
return Collections.unmodifiableList(holograms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved() {
|
||||
return removed || super.isRemoved();
|
||||
}
|
||||
|
||||
public ChunkLoaderBlockEntityTicker getTicker() {
|
||||
return ticker;
|
||||
}
|
||||
|
||||
private void updateName(EntityHologram hologram, String line) {
|
||||
hologram.setHologramName(line
|
||||
.replace("{0}", this.cachedPlacerName)
|
||||
.replace("{1}", daysAmount + "")
|
||||
.replace("{2}", hoursAmount + "")
|
||||
.replace("{3}", minutesAmount + "")
|
||||
.replace("{4}", secondsAmount + "")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_1.loader;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.TickingBlockEntity;
|
||||
|
||||
public record ChunkLoaderBlockEntityTicker(
|
||||
ChunkLoaderBlockEntity chunkLoaderBlockEntity) implements TickingBlockEntity {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
chunkLoaderBlockEntity.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved() {
|
||||
return chunkLoaderBlockEntity.isRemoved();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return chunkLoaderBlockEntity.getBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return BlockEntityType.getKey(chunkLoaderBlockEntity.getType()) + "";
|
||||
}
|
||||
|
||||
public BlockEntity getTileEntity() {
|
||||
return chunkLoaderBlockEntity;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1"
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
group 'NMS:v1_20_2'
|
||||
|
||||
dependencies {
|
||||
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.2-R0.1-SNAPSHOT")
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = "${project.name}-exclude.jar"
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
tasks {
|
||||
reobfJar {
|
||||
File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar")
|
||||
outputJar.set(layout.buildDirectory.file(outputFile.getPath()))
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('nms.compile_v1_20') && !Boolean.valueOf(project.findProperty("nms.compile_v1_20").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -1,254 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_2;
|
||||
|
||||
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;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketListener;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.ServerAdvancementManager;
|
||||
import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoaderNPC {
|
||||
|
||||
private static final ReflectMethod<Void> SET_GAMEMODE = new ReflectMethod<>(ServerPlayerGameMode.class,
|
||||
1, GameType.class, GameType.class);
|
||||
|
||||
private final ServerLevel serverLevel;
|
||||
private final AABB boundingBox;
|
||||
private final PlayerAdvancements advancements;
|
||||
|
||||
private boolean dieCall = false;
|
||||
|
||||
public ChunkLoaderNPCImpl(MinecraftServer minecraftServer, Location location, UUID uuid) {
|
||||
super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(),
|
||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
||||
ClientInformation.createDefault());
|
||||
|
||||
this.serverLevel = serverLevel();
|
||||
this.boundingBox = new AABB(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
|
||||
this.connection = new DummyServerGamePacketListenerImpl(minecraftServer, this);
|
||||
|
||||
this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
|
||||
|
||||
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
|
||||
try {
|
||||
setLoadViewDistance(2);
|
||||
setTickViewDistance(2);
|
||||
setSendViewDistance(2);
|
||||
affectsSpawning = true;
|
||||
} catch (Throwable ignored) {
|
||||
// Doesn't exist on Spigot
|
||||
}
|
||||
|
||||
spawnIn(this.serverLevel);
|
||||
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
||||
this.serverLevel.addNewPlayer(this);
|
||||
|
||||
super.setBoundingBox(this.boundingBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return super.getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling() {
|
||||
return this.boundingBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(RemovalReason removalReason) {
|
||||
if (!dieCall) {
|
||||
dieCall = true;
|
||||
this.serverLevel.removePlayerImmediately(this, RemovalReason.UNLOADED_WITH_PLAYER);
|
||||
dieCall = false;
|
||||
} else {
|
||||
super.remove(removalReason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerAdvancements getAdvancements() {
|
||||
return this.advancements;
|
||||
}
|
||||
|
||||
public static class DummyConnection extends Connection {
|
||||
|
||||
DummyConnection() {
|
||||
super(PacketFlow.SERVERBOUND);
|
||||
this.channel = new DummyChannel();
|
||||
this.address = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(PacketListener packetListener) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
public class DummyServerGamePacketListenerImpl extends ServerGamePacketListenerImpl {
|
||||
|
||||
DummyServerGamePacketListenerImpl(MinecraftServer minecraftServer, ServerPlayer serverPlayer) {
|
||||
super(minecraftServer, new DummyConnection(), serverPlayer, CommonListenerCookie.createInitial(ChunkLoaderNPCImpl.this.getGameProfile()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleContainerClick(ServerboundContainerClickPacket containerClickPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMovePlayer(ServerboundMovePlayerPacket movePlayerPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSignUpdate(ServerboundSignUpdatePacket signUpdatePacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePlayerAction(ServerboundPlayerActionPacket playerActionPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUseItem(ServerboundUseItemPacket useItemPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket setCarriedItemPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChat(ServerboundChatPacket chatPacket) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String s) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public void send(Packet<?> packet) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class DummyPlayerAdvancements extends PlayerAdvancements {
|
||||
|
||||
DummyPlayerAdvancements(MinecraftServer server, ServerPlayer serverPlayer) {
|
||||
super(server.getFixerUpper(), server.getPlayerList(), server.getAdvancements(),
|
||||
getAdvancementsFile(server, serverPlayer), serverPlayer);
|
||||
}
|
||||
|
||||
private static Path getAdvancementsFile(MinecraftServer server, ServerPlayer serverPlayer) {
|
||||
File advancementsDir = server.getWorldPath(LevelResource.PLAYER_ADVANCEMENTS_DIR).toFile();
|
||||
return new File(advancementsDir, serverPlayer.getUUID() + ".json").toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(ServerPlayer owner) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListening() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(ServerAdvancementManager advancementLoader) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean award(AdvancementHolder advancement, String criterionName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revoke(AdvancementHolder advancement, String criterionName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushDirty(ServerPlayer player) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedTab(@Nullable AdvancementHolder advancement) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdvancementProgress getOrStartProgress(AdvancementHolder advancement) {
|
||||
return new AdvancementProgress();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_2;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftArmorStand;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.util.CraftChatMessage;
|
||||
|
||||
public final class EntityHologram extends ArmorStand implements Hologram {
|
||||
|
||||
private static final AABB EMPTY_BOUND = new AABB(0D, 0D, 0D, 0D, 0D, 0D);
|
||||
|
||||
private CraftEntity bukkitEntity;
|
||||
|
||||
public EntityHologram(ServerLevel serverLevel, double x, double y, double z) {
|
||||
super(serverLevel, x, y, z);
|
||||
|
||||
setInvisible(true);
|
||||
setSmall(true);
|
||||
setShowArms(false);
|
||||
setNoGravity(true);
|
||||
setNoBasePlate(true);
|
||||
setMarker(true);
|
||||
|
||||
super.collides = false;
|
||||
super.setCustomNameVisible(true); // Custom name visible
|
||||
super.setBoundingBox(EMPTY_BOUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHologramName(String name) {
|
||||
super.setCustomName(CraftChatMessage.fromStringOrNull(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHologram() {
|
||||
super.remove(RemovalReason.DISCARDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getEntity() {
|
||||
return getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
// Disable normal ticking for this entity.
|
||||
|
||||
// Workaround to force EntityTrackerEntry to send a teleport packet immediately after spawning this entity.
|
||||
if (this.onGround) {
|
||||
this.onGround = 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.onGround) {
|
||||
this.onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdditionalSaveData(CompoundTag compoundTag) {
|
||||
// Do not save NBT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveAsPassenger(CompoundTag compoundTag) {
|
||||
// Do not save NBT.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag saveWithoutId(CompoundTag compoundTag) {
|
||||
// Do not save NBT.
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag compoundTag) {
|
||||
// Do not load NBT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag compoundTag) {
|
||||
// Do not load NBT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerableTo(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 repositionEntityAfterLoad() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(Component component) {
|
||||
// Locks the custom name.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomNameVisible(boolean visible) {
|
||||
// Locks the custom name.
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult interactAt(Player player, Vec3 hitPos, InteractionHand hand) {
|
||||
// Prevent stand being equipped
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemSlot(EquipmentSlot equipmentSlot, ItemStack itemStack, boolean silent) {
|
||||
// Prevent stand being equipped
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling() {
|
||||
return EMPTY_BOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(SoundEvent soundEvent, float volume, float pitch) {
|
||||
// Remove sounds.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(RemovalReason removalReason) {
|
||||
// Prevent being killed.
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null) {
|
||||
bukkitEntity = new CraftArmorStand((CraftServer) Bukkit.getServer(), this);
|
||||
}
|
||||
return bukkitEntity;
|
||||
}
|
||||
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_2;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
||||
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_20_2.loader.ChunkLoaderBlockEntity;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class NMSAdapterImpl implements NMSAdapter {
|
||||
|
||||
@Override
|
||||
public String getTag(org.bukkit.inventory.ItemStack bukkitItem, String key, String def) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getTag();
|
||||
return compoundTag == null || !compoundTag.contains(key, 8) ? def : compoundTag.getString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack bukkitItem, String key, String value) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
|
||||
compoundTag.putString(key, value);
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTag(org.bukkit.inventory.ItemStack bukkitItem, String key, long def) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getTag();
|
||||
return compoundTag == null || !compoundTag.contains(key, 4) ? def : compoundTag.getLong(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack setTag(org.bukkit.inventory.ItemStack bukkitItem, String key, long value) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
|
||||
compoundTag.putLong(key, value);
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack bukkitItem, String texture) {
|
||||
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
|
||||
CompoundTag skullOwner = compoundTag.contains("SkullOwner") ?
|
||||
compoundTag.getCompound("SkullOwner") : new CompoundTag();
|
||||
|
||||
CompoundTag properties = new CompoundTag();
|
||||
ListTag textures = new ListTag();
|
||||
CompoundTag signature = new CompoundTag();
|
||||
|
||||
signature.putString("Value", texture);
|
||||
textures.add(signature);
|
||||
|
||||
properties.put("textures", textures);
|
||||
|
||||
skullOwner.put("Properties", properties);
|
||||
skullOwner.putString("Id", UUID.randomUUID().toString());
|
||||
|
||||
compoundTag.put("SkullOwner", skullOwner);
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||
return new ChunkLoaderNPCImpl(((CraftServer) Bukkit.getServer()).getServer(), location, uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
|
||||
Location loaderLoc = chunkLoader.getLocation();
|
||||
World bukkitWorld = loaderLoc.getWorld();
|
||||
|
||||
if (bukkitWorld == null)
|
||||
throw new IllegalArgumentException("Cannot create loader in null world.");
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
||||
BlockPos blockPos = new BlockPos(loaderLoc.getBlockX(), loaderLoc.getBlockY(), loaderLoc.getBlockZ());
|
||||
|
||||
ChunkLoaderBlockEntity ChunkLoaderBlockEntity = new ChunkLoaderBlockEntity(chunkLoader, serverLevel, blockPos);
|
||||
serverLevel.addBlockEntityTicker(ChunkLoaderBlockEntity.getTicker());
|
||||
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, true));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, true);
|
||||
}
|
||||
|
||||
return ChunkLoaderBlockEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
|
||||
Location loaderLoc = chunkLoader.getLocation();
|
||||
World bukkitWorld = loaderLoc.getWorld();
|
||||
|
||||
if (bukkitWorld == null)
|
||||
throw new IllegalArgumentException("Cannot remove loader in null world.");
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
||||
BlockPos blockPos = new BlockPos(loaderLoc.getBlockX(), loaderLoc.getBlockY(), loaderLoc.getBlockZ());
|
||||
|
||||
long chunkPosLong = ChunkPos.asLong(blockPos.getX() >> 4, blockPos.getZ() >> 4);
|
||||
ChunkLoaderBlockEntity chunkLoaderBlockEntity = ChunkLoaderBlockEntity.chunkLoaderBlockEntityMap.remove(chunkPosLong);
|
||||
|
||||
if (chunkLoaderBlockEntity != null) {
|
||||
chunkLoaderBlockEntity.holograms.forEach(EntityHologram::removeHologram);
|
||||
chunkLoaderBlockEntity.removed = true;
|
||||
}
|
||||
|
||||
if (spawnParticle)
|
||||
serverLevel.levelEvent(null, 2001, blockPos, Block.getId(serverLevel.getBlockState(blockPos)));
|
||||
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, false));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setChunksForcedForLoader(ChunkLoader chunkLoader, ServerLevel serverLevel, boolean forced) {
|
||||
int requiredPlayerRange = forced ? -1 : 16;
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
LevelChunk levelChunk = serverLevel.getChunk(bukkitChunk.getX(), bukkitChunk.getZ());
|
||||
|
||||
for (BlockEntity blockEntity : levelChunk.getBlockEntities().values()) {
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = requiredPlayerRange;
|
||||
}
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, forced);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSpawner(Location location, boolean reset) {
|
||||
World bukkitWorld = location.getWorld();
|
||||
|
||||
if (bukkitWorld == null)
|
||||
throw new IllegalArgumentException("Cannot remove loader in null world.");
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld) bukkitWorld).getHandle();
|
||||
BlockPos blockPos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockEntity blockEntity = serverLevel.getBlockEntity(blockPos);
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = reset ? 16 : -1;
|
||||
}
|
||||
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_2.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_20_2.EntityHologram;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
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.Optional;
|
||||
|
||||
public final class ChunkLoaderBlockEntity extends BlockEntity implements ITileEntityChunkLoader {
|
||||
|
||||
public static final Map<Long, ChunkLoaderBlockEntity> chunkLoaderBlockEntityMap = new HashMap<>();
|
||||
|
||||
public final List<EntityHologram> holograms = new ArrayList<>();
|
||||
private final WChunkLoader chunkLoader;
|
||||
private final Block loaderBlock;
|
||||
private final ChunkLoaderBlockEntityTicker ticker;
|
||||
private final ServerLevel serverLevel;
|
||||
private final BlockPos blockPos;
|
||||
private final String cachedPlacerName;
|
||||
|
||||
private short currentTick = 20;
|
||||
private short daysAmount, hoursAmount, minutesAmount, secondsAmount;
|
||||
public boolean removed = false;
|
||||
|
||||
public ChunkLoaderBlockEntity(ChunkLoader chunkLoader, ServerLevel serverLevel, BlockPos blockPos) {
|
||||
super(BlockEntityType.COMMAND_BLOCK, blockPos, serverLevel.getBlockState(blockPos));
|
||||
|
||||
this.chunkLoader = (WChunkLoader) chunkLoader;
|
||||
this.ticker = new ChunkLoaderBlockEntityTicker(this);
|
||||
this.blockPos = blockPos;
|
||||
this.serverLevel = serverLevel;
|
||||
|
||||
setLevel(serverLevel);
|
||||
|
||||
loaderBlock = serverLevel.getBlockState(blockPos).getBlock();
|
||||
|
||||
this.cachedPlacerName = Optional.ofNullable(this.chunkLoader.getWhoPlaced().getName()).orElse("");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
long chunkPosLong = ChunkPos.asLong(blockPos.getX() >> 4, blockPos.getZ() >> 4);
|
||||
chunkLoaderBlockEntityMap.put(chunkPosLong, this);
|
||||
|
||||
List<String> hologramLines = this.chunkLoader.getHologramLines();
|
||||
|
||||
double currentY = blockPos.getY() + 1;
|
||||
for (int i = hologramLines.size(); i > 0; i--) {
|
||||
EntityHologram hologram = new EntityHologram(serverLevel, blockPos.getX() + 0.5, currentY, blockPos.getZ() + 0.5);
|
||||
updateName(hologram, hologramLines.get(i - 1));
|
||||
serverLevel.addFreshEntity(hologram);
|
||||
currentY += 0.23;
|
||||
holograms.add(hologram);
|
||||
}
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if (removed || ++currentTick <= 20)
|
||||
return;
|
||||
|
||||
currentTick = 0;
|
||||
|
||||
if (chunkLoader.isNotActive() || this.serverLevel.getBlockState(this.blockPos).getBlock() != loaderBlock) {
|
||||
chunkLoader.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunkLoader.isInfinite())
|
||||
return;
|
||||
|
||||
List<String> hologramLines = chunkLoader.getHologramLines();
|
||||
|
||||
int hologramsAmount = holograms.size();
|
||||
for (int i = hologramsAmount; i > 0; i--) {
|
||||
EntityHologram 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<Hologram> getHolograms() {
|
||||
return Collections.unmodifiableList(holograms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved() {
|
||||
return removed || super.isRemoved();
|
||||
}
|
||||
|
||||
public ChunkLoaderBlockEntityTicker getTicker() {
|
||||
return ticker;
|
||||
}
|
||||
|
||||
private void updateName(EntityHologram hologram, String line) {
|
||||
hologram.setHologramName(line
|
||||
.replace("{0}", this.cachedPlacerName)
|
||||
.replace("{1}", daysAmount + "")
|
||||
.replace("{2}", hoursAmount + "")
|
||||
.replace("{3}", minutesAmount + "")
|
||||
.replace("{4}", secondsAmount + "")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_2.loader;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.TickingBlockEntity;
|
||||
|
||||
public record ChunkLoaderBlockEntityTicker(
|
||||
ChunkLoaderBlockEntity chunkLoaderBlockEntity) implements TickingBlockEntity {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
chunkLoaderBlockEntity.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved() {
|
||||
return chunkLoaderBlockEntity.isRemoved();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return chunkLoaderBlockEntity.getBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return BlockEntityType.getKey(chunkLoaderBlockEntity.getType()) + "";
|
||||
}
|
||||
|
||||
public BlockEntity getTileEntity() {
|
||||
return chunkLoaderBlockEntity;
|
||||
}
|
||||
|
||||
}
|
@ -29,10 +29,7 @@ include 'NMS:v1_16_R3'
|
||||
include 'NMS:v1_17'
|
||||
include 'NMS:v1_18'
|
||||
include 'NMS:v1_19'
|
||||
include 'NMS:v1_20_1'
|
||||
include 'NMS:v1_20_2'
|
||||
include 'NMS:v1_20_3'
|
||||
include 'NMS:v1_20_4'
|
||||
include 'NMS:v1_21'
|
||||
findProject(':NMS:v1_21')?.name = 'v1_21'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user