mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2024-11-22 11:56:17 +01:00
Moved all nms classes to their own version packages
This commit is contained in:
parent
c0a137ff01
commit
5eeb714145
@ -92,8 +92,9 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders {
|
|||||||
private void loadNMSAdapter() {
|
private void loadNMSAdapter() {
|
||||||
String version = getServer().getClass().getPackage().getName().split("\\.")[3];
|
String version = getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||||
try {
|
try {
|
||||||
nmsAdapter = (NMSAdapter) Class.forName("com.bgsoftware.wildloaders.nms.NMSAdapter_" + version).newInstance();
|
nmsAdapter = (NMSAdapter) Class.forName(String.format("com.bgsoftware.wildloaders.nms.%s.NMSAdapter", version)).newInstance();
|
||||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
|
||||||
|
shouldEnable = false;
|
||||||
log("Couldn't load up with an adapter " + version + ". Please contact @Ome_R");
|
log("Couldn't load up with an adapter " + version + ". Please contact @Ome_R");
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
@ -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.handlers.NPCHandler;
|
||||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@ -32,11 +31,11 @@ import org.bukkit.entity.Player;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.UUID;
|
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);
|
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(),
|
super(((CraftServer) Bukkit.getServer()).getServer(),
|
||||||
((CraftWorld) location.getWorld()).getHandle(),
|
((CraftWorld) location.getWorld()).getHandle(),
|
||||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
@ -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 com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
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;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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);
|
super(world, x, y, z);
|
||||||
setInvisible(true);
|
setInvisible(true);
|
||||||
setSmall(true);
|
setSmall(true);
|
@ -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.WildLoadersPlugin;
|
||||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
|
||||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
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.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.Block;
|
||||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||||
import net.minecraft.server.v1_12_R1.Chunk;
|
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.ItemStack;
|
||||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_12_R1.NBTTagList;
|
import net.minecraft.server.v1_12_R1.NBTTagList;
|
||||||
@ -24,27 +22,14 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
|||||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.util.LongHash;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings({"ConstantConditions", "unused"})
|
@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 final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
|
||||||
private static Method compoundLoadMethod = null;
|
|
||||||
|
|
||||||
static {
|
private static final ReflectMethod<Void> TILE_ENTITY_LOAD = new ReflectMethod<>(TileEntity.class, "load", NBTTagCompound.class);
|
||||||
try{
|
|
||||||
//noinspection JavaReflectionMemberAccess
|
|
||||||
compoundLoadMethod = TileEntity.class.getMethod("load", NBTTagCompound.class);
|
|
||||||
}catch (Exception ignored){}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
|
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
|
||||||
@ -120,8 +105,8 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||||
return new ChunkLoaderNPC_v1_12_R1(location, uuid);
|
return new ChunkLoaderNPC(location, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,10 +124,9 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter {
|
|||||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||||
tileEntity.save(nbtTagCompound);
|
tileEntity.save(nbtTagCompound);
|
||||||
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
|
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
|
||||||
|
if (TILE_ENTITY_LOAD.isValid()) {
|
||||||
try {
|
TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound);
|
||||||
compoundLoadMethod.invoke(tileEntity, nbtTagCompound);
|
} else {
|
||||||
} catch (Throwable ex) {
|
|
||||||
tileEntity.a(nbtTagCompound);
|
tileEntity.a(nbtTagCompound);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -160,7 +144,7 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter {
|
|||||||
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
||||||
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
||||||
if (tileEntityChunkLoader != null) {
|
if (tileEntityChunkLoader != null) {
|
||||||
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_12_R1::removeHologram);
|
tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram);
|
||||||
tileEntityChunkLoader.removed = true;
|
tileEntityChunkLoader.removed = true;
|
||||||
world.tileEntityListTick.remove(tileEntityChunkLoader);
|
world.tileEntityListTick.remove(tileEntityChunkLoader);
|
||||||
}
|
}
|
||||||
@ -174,10 +158,9 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter {
|
|||||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||||
tileEntity.save(nbtTagCompound);
|
tileEntity.save(nbtTagCompound);
|
||||||
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
|
nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
|
||||||
|
if (TILE_ENTITY_LOAD.isValid()) {
|
||||||
try {
|
TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound);
|
||||||
compoundLoadMethod.invoke(tileEntity, nbtTagCompound);
|
} else {
|
||||||
} catch (Throwable ex) {
|
|
||||||
tileEntity.a(nbtTagCompound);
|
tileEntity.a(nbtTagCompound);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -193,120 +176,11 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter {
|
|||||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||||
mobSpawner.save(nbtTagCompound);
|
mobSpawner.save(nbtTagCompound);
|
||||||
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
|
nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
|
||||||
|
if (TILE_ENTITY_LOAD.isValid()) {
|
||||||
try {
|
TILE_ENTITY_LOAD.invoke(mobSpawner, nbtTagCompound);
|
||||||
compoundLoadMethod.invoke(mobSpawner, nbtTagCompound);
|
} else {
|
||||||
}catch (Throwable ex){
|
|
||||||
mobSpawner.a(nbtTagCompound);
|
mobSpawner.a(nbtTagCompound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
|
|
||||||
|
|
||||||
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_12_R1> 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<String> 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<String> 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<Hologram> 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 + "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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.handlers.NPCHandler;
|
||||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@ -31,13 +30,13 @@ import org.bukkit.entity.Player;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.UUID;
|
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 static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D);
|
||||||
|
|
||||||
private boolean dieCall = false;
|
private boolean dieCall = false;
|
||||||
|
|
||||||
public ChunkLoaderNPC_v1_16_R3(Location location, UUID uuid) {
|
public ChunkLoaderNPC(Location location, UUID uuid) {
|
||||||
super(((CraftServer) Bukkit.getServer()).getServer(),
|
super(((CraftServer) Bukkit.getServer()).getServer(),
|
||||||
((CraftWorld) location.getWorld()).getHandle(),
|
((CraftWorld) location.getWorld()).getHandle(),
|
||||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
@ -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 com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||||
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
|
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
|
||||||
@ -22,11 +22,11 @@ import org.bukkit.entity.Entity;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class EntityHolograms_v1_16_R3 extends EntityArmorStand implements Hologram {
|
public final class EntityHolograms extends EntityArmorStand implements Hologram {
|
||||||
|
|
||||||
private CraftEntity bukkitEntity;
|
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);
|
super(world, x, y, z);
|
||||||
setInvisible(true);
|
setInvisible(true);
|
||||||
setSmall(true);
|
setSmall(true);
|
@ -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.WildLoadersPlugin;
|
||||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
|
||||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
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.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.Block;
|
||||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||||
import net.minecraft.server.v1_16_R3.Chunk;
|
import net.minecraft.server.v1_16_R3.Chunk;
|
||||||
import net.minecraft.server.v1_16_R3.ChunkCoordIntPair;
|
import net.minecraft.server.v1_16_R3.ChunkCoordIntPair;
|
||||||
import net.minecraft.server.v1_16_R3.IBlockData;
|
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.ItemStack;
|
||||||
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_16_R3.NBTTagList;
|
import net.minecraft.server.v1_16_R3.NBTTagList;
|
||||||
import net.minecraft.server.v1_16_R3.NBTTagLong;
|
import net.minecraft.server.v1_16_R3.NBTTagLong;
|
||||||
import net.minecraft.server.v1_16_R3.NBTTagString;
|
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.TileEntityMobSpawner;
|
||||||
import net.minecraft.server.v1_16_R3.TileEntityTypes;
|
|
||||||
import net.minecraft.server.v1_16_R3.World;
|
import net.minecraft.server.v1_16_R3.World;
|
||||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||||
import org.bukkit.Location;
|
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.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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();
|
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
|
||||||
|
|
||||||
@ -114,8 +103,8 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||||
return new ChunkLoaderNPC_v1_16_R3(location, uuid);
|
return new ChunkLoaderNPC(location, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -149,7 +138,7 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter {
|
|||||||
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
||||||
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
||||||
if (tileEntityChunkLoader != null) {
|
if (tileEntityChunkLoader != null) {
|
||||||
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_16_R3::removeHologram);
|
tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram);
|
||||||
tileEntityChunkLoader.removed = true;
|
tileEntityChunkLoader.removed = true;
|
||||||
world.tileEntityListTick.remove(tileEntityChunkLoader);
|
world.tileEntityListTick.remove(tileEntityChunkLoader);
|
||||||
}
|
}
|
||||||
@ -181,125 +170,4 @@ public final class NMSAdapter_v1_16_R3 implements NMSAdapter {
|
|||||||
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
|
mobSpawner.getSpawner().requiredPlayerRange = reset ? 16 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TileEntityChunkLoader extends TileEntity implements ITickable, ITileEntityChunkLoader {
|
|
||||||
|
|
||||||
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_16_R3> 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<String> 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<String> 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<Hologram> 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 + "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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.common.reflection.ReflectMethod;
|
||||||
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
|
|
||||||
import com.bgsoftware.wildloaders.handlers.NPCHandler;
|
import com.bgsoftware.wildloaders.handlers.NPCHandler;
|
||||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@ -29,7 +28,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.UUID;
|
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);
|
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;
|
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(),
|
super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(),
|
||||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())));
|
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())));
|
||||||
|
|
@ -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 com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@ -24,13 +24,13 @@ import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D);
|
||||||
|
|
||||||
private CraftEntity bukkitEntity;
|
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);
|
super(world, x, y, z);
|
||||||
setInvisible(true);
|
setInvisible(true);
|
||||||
setSmall(true);
|
setSmall(true);
|
@ -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.common.reflection.ReflectMethod;
|
||||||
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
||||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
|
||||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
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.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.core.BlockPosition;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
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.TickingBlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.TileEntity;
|
import net.minecraft.world.level.block.entity.TileEntity;
|
||||||
import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
|
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.block.state.IBlockData;
|
||||||
import net.minecraft.world.level.chunk.Chunk;
|
import net.minecraft.world.level.chunk.Chunk;
|
||||||
import org.bukkit.Bukkit;
|
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.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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();
|
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
|
||||||
|
|
||||||
@ -121,8 +112,8 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||||
return new ChunkLoaderNPC_v1_17_R1(((CraftServer) Bukkit.getServer()).getServer(), location, uuid);
|
return new ChunkLoaderNPC(((CraftServer) Bukkit.getServer()).getServer(), location, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -156,7 +147,7 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter {
|
|||||||
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
||||||
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
||||||
if (tileEntityChunkLoader != null) {
|
if (tileEntityChunkLoader != null) {
|
||||||
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_17_R1::removeHologram);
|
tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram);
|
||||||
tileEntityChunkLoader.removed = true;
|
tileEntityChunkLoader.removed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,146 +178,4 @@ public final class NMSAdapter_v1_17_R1 implements NMSAdapter {
|
|||||||
mobSpawner.getSpawner().n = reset ? 16 : -1;
|
mobSpawner.getSpawner().n = reset ? 16 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TileEntityChunkLoader extends TileEntity implements ITileEntityChunkLoader {
|
|
||||||
|
|
||||||
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_17_R1> 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<String> 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<String> 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<Hologram> 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()) + "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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()) + "";
|
||||||
|
}
|
||||||
|
}
|
@ -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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<TickingBlockEntity> 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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_18_R1> 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<String> 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<String> 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<Hologram> 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)) + "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<Void> 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<BlockPosition, TileEntity> 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<Void> 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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.api.holograms.Hologram;
|
||||||
|
import com.bgsoftware.wildloaders.nms.mapping.Remap;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.chat.IChatBaseComponent;
|
import net.minecraft.network.chat.IChatBaseComponent;
|
||||||
import net.minecraft.sounds.SoundEffect;
|
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;
|
import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D);
|
||||||
|
|
||||||
private CraftEntity bukkitEntity;
|
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);
|
super(world, x, y, z);
|
||||||
j(true); // Invisible
|
j(true); // Invisible
|
||||||
a(true); // Small
|
a(true); // Small
|
||||||
@ -40,11 +49,19 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements
|
|||||||
super.a(EMPTY_BOUND);
|
super.a(EMPTY_BOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "setCustomName",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "a")
|
||||||
@Override
|
@Override
|
||||||
public void setHologramName(String name) {
|
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
|
@Override
|
||||||
public void removeHologram() {
|
public void removeHologram() {
|
||||||
super.a(RemovalReason.b);
|
super.a(RemovalReason.b);
|
||||||
@ -55,6 +72,10 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements
|
|||||||
return getBukkitEntity();
|
return getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "tick",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "k")
|
||||||
@Override
|
@Override
|
||||||
public void k() {
|
public void k() {
|
||||||
// Disable normal ticking for this entity.
|
// 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
|
@Override
|
||||||
public void inactiveTick() {
|
public void inactiveTick() {
|
||||||
// Disable normal ticking for this entity.
|
// 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
|
@Override
|
||||||
public void b(NBTTagCompound nbttagcompound) {
|
public void b(NBTTagCompound nbttagcompound) {
|
||||||
// Do not save NBT.
|
// Do not save NBT.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "saveAsPassenger",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "d")
|
||||||
@Override
|
@Override
|
||||||
public boolean d(NBTTagCompound nbttagcompound) {
|
public boolean d(NBTTagCompound nbttagcompound) {
|
||||||
// Do not save NBT.
|
// Do not save NBT.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "saveWithoutId",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "f")
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound f(NBTTagCompound nbttagcompound) {
|
public NBTTagCompound f(NBTTagCompound nbttagcompound) {
|
||||||
// Do not save NBT.
|
// Do not save NBT.
|
||||||
return nbttagcompound;
|
return nbttagcompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "readAdditionalSaveData",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "a")
|
||||||
@Override
|
@Override
|
||||||
public void a(NBTTagCompound nbttagcompound) {
|
public void a(NBTTagCompound nbttagcompound) {
|
||||||
// Do not load NBT.
|
// Do not load NBT.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "load",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "g")
|
||||||
@Override
|
@Override
|
||||||
public void g(NBTTagCompound nbttagcompound) {
|
public void g(NBTTagCompound nbttagcompound) {
|
||||||
// Do not load NBT.
|
// Do not load NBT.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "isInvulnerableTo",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "b")
|
||||||
@Override
|
@Override
|
||||||
public boolean b(DamageSource source) {
|
public boolean b(DamageSource source) {
|
||||||
/*
|
/*
|
||||||
@ -112,21 +161,37 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "repositionEntityAfterLoad",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "bj")
|
||||||
@Override
|
@Override
|
||||||
public boolean bi() {
|
public boolean bj() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "setCustomName",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "a")
|
||||||
@Override
|
@Override
|
||||||
public void a(IChatBaseComponent ichatbasecomponent) {
|
public void a(IChatBaseComponent ichatbasecomponent) {
|
||||||
// Locks the custom name.
|
// Locks the custom name.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "setCustomNameVisible",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "n")
|
||||||
@Override
|
@Override
|
||||||
public void n(boolean flag) {
|
public void n(boolean flag) {
|
||||||
// Locks the custom name.
|
// Locks the custom name.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.decoration.ArmorStand",
|
||||||
|
name = "interactAt",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "a")
|
||||||
@Override
|
@Override
|
||||||
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
|
public EnumInteractionResult a(EntityHuman human, Vec3D vec3d, EnumHand enumhand) {
|
||||||
// Prevent stand being equipped
|
// Prevent stand being equipped
|
||||||
@ -138,6 +203,10 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements
|
|||||||
// Prevent stand being equipped
|
// Prevent stand being equipped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "getBoundingBoxForCulling",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "cx")
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBB cx() {
|
public AxisAlignedBB cx() {
|
||||||
return EMPTY_BOUND;
|
return EMPTY_BOUND;
|
||||||
@ -147,11 +216,19 @@ public final class EntityHolograms_v1_18_R1 extends EntityArmorStand implements
|
|||||||
super.a(boundingBox);
|
super.a(boundingBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "playSound",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "a")
|
||||||
@Override
|
@Override
|
||||||
public void a(SoundEffect soundeffect, float f, float f1) {
|
public void a(SoundEffect soundeffect, float f, float f1) {
|
||||||
// Remove sounds.
|
// Remove sounds.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remap(classPath = "net.minecraft.world.entity.Entity",
|
||||||
|
name = "remove",
|
||||||
|
type = Remap.Type.METHOD,
|
||||||
|
remappedName = "a")
|
||||||
@Override
|
@Override
|
||||||
public void a(RemovalReason entity_removalreason) {
|
public void a(RemovalReason entity_removalreason) {
|
||||||
// Prevent being killed.
|
// Prevent being killed.
|
@ -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<TickingBlockEntity> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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()) + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.bgsoftware.wildloaders.nms.v1_18_R1.mappings;
|
||||||
|
|
||||||
|
public abstract class MappedObject<E> {
|
||||||
|
|
||||||
|
protected final E handle;
|
||||||
|
|
||||||
|
protected MappedObject(E handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public E getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.core.BlockPosition> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.nbt.NBTTagCompound> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.entity.Entity> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.item.ItemStack> {
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.ChunkCoordIntPair> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.World> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.block.entity.TileEntity> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.block.state.IBlockData> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.chunk.Chunk> {
|
||||||
|
|
||||||
|
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<BlockPosition, TileEntity> 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<TickingBlockEntity> 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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_18_R2> 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<String> 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<String> 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<Hologram> 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)) + "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<Void> 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<BlockPosition, TileEntity> 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<Void> 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<TickingBlockEntity> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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()) + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.bgsoftware.wildloaders.nms.v1_18_R2.mappings;
|
||||||
|
|
||||||
|
public abstract class MappedObject<E> {
|
||||||
|
|
||||||
|
protected final E handle;
|
||||||
|
|
||||||
|
protected MappedObject(E handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public E getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.core.BlockPosition> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.nbt.NBTTagCompound> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.entity.Entity> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.item.ItemStack> {
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.ChunkCoordIntPair> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.World> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.block.entity.TileEntity> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.block.state.IBlockData> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.chunk.Chunk> {
|
||||||
|
|
||||||
|
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<BlockPosition, TileEntity> 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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'
|
compileOnly 'io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT'
|
||||||
|
|
||||||
|
@ -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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<TickingBlockEntity> 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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_19_R1> 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<String> 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<String> 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<Hologram> 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)) + "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<Void> 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<BlockPosition, TileEntity> 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<Void> 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<TickingBlockEntity> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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()) + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.bgsoftware.wildloaders.nms.v1_19_R1.mappings;
|
||||||
|
|
||||||
|
public abstract class MappedObject<E> {
|
||||||
|
|
||||||
|
protected final E handle;
|
||||||
|
|
||||||
|
protected MappedObject(E handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public E getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.core.BlockPosition> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.nbt.NBTTagCompound> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.entity.Entity> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.item.ItemStack> {
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.ChunkCoordIntPair> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.World> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.block.entity.TileEntity> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.block.state.IBlockData> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<net.minecraft.world.level.chunk.Chunk> {
|
||||||
|
|
||||||
|
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<BlockPosition, TileEntity> 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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.handlers.NPCHandler;
|
||||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||||
import net.minecraft.server.v1_7_R4.DamageSource;
|
import net.minecraft.server.v1_7_R4.DamageSource;
|
||||||
@ -30,9 +29,9 @@ import org.bukkit.entity.Player;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.UUID;
|
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(),
|
super(((CraftServer) Bukkit.getServer()).getServer(),
|
||||||
((CraftWorld) location.getWorld()).getHandle(),
|
((CraftWorld) location.getWorld()).getHandle(),
|
||||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
@ -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.WildLoadersPlugin;
|
||||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
|
||||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
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.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.Block;
|
||||||
import net.minecraft.server.v1_7_R4.Chunk;
|
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.ItemStack;
|
||||||
import net.minecraft.server.v1_7_R4.NBTTagCompound;
|
import net.minecraft.server.v1_7_R4.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_7_R4.NBTTagList;
|
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.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.util.LongHash;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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();
|
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
|
||||||
|
|
||||||
@ -108,8 +101,8 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||||
return new ChunkLoaderNPC_v1_7_R4(location, uuid);
|
return new ChunkLoaderNPC(location, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -177,51 +170,4 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter {
|
|||||||
mobSpawner.a(nbtTagCompound);
|
mobSpawner.a(nbtTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader {
|
|
||||||
|
|
||||||
private static final Collection<Hologram> EMPTY_CONTAINER = Collections.emptyList();
|
|
||||||
|
|
||||||
private static final Map<Long, TileEntityChunkLoader> 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<Hologram> getHolograms() {
|
|
||||||
return EMPTY_CONTAINER;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -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<Hologram> EMPTY_CONTAINER = Collections.emptyList();
|
||||||
|
|
||||||
|
public static final Map<Long, TileEntityChunkLoader> 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<Hologram> getHolograms() {
|
||||||
|
return EMPTY_CONTAINER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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.handlers.NPCHandler;
|
||||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@ -32,11 +31,11 @@ import org.bukkit.entity.Player;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.UUID;
|
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);
|
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(),
|
super(((CraftServer) Bukkit.getServer()).getServer(),
|
||||||
((CraftWorld) location.getWorld()).getHandle(),
|
((CraftWorld) location.getWorld()).getHandle(),
|
||||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
|
@ -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 com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||||
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
|
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;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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);
|
super(world, x, y, z);
|
||||||
setInvisible(true);
|
setInvisible(true);
|
||||||
setSmall(true);
|
setSmall(true);
|
@ -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.WildLoadersPlugin;
|
||||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
|
||||||
import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
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.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.Block;
|
||||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||||
import net.minecraft.server.v1_8_R3.Chunk;
|
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.ItemStack;
|
||||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_8_R3.NBTTagList;
|
import net.minecraft.server.v1_8_R3.NBTTagList;
|
||||||
import net.minecraft.server.v1_8_R3.NBTTagLong;
|
import net.minecraft.server.v1_8_R3.NBTTagLong;
|
||||||
import net.minecraft.server.v1_8_R3.NBTTagString;
|
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.TileEntityMobSpawner;
|
||||||
import net.minecraft.server.v1_8_R3.World;
|
import net.minecraft.server.v1_8_R3.World;
|
||||||
import org.bukkit.Location;
|
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.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.util.LongHash;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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();
|
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
|
||||||
|
|
||||||
@ -111,8 +101,8 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
public com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC createNPC(Location location, UUID uuid) {
|
||||||
return new ChunkLoaderNPC_v1_8_R3(location, uuid);
|
return new ChunkLoaderNPC(location, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -146,7 +136,7 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter {
|
|||||||
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
|
||||||
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
|
||||||
if (tileEntityChunkLoader != null) {
|
if (tileEntityChunkLoader != null) {
|
||||||
tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R3::removeHologram);
|
tileEntityChunkLoader.holograms.forEach(EntityHolograms::removeHologram);
|
||||||
tileEntityChunkLoader.removed = true;
|
tileEntityChunkLoader.removed = true;
|
||||||
world.tileEntityList.remove(tileEntityChunkLoader);
|
world.tileEntityList.remove(tileEntityChunkLoader);
|
||||||
}
|
}
|
||||||
@ -178,112 +168,4 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter {
|
|||||||
mobSpawner.a(nbtTagCompound);
|
mobSpawner.a(nbtTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TileEntityChunkLoader extends TileEntity implements IUpdatePlayerListBox, ITileEntityChunkLoader {
|
|
||||||
|
|
||||||
private static final Map<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final List<EntityHolograms_v1_8_R3> 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<String> 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<String> 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<Hologram> 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 + "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -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<Long, TileEntityChunkLoader> tileEntityChunkLoaderMap = new HashMap<>();
|
||||||
|
|
||||||
|
public final List<EntityHolograms> 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<String> 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<String> 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<Hologram> 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 + "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user