Migrate v1_18_R1 NMS module to use remapped-spigot at compile-time

This commit is contained in:
Christian Koop 2022-08-28 16:52:21 +02:00
parent 9d7026ec27
commit e96cb5426d
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
18 changed files with 313 additions and 271 deletions

View File

@ -19,5 +19,5 @@ runs:
- uses: SpraxDev/Action-SpigotMC@v4 - uses: SpraxDev/Action-SpigotMC@v4
with: with:
versions: 1.18.2, 1.19 versions: 1.18.1, 1.18.2, 1.19
remapped: true remapped: true

View File

@ -13,6 +13,44 @@
<target>17</target> <target>17</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.4</version>
<executions>
<execution>
<id>remap-obf</id>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<configuration>
<srgIn>org.spigotmc:minecraft-server:${nms.ver}:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:${nms.ver}:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<id>remap-spigot</id>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:${nms.ver}:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:${nms.ver}:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
@ -26,6 +64,8 @@
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<java.release>17</java.release> <java.release>17</java.release>
<nms.ver>1.18.1-R0.1-SNAPSHOT</nms.ver>
</properties> </properties>
<artifactId>SongodaCore-NMS-v1_18_R1</artifactId> <artifactId>SongodaCore-NMS-v1_18_R1</artifactId>
@ -35,7 +75,8 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.18</version> <version>${nms.ver}</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -1,7 +1,7 @@
package com.songoda.core.nms.v1_18_R1.anvil; package com.songoda.core.nms.v1_18_R1.anvil;
import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.CustomAnvil;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
@ -9,13 +9,13 @@ import org.bukkit.inventory.InventoryHolder;
public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore {
@Override @Override
public CustomAnvil createAnvil(Player player) { public CustomAnvil createAnvil(Player player) {
EntityPlayer p = ((CraftPlayer) player).getHandle(); return createAnvil(player, null);
return new AnvilView(p.nextContainerCounter(), p, null);
} }
@Override @Override
public CustomAnvil createAnvil(Player player, InventoryHolder holder) { public CustomAnvil createAnvil(Player player, InventoryHolder holder) {
EntityPlayer p = ((CraftPlayer) player).getHandle(); ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
return new AnvilView(p.nextContainerCounter(), p, holder);
return new AnvilView(serverPlayer.nextContainerCounter(), serverPlayer, holder);
} }
} }

View File

@ -1,7 +1,7 @@
package com.songoda.core.nms.v1_18_R1.anvil; package com.songoda.core.nms.v1_18_R1.anvil;
import net.minecraft.world.IInventory; import net.minecraft.world.Container;
import net.minecraft.world.inventory.ContainerAnvil; import net.minecraft.world.inventory.AnvilMenu;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
@ -9,7 +9,7 @@ import org.bukkit.inventory.InventoryHolder;
public class AnvilInventoryCustom extends CraftInventoryAnvil { public class AnvilInventoryCustom extends CraftInventoryAnvil {
final InventoryHolder holder; final InventoryHolder holder;
public AnvilInventoryCustom(InventoryHolder holder, Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) { public AnvilInventoryCustom(InventoryHolder holder, Location location, Container inventory, Container resultInventory, AnvilMenu container) {
super(location, inventory, resultInventory, container); super(location, inventory, resultInventory, container);
this.holder = holder; this.holder = holder;

View File

@ -2,17 +2,17 @@ package com.songoda.core.nms.v1_18_R1.anvil;
import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.CustomAnvil;
import com.songoda.core.nms.anvil.methods.AnvilTextChange; import com.songoda.core.nms.anvil.methods.AnvilTextChange;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ChatMessage; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.IInventory; import net.minecraft.world.Container;
import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerAccess; import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.inventory.ContainerAnvil; import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.ContainerAnvilAbstract; import net.minecraft.world.inventory.ItemCombinerMenu;
import net.minecraft.world.inventory.Containers; import net.minecraft.world.inventory.MenuType;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -23,8 +23,8 @@ import java.lang.reflect.Field;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class AnvilView extends ContainerAnvil implements CustomAnvil { public class AnvilView extends AnvilMenu implements CustomAnvil {
private final EntityPlayer entity; private final ServerPlayer entity;
private final Inventory inventory; private final Inventory inventory;
private String customTitle = "Repairing"; private String customTitle = "Repairing";
private int cost = -1; private int cost = -1;
@ -38,13 +38,13 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
static { static {
try { try {
mc_ContainerAnvil_repairInventory = ContainerAnvilAbstract.class.getDeclaredField("p"); mc_ContainerAnvil_repairInventory = ItemCombinerMenu.class.getDeclaredField("p");
mc_ContainerAnvil_repairInventory.setAccessible(true); mc_ContainerAnvil_repairInventory.setAccessible(true);
mc_ContainerAnvil_resultInventory = ContainerAnvilAbstract.class.getDeclaredField("o"); mc_ContainerAnvil_resultInventory = ItemCombinerMenu.class.getDeclaredField("o");
mc_ContainerAnvil_resultInventory.setAccessible(true); mc_ContainerAnvil_resultInventory.setAccessible(true);
mc_ContainerAnvil_bukkitEntity = ContainerAnvil.class.getDeclaredField("bukkitEntity"); mc_ContainerAnvil_bukkitEntity = AnvilMenu.class.getDeclaredField("bukkitEntity");
mc_ContainerAnvil_bukkitEntity.setAccessible(true); mc_ContainerAnvil_bukkitEntity.setAccessible(true);
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
@ -56,17 +56,17 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
static { static {
try { try {
mc_Container_title = Container.class.getDeclaredField("title"); mc_Container_title = AbstractContainerMenu.class.getDeclaredField("title");
mc_Container_title.setAccessible(true); mc_Container_title.setAccessible(true);
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex);
} }
} }
public AnvilView(int id, EntityPlayer entity, InventoryHolder holder) { public AnvilView(int id, ServerPlayer entity, InventoryHolder holder) {
super(entity.nextContainerCounter(), entity.fq(), ContainerAccess.a(entity.t, new BlockPosition(0, 0, 0))); super(entity.nextContainerCounter(), entity.getInventory(), ContainerLevelAccess.create(entity.level, new BlockPos(0, 0, 0)));
this.setTitle(new ChatMessage(customTitle != null ? customTitle : "")); this.setTitle(new TranslatableComponent(customTitle != null ? customTitle : ""));
this.checkReachable = false; this.checkReachable = false;
this.entity = entity; this.entity = entity;
@ -77,12 +77,12 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
} }
} }
public CraftInventoryView getBukkitView(EntityHuman player, InventoryHolder holder) { public CraftInventoryView getBukkitView(Player player, InventoryHolder holder) {
try { try {
AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder, AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder,
new Location(entity.t.getWorld(), 0, 0, 0), new Location(entity.level.getWorld(), 0, 0, 0),
(IInventory) mc_ContainerAnvil_repairInventory.get(this), (Container) mc_ContainerAnvil_repairInventory.get(this),
(IInventory) mc_ContainerAnvil_resultInventory.get(this), this); (Container) mc_ContainerAnvil_resultInventory.get(this), this);
CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this); CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this);
mc_ContainerAnvil_bukkitEntity.set(this, view); mc_ContainerAnvil_bukkitEntity.set(this, view);
@ -95,13 +95,13 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
} }
@Override @Override
public boolean a(EntityHuman entityhuman) { public boolean stillValid(Player entityHuman) {
return canUse; return canUse;
} }
@Override @Override
public void e() { public void broadcastFullState() {
super.e(); super.broadcastFullState();
if (cost >= 0) { if (cost >= 0) {
this.setLevelCost(cost); this.setLevelCost(cost);
@ -112,17 +112,17 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
@Override @Override
public void update() { public void update() {
e(); broadcastFullState();
} }
@Override @Override
public String getRenameText() { public String getRenameText() {
return this.v; return this.itemName;
} }
@Override @Override
public void setRenameText(String text) { public void setRenameText(String text) {
this.a(text); this.setItemName(text);
} }
@Override @Override
@ -140,7 +140,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.customTitle = title; this.customTitle = title;
try { try {
mc_Container_title.set(this, new ChatMessage(customTitle != null ? customTitle : "")); mc_Container_title.set(this, new TranslatableComponent(customTitle != null ? customTitle : ""));
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex);
} }
@ -203,12 +203,12 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
@Override @Override
public void open() { public void open() {
// Send the packet // Send the packet
entity.b.a(new PacketPlayOutOpenWindow(j, Containers.h, new ChatMessage(customTitle != null ? customTitle : ""))); entity.connection.send(new ClientboundOpenScreenPacket(super.containerId, MenuType.ANVIL, new TranslatableComponent(customTitle != null ? customTitle : "")));
// Set their active container to this anvil // Set their active container to this anvil
entity.bW = this; entity.containerMenu = this;
// Add the slot listener // Add the slot listener
entity.a(entity.bW); entity.initMenu(entity.containerMenu);
} }
} }

View File

@ -8,6 +8,6 @@ import org.bukkit.entity.Player;
public class NMSPlayerImpl implements NMSPlayer { public class NMSPlayerImpl implements NMSPlayer {
@Override @Override
public void sendPacket(Player p, Object packet) { public void sendPacket(Player p, Object packet) {
((CraftPlayer) p).getHandle().b.a((Packet<?>) packet); ((CraftPlayer) p).getHandle().connection.send((Packet<?>) packet);
} }
} }

View File

@ -2,98 +2,96 @@ package com.songoda.core.nms.v1_18_R1.nbt;
import com.songoda.core.nms.nbt.NBTCompound; import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTObject; import com.songoda.core.nms.nbt.NBTObject;
import net.minecraft.nbt.NBTCompressedStreamTools; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NbtIo;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class NBTCompoundImpl implements NBTCompound { public class NBTCompoundImpl implements NBTCompound {
protected NBTTagCompound compound; protected CompoundTag compound;
protected NBTCompoundImpl(NBTTagCompound compound) { protected NBTCompoundImpl(CompoundTag compound) {
this.compound = compound; this.compound = compound;
} }
public NBTCompoundImpl() { public NBTCompoundImpl() {
this.compound = new NBTTagCompound(); this.compound = new CompoundTag();
} }
@Override @Override
public NBTCompound set(String tag, String s) { public NBTCompound set(String tag, String s) {
compound.a(tag, s); compound.putString(tag, s);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, boolean b) { public NBTCompound set(String tag, boolean b) {
compound.a(tag, b); compound.putBoolean(tag, b);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, int i) { public NBTCompound set(String tag, int i) {
compound.a(tag, i); compound.putInt(tag, i);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, double i) { public NBTCompound set(String tag, double i) {
compound.a(tag, i); compound.putDouble(tag, i);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, long l) { public NBTCompound set(String tag, long l) {
compound.a(tag, l); compound.putLong(tag, l);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, short s) { public NBTCompound set(String tag, short s) {
compound.a(tag, s); compound.putShort(tag, s);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, byte b) { public NBTCompound set(String tag, byte b) {
compound.a(tag, b); compound.putByte(tag, b);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, int[] i) { public NBTCompound set(String tag, int[] i) {
compound.a(tag, i); compound.putIntArray(tag, i);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, byte[] b) { public NBTCompound set(String tag, byte[] b) {
compound.a(tag, b); compound.putByteArray(tag, b);
return this; return this;
} }
@Override @Override
public NBTCompound set(String tag, UUID u) { public NBTCompound set(String tag, UUID u) {
compound.a(tag, u); compound.putUUID(tag, u);
return this; return this;
} }
@Override @Override
public NBTCompound remove(String tag) { public NBTCompound remove(String tag) {
compound.r(tag); compound.remove(tag);
return this; return this;
} }
@Override @Override
public boolean has(String tag) { public boolean has(String tag) {
return compound.e(tag); return compound.contains(tag);
} }
@Override @Override
@ -152,19 +150,19 @@ public class NBTCompoundImpl implements NBTCompound {
return getNBTObject(tag).asCompound(); return getNBTObject(tag).asCompound();
} }
NBTTagCompound newCompound = new NBTTagCompound(); CompoundTag newCompound = new CompoundTag();
compound.a(tag, newCompound); compound.put(tag, newCompound);
return new NBTCompoundImpl(newCompound); return new NBTCompoundImpl(newCompound);
} }
@Override @Override
public Set<String> getKeys() { public Set<String> getKeys() {
return compound.d(); return compound.getAllKeys();
} }
@Override @Override
public Set<String> getKeys(String tag) { public Set<String> getKeys(String tag) {
return compound.p(tag).d(); return compound.getCompound(tag).getAllKeys();
} }
@Override @Override
@ -172,13 +170,13 @@ public class NBTCompoundImpl implements NBTCompound {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) { ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
addExtras(); addExtras();
NBTTagCompound compound = this.compound.g(); CompoundTag compound = this.compound.copy();
for (String exclusion : exclusions) { for (String exclusion : exclusions) {
compound.r(exclusion); compound.remove(exclusion);
} }
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput); NbtIo.writeCompressed(compound, dataOutput);
return outputStream.toByteArray(); return outputStream.toByteArray();
} catch (Exception ex) { } catch (Exception ex) {
@ -192,7 +190,7 @@ public class NBTCompoundImpl implements NBTCompound {
public void deSerialize(byte[] serialized) { public void deSerialize(byte[] serialized) {
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized); try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) { ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
compound = NBTCompressedStreamTools.a((InputStream) dataInput); compound = NbtIo.readCompressed(dataInput);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }

View File

@ -3,7 +3,7 @@ package com.songoda.core.nms.v1_18_R1.nbt;
import com.songoda.core.nms.nbt.NBTCore; import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.nbt.NBTEntity; import com.songoda.core.nms.nbt.NBTEntity;
import com.songoda.core.nms.nbt.NBTItem; import com.songoda.core.nms.nbt.NBTItem;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundTag;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -25,14 +25,14 @@ public class NBTCoreImpl implements NBTCore {
@Override @Override
public NBTEntity of(Entity entity) { public NBTEntity of(Entity entity) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle(); net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
NBTTagCompound nbt = new NBTTagCompound(); CompoundTag nbt = new CompoundTag();
nmsEntity.f(nbt); nmsEntity.saveWithoutId(nbt);
return new NBTEntityImpl(nbt, nmsEntity); return new NBTEntityImpl(nbt, nmsEntity);
} }
@Override @Override
public NBTEntity newEntity() { public NBTEntity newEntity() {
return new NBTEntityImpl(new NBTTagCompound(), null); return new NBTEntityImpl(new CompoundTag(), null);
} }
} }

View File

@ -1,12 +1,12 @@
package com.songoda.core.nms.v1_18_R1.nbt; package com.songoda.core.nms.v1_18_R1.nbt;
import com.songoda.core.nms.nbt.NBTEntity; import com.songoda.core.nms.nbt.NBTEntity;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.core.IRegistry; import net.minecraft.core.Registry;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EnumMobSpawn; import net.minecraft.world.entity.MobSpawnType;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
@ -15,7 +15,7 @@ import java.util.Optional;
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
private Entity nmsEntity; private Entity nmsEntity;
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) { public NBTEntityImpl(CompoundTag entityNBT, Entity nmsEntity) {
super(entityNBT); super(entityNBT);
this.nmsEntity = nmsEntity; this.nmsEntity = nmsEntity;
@ -25,23 +25,23 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
public org.bukkit.entity.Entity spawn(Location location) { public org.bukkit.entity.Entity spawn(Location location) {
String entityType = getNBTObject("entity_type").asString(); String entityType = getNBTObject("entity_type").asString();
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType); Optional<EntityType<?>> optionalEntity = EntityType.byString(entityType);
if (optionalEntity.isPresent()) { if (optionalEntity.isPresent()) {
assert location.getWorld() != null; assert location.getWorld() != null;
Entity spawned = optionalEntity.get().a( Entity spawned = optionalEntity.get().spawn(
((CraftWorld) location.getWorld()).getHandle(), ((CraftWorld) location.getWorld()).getHandle(),
compound, compound,
null, null,
null, null,
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
EnumMobSpawn.n, MobSpawnType.COMMAND,
true, true,
false false
); );
if (spawned != null) { if (spawned != null) {
spawned.g(compound); spawned.load(compound);
org.bukkit.entity.Entity entity = spawned.getBukkitEntity(); org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
entity.teleport(location); entity.teleport(location);
nmsEntity = spawned; nmsEntity = spawned;
@ -55,12 +55,12 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
@Override @Override
public org.bukkit.entity.Entity reSpawn(Location location) { public org.bukkit.entity.Entity reSpawn(Location location) {
nmsEntity.ah(); nmsEntity.discard();
return spawn(location); return spawn(location);
} }
@Override @Override
public void addExtras() { public void addExtras() {
compound.a("entity_type", IRegistry.Z.b(nmsEntity.ad()).toString()); compound.putString("entity_type", Registry.ENTITY_TYPE.getKey(nmsEntity.getType()).toString());
} }
} }

View File

@ -1,22 +1,22 @@
package com.songoda.core.nms.v1_18_R1.nbt; package com.songoda.core.nms.v1_18_R1.nbt;
import com.songoda.core.nms.nbt.NBTItem; import com.songoda.core.nms.nbt.NBTItem;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class NBTItemImpl extends NBTCompoundImpl implements NBTItem { public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
private final net.minecraft.world.item.ItemStack nmsItem; private final ItemStack nmsItem;
public NBTItemImpl(net.minecraft.world.item.ItemStack nmsItem) { public NBTItemImpl(ItemStack nmsItem) {
super(nmsItem != null && nmsItem.r() ? nmsItem.s() : new NBTTagCompound()); super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new CompoundTag());
this.nmsItem = nmsItem; this.nmsItem = nmsItem;
} }
public ItemStack finish() { public org.bukkit.inventory.ItemStack finish() {
if (nmsItem == null) { if (nmsItem == null) {
return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.a(compound)); return CraftItemStack.asBukkitCopy(ItemStack.of(compound));
} }
return CraftItemStack.asBukkitCopy(nmsItem); return CraftItemStack.asBukkitCopy(nmsItem);

View File

@ -2,71 +2,71 @@ package com.songoda.core.nms.v1_18_R1.nbt;
import com.songoda.core.nms.nbt.NBTCompound; import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTObject; import com.songoda.core.nms.nbt.NBTObject;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundTag;
import java.util.Set; import java.util.Set;
public class NBTObjectImpl implements NBTObject { public class NBTObjectImpl implements NBTObject {
private final NBTTagCompound compound; private final CompoundTag compound;
private final String tag; private final String tag;
public NBTObjectImpl(NBTTagCompound compound, String tag) { public NBTObjectImpl(CompoundTag compound, String tag) {
this.compound = compound; this.compound = compound;
this.tag = tag; this.tag = tag;
} }
@Override @Override
public String asString() { public String asString() {
return compound.l(tag); return compound.getString(tag);
} }
@Override @Override
public boolean asBoolean() { public boolean asBoolean() {
return compound.q(tag); return compound.getBoolean(tag);
} }
@Override @Override
public int asInt() { public int asInt() {
return compound.h(tag); return compound.getInt(tag);
} }
@Override @Override
public double asDouble() { public double asDouble() {
return compound.k(tag); return compound.getDouble(tag);
} }
@Override @Override
public long asLong() { public long asLong() {
return compound.i(tag); return compound.getLong(tag);
} }
@Override @Override
public short asShort() { public short asShort() {
return compound.g(tag); return compound.getShort(tag);
} }
@Override @Override
public byte asByte() { public byte asByte() {
return compound.f(tag); return compound.getByte(tag);
} }
@Override @Override
public int[] asIntArray() { public int[] asIntArray() {
return compound.n(tag); return compound.getIntArray(tag);
} }
@Override @Override
public byte[] asByteArray() { public byte[] asByteArray() {
return compound.m(tag); return compound.getByteArray(tag);
} }
@Override @Override
public NBTCompound asCompound() { public NBTCompound asCompound() {
return new NBTCompoundImpl(compound.p(tag)); return new NBTCompoundImpl(compound.getCompound(tag));
} }
@Override @Override
public Set<String> getKeys() { public Set<String> getKeys() {
return compound.d(); return compound.getAllKeys();
} }
} }

View File

@ -25,15 +25,15 @@ public class NmsWorldBorderImpl implements NmsWorldBorder {
WorldBorder worldBorder = new WorldBorder(); WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle(); worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.c(center.getX(), center.getZ()); // setCenter worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.a(size); // setSize worldBorder.setSize(size);
worldBorder.b(0); // setWarningTime worldBorder.setWarningTime(0);
worldBorder.c(0); // setWarningDistance worldBorder.setWarningBlocks(0);
if (color == BorderColor.GREEN) { if (color == BorderColor.GREEN) {
worldBorder.a(size - 0.1D, size, Long.MAX_VALUE); // transitionSizeBetween worldBorder.lerpSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) { } else if (color == BorderColor.RED) {
worldBorder.a(size, size - 1.0D, Long.MAX_VALUE); // transitionSizeBetween worldBorder.lerpSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
} }
this.nmsPlayer.sendPacket(player, new ClientboundInitializeBorderPacket(worldBorder)); this.nmsPlayer.sendPacket(player, new ClientboundInitializeBorderPacket(worldBorder));

View File

@ -1,10 +1,10 @@
package com.songoda.core.nms.v1_18_R1.world; package com.songoda.core.nms.v1_18_R1.world;
import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SItemStack;
import net.minecraft.core.particles.ParticleParamItem; import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.Particles; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.Vec3;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -19,21 +19,21 @@ public class SItemStackImpl implements SItemStack {
@Override @Override
public void breakItem(Player player, int amount) { public void breakItem(Player player, int amount) {
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
for (int i = 0; i < amount; ++i) { for (int i = 0; i < amount; ++i) {
Vec3D vec3d = new Vec3D(((double) random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); Vec3 vec3d = new Vec3(((double) random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
vec3d = vec3d.a(-entityPlayer.dn() * 0.017453292F); vec3d = vec3d.xRot(-entityPlayer.getXRot() * 0.017453292F);
vec3d = vec3d.b(-entityPlayer.dm() * 0.017453292F); vec3d = vec3d.yRot(-entityPlayer.getYRot() * 0.017453292F);
double d0 = (double) (-random.nextFloat()) * 0.6D - 0.3D; double d0 = (double) (-random.nextFloat()) * 0.6D - 0.3D;
Vec3D vec3d1 = new Vec3D(((double) random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); Vec3 vec3d1 = new Vec3(((double) random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
vec3d1 = vec3d1.a(-entityPlayer.dn() * 0.017453292F); vec3d1 = vec3d1.xRot(-entityPlayer.getXRot() * 0.017453292F);
vec3d1 = vec3d1.b(-entityPlayer.dm() * 0.017453292F); vec3d1 = vec3d1.yRot(-entityPlayer.getYRot() * 0.017453292F);
vec3d1 = vec3d1.b(entityPlayer.dc(), entityPlayer.dg(), entityPlayer.di()); vec3d1 = vec3d1.add(entityPlayer.getX(), entityPlayer.getEyeY(), entityPlayer.getZ());
entityPlayer.t.a(new ParticleParamItem(Particles.J, CraftItemStack.asNMSCopy(item)), vec3d1.b, vec3d1.c, vec3d1.d, vec3d.b, vec3d.c + 0.05D, vec3d.d); entityPlayer.level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z);
} }
} }
} }

View File

@ -4,15 +4,14 @@ import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleParticleHandler; import com.songoda.core.compatibility.CompatibleParticleHandler;
import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SSpawner;
import com.songoda.core.nms.world.SpawnedEntity; import com.songoda.core.nms.world.SpawnedEntity;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.WorldServer; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.DifficultyDamageScaler; import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.EnumMobSpawn; import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.MobSpawnerData;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
@ -37,35 +36,35 @@ public class SSpawnerImpl implements SSpawner {
} }
@Override @Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
Set<CompatibleMaterial> canSpawnOn) { SpawnData data = new SpawnData();
MobSpawnerData data = new MobSpawnerData(); CompoundTag compound = data.getEntityToSpawn();
NBTTagCompound compound = data.a();
String name = type.name().toLowerCase().replace("snowman", "snow_golem") String name = type.name().toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom"); .replace("mushroom_cow", "mooshroom");
compound.a("id", "minecraft:" + name); compound.putString("id", "minecraft:" + name);
short spawnRange = 4; short spawnRange = 4;
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null; assert spawnerLocation.getWorld() != null;
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle(); ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
Random random = world.r_(); Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D; double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1; double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D; double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world); Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue; if (optionalEntity.isEmpty()) continue;
Entity entity = optionalEntity.get(); Entity entity = optionalEntity.get();
entity.e(x, y, z); entity.setPos(x, y, z);
BlockPosition position = entity.cW(); BlockPos position = entity.blockPosition();
DifficultyDamageScaler damageScaler = world.d_(position); DifficultyInstance damageScaler = world.getCurrentDifficultyAt(position);
if (!(entity instanceof EntityInsentient entityInsentient)) { if (!(entity instanceof Mob entityInsentient)) {
continue; continue;
} }
@ -75,7 +74,7 @@ public class SSpawnerImpl implements SSpawner {
continue; continue;
} }
entityInsentient.a(world, damageScaler, EnumMobSpawn.c, null, null); entityInsentient.finalizeSpawn(world, damageScaler, MobSpawnType.SPAWNER, null, null);
LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity();
@ -103,9 +102,8 @@ public class SSpawnerImpl implements SSpawner {
return null; return null;
} }
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
Set<CompatibleMaterial> canSpawnOn) { if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
if (!world.a(entityInsentient, entityInsentient.cw())) {
return false; return false;
} }

View File

@ -1,10 +1,10 @@
package com.songoda.core.nms.v1_18_R1.world; package com.songoda.core.nms.v1_18_R1.world;
import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.SWorld;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.WorldServer; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.Chunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.entity.LevelEntityGetter; import net.minecraft.world.level.entity.LevelEntityGetter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -26,10 +26,10 @@ public class SWorldImpl implements SWorld {
public List<LivingEntity> getLivingEntities() { public List<LivingEntity> getLivingEntities() {
List<LivingEntity> result = new ArrayList<>(); List<LivingEntity> result = new ArrayList<>();
WorldServer worldServer = ((CraftWorld) this.world).getHandle(); ServerLevel worldServer = ((CraftWorld) this.world).getHandle();
LevelEntityGetter<net.minecraft.world.entity.Entity> entities = worldServer.P.d(); LevelEntityGetter<net.minecraft.world.entity.Entity> entities = worldServer.entityManager.getEntityGetter();
entities.a().forEach((mcEnt) -> { entities.getAll().forEach((mcEnt) -> {
org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity(); org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity();
if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) { if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) {
@ -42,10 +42,10 @@ public class SWorldImpl implements SWorld {
@Override @Override
public void setBlockFast(int x, int y, int z, Material material) { public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle(); ServerLevel serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4); LevelChunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState(); BlockState blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true); levelChunk.setBlockState(new BlockPos(x & 0xF, y, z & 0xF), blockState, true);
} }
} }

View File

@ -7,16 +7,16 @@ import com.songoda.core.nms.world.SItemStack;
import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SSpawner;
import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.SWorld;
import com.songoda.core.nms.world.WorldCore; import com.songoda.core.nms.world.WorldCore;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.WorldServer; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.GameProfilerFiller; import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.MobSpawnerAbstract; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.Chunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.ChunkSection; import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
@ -53,61 +53,61 @@ public class WorldCoreImpl implements WorldCore {
public BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, IllegalAccessException { public BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, IllegalAccessException {
Object cTileEntity = ReflectionUtils.getFieldValue(spawner, "tileEntity"); Object cTileEntity = ReflectionUtils.getFieldValue(spawner, "tileEntity");
return new BBaseSpawnerImpl(spawner, (MobSpawnerAbstract) ReflectionUtils.getFieldValue(cTileEntity, "a")); return new BBaseSpawnerImpl(spawner, (BaseSpawner) ReflectionUtils.getFieldValue(cTileEntity, "a"));
} }
/** /**
* Method is based on {@link WorldServer#a(Chunk, int)}. * Method is based on {@link ServerLevel#tickChunk(LevelChunk, int)}.
*/ */
@Override @Override
public void randomTickChunk(org.bukkit.Chunk bukkitChunk, int tickAmount) { public void randomTickChunk(org.bukkit.Chunk bukkitChunk, int tickAmount) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); LevelChunk chunk = ((CraftChunk) bukkitChunk).getHandle();
WorldServer world = chunk.q; ServerLevel world = chunk.q;
ChunkCoordIntPair chunkcoordintpair = chunk.f(); ChunkPos chunkcoordintpair = chunk.getPos();
int j = chunkcoordintpair.d(); int j = chunkcoordintpair.getMinBlockX();
int k = chunkcoordintpair.e(); int k = chunkcoordintpair.getMinBlockZ();
GameProfilerFiller gameprofilerfiller = world.ab(); ProfilerFiller gameprofilerfiller = world.getProfiler();
gameprofilerfiller.b("tickBlocks"); gameprofilerfiller.popPush("tickBlocks");
if (tickAmount > 0) { if (tickAmount > 0) {
ChunkSection[] achunksection = chunk.d(); LevelChunkSection[] achunksection = chunk.getSections();
int l = achunksection.length; int l = achunksection.length;
for (ChunkSection chunksection : achunksection) { for (LevelChunkSection chunksection : achunksection) {
if (chunksection.d()) { if (chunksection.isRandomlyTicking()) {
int j1 = chunksection.g(); int j1 = chunksection.bottomBlockY();
for (int k1 = 0; k1 < tickAmount; ++k1) { for (int k1 = 0; k1 < tickAmount; ++k1) {
BlockPosition blockposition2 = world.a(j, j1, k, 15); BlockPos blockposition2 = world.getBlockRandomPos(j, j1, k, 15);
gameprofilerfiller.a("randomTick"); gameprofilerfiller.push("randomTick");
IBlockData iblockdata1 = chunksection.a(blockposition2.u() - j, blockposition2.v() - j1, blockposition2.w() - k); BlockState iblockdata1 = chunksection.getBlockState(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k);
if (iblockdata1.o()) { if (iblockdata1.isRandomlyTicking()) {
iblockdata1.b(world, blockposition2, world.w); iblockdata1.randomTick(world, blockposition2, world.random);
} }
Fluid fluid = iblockdata1.n(); FluidState fluid = iblockdata1.getFluidState();
if (fluid.f()) { if (fluid.isRandomlyTicking()) {
fluid.b(world, blockposition2, world.w); fluid.randomTick(world, blockposition2, world.random);
} }
gameprofilerfiller.c(); gameprofilerfiller.pop();
} }
} }
} }
} }
gameprofilerfiller.c(); gameprofilerfiller.pop();
} }
@Override @Override
public void updateAdjacentComparators(@NotNull Location loc) { public void updateAdjacentComparators(@NotNull Location loc) {
Objects.requireNonNull(loc.getWorld()); Objects.requireNonNull(loc.getWorld());
WorldServer serverLevel = ((CraftWorld) loc.getWorld()).getHandle(); ServerLevel serverLevel = ((CraftWorld) loc.getWorld()).getHandle();
BlockPosition blockPos = new BlockPosition(loc.getX(), loc.getY(), loc.getZ()); BlockPos blockPos = new BlockPos(loc.getX(), loc.getY(), loc.getZ());
Block nmsBlock = ((CraftBlock) loc.getBlock()).getNMS().b(); Block nmsBlock = ((CraftBlock) loc.getBlock()).getNMS().getBlock();
serverLevel.c(blockPos, nmsBlock); serverLevel.updateNeighbourForOutputSignal(blockPos, nmsBlock);
} }
} }

View File

@ -1,21 +1,21 @@
package com.songoda.core.nms.v1_18_R1.world.spawner; package com.songoda.core.nms.v1_18_R1.world.spawner;
import com.songoda.core.nms.world.BBaseSpawner; import com.songoda.core.nms.world.BBaseSpawner;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.ListTag;
import net.minecraft.server.level.WorldServer; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.EnumDifficulty; import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EntityPositionTypes; import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.EnumMobSpawn; import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.level.EnumSkyBlock; import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.MobSpawnerAbstract; import net.minecraft.world.level.Level;
import net.minecraft.world.level.MobSpawnerData; import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.World; import net.minecraft.world.level.SpawnData;
import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.AABB;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.block.CraftCreatureSpawner; import org.bukkit.craftbukkit.v1_18_R1.block.CraftCreatureSpawner;
@ -27,40 +27,45 @@ import java.util.Random;
public class BBaseSpawnerImpl implements BBaseSpawner { public class BBaseSpawnerImpl implements BBaseSpawner {
private final CreatureSpawner bukkitSpawner; private final CreatureSpawner bukkitSpawner;
private final MobSpawnerAbstract spawner; private final BaseSpawner spawner;
private static final Random spawnerFieldO = new Random(); // Field o in MobSpawnerAbstract is private - We use one random for *all* our spawners (should be fine, right?) private static final Random spawnerFieldO = new Random(); // Field random in BaseSpawner is private - We use one random for *all* our spawners (should be fine, right?)
public BBaseSpawnerImpl(CreatureSpawner bukkitSpawner, MobSpawnerAbstract spawner) { public BBaseSpawnerImpl(CreatureSpawner bukkitSpawner, BaseSpawner spawner) {
this.bukkitSpawner = bukkitSpawner; this.bukkitSpawner = bukkitSpawner;
this.spawner = spawner; this.spawner = spawner;
} }
/** /**
* This method is based on {@link MobSpawnerAbstract#b(World, BlockPosition)}. * This method is based on {@link BaseSpawner#isNearPlayer(Level, BlockPos)}.
*/ */
@SuppressWarnings("JavadocReference") @SuppressWarnings("JavadocReference")
@Override @Override
public boolean isNearPlayer() { public boolean isNearPlayer() {
BlockPosition bPos = getBlockPosition(); BlockPos bPos = getBlockPosition();
return getWorld().a((double) bPos.u() + 0.5D, (double) bPos.v() + 0.5D, (double) bPos.w() + 0.5D, this.spawner.m); return getWorld().hasNearbyAlivePlayer(
(double) bPos.getX() + 0.5D,
(double) bPos.getY() + 0.5D,
(double) bPos.getZ() + 0.5D,
this.spawner.requiredPlayerRange
);
} }
/** /**
* This method is based on {@link MobSpawnerAbstract#a(WorldServer, BlockPosition)}. * This method is based on {@link BaseSpawner#serverTick(ServerLevel, BlockPos)}.
*/ */
@Override @Override
public void tick() { public void tick() {
WorldServer world = getWorld(); ServerLevel world = getWorld();
BlockPosition bPos = getBlockPosition(); BlockPos bPos = getBlockPosition();
if (this.spawner.c == -1) { if (this.spawner.spawnDelay == -1) {
this.delay(world, bPos); this.delay(world, bPos);
} }
if (this.spawner.c > 0) { if (this.spawner.spawnDelay > 0) {
--this.spawner.c; --this.spawner.spawnDelay;
return; return;
} }
@ -68,44 +73,45 @@ public class BBaseSpawnerImpl implements BBaseSpawner {
int i = 0; int i = 0;
while (true) { while (true) {
if (i >= this.spawner.j) { if (i >= this.spawner.spawnCount) {
if (flag) { if (flag) {
this.delay(world, bPos); this.delay(world, bPos);
} }
break; break;
} }
NBTTagCompound nbttagcompound = this.spawner.e.a(); CompoundTag nbttagcompound = this.spawner.nextSpawnData.getEntityToSpawn();
Optional<EntityTypes<?>> optional = EntityTypes.a(nbttagcompound); Optional<EntityType<?>> optional = EntityType.by(nbttagcompound);
if (optional.isEmpty()) { if (optional.isEmpty()) {
this.delay(world, bPos); this.delay(world, bPos);
return; return;
} }
NBTTagList nbttaglist = nbttagcompound.c("Pos", 6); ListTag nbttaglist = nbttagcompound.getList("Pos", 6);
int j = nbttaglist.size(); int j = nbttaglist.size();
double d0 = j >= 1 ? nbttaglist.h(0) : (double) bPos.u() + (world.w.nextDouble() - world.w.nextDouble()) * (double) this.spawner.n + 0.5D; double d0 = j >= 1 ? nbttaglist.getDouble(0) : (double) bPos.getX() + (world.random.nextDouble() - world.random.nextDouble()) * (double) this.spawner.spawnRange + 0.5D;
double d1 = j >= 2 ? nbttaglist.h(1) : (double) (bPos.v() + world.w.nextInt(3) - 1); double d1 = j >= 2 ? nbttaglist.getDouble(1) : (double) (bPos.getY() + world.random.nextInt(3) - 1);
double d2 = j >= 3 ? nbttaglist.h(2) : (double) bPos.w() + (world.w.nextDouble() - world.w.nextDouble()) * (double) this.spawner.n + 0.5D; double d2 = j >= 3 ? nbttaglist.getDouble(2) : (double) bPos.getZ() + (world.random.nextDouble() - world.random.nextDouble()) * (double) this.spawner.spawnRange + 0.5D;
if (world.b(optional.get().a(d0, d1, d2))) { if (world.noCollision(optional.get().getAABB(d0, d1, d2))) {
label128: label128:
{ {
BlockPosition blockposition1 = new BlockPosition(d0, d1, d2); BlockPos blockposition1 = new BlockPos(d0, d1, d2);
if (this.spawner.e.b().isPresent()) { if (this.spawner.nextSpawnData.getCustomSpawnRules().isPresent()) {
if (!optional.get().f().d() && world.af() == EnumDifficulty.a) { if (!optional.get().getCategory().isFriendly() && world.getDifficulty() == Difficulty.PEACEFUL) {
break label128; break label128;
} }
MobSpawnerData.a mobspawnerdata_a = this.spawner.e.b().get(); SpawnData.CustomSpawnRules mobspawnerdata_a = this.spawner.nextSpawnData.getCustomSpawnRules().get();
if (!mobspawnerdata_a.a().a(world.a(EnumSkyBlock.b, blockposition1)) || !mobspawnerdata_a.b().a(world.a(EnumSkyBlock.a, blockposition1))) { if (!mobspawnerdata_a.blockLightLimit().isValueInRange(world.getBrightness(LightLayer.BLOCK, blockposition1)) ||
!mobspawnerdata_a.skyLightLimit().isValueInRange(world.getBrightness(LightLayer.SKY, blockposition1))) {
break label128; break label128;
} }
} else if (!EntityPositionTypes.a((EntityTypes<?>) optional.get(), world, EnumMobSpawn.c, blockposition1, world.r_())) { } else if (!SpawnPlacements.checkSpawnRules(optional.get(), world, MobSpawnType.SPAWNER, blockposition1, world.getRandom())) {
break label128; break label128;
} }
Entity entity = EntityTypes.a(nbttagcompound, world, (entity1) -> { Entity entity = EntityType.loadEntityRecursive(nbttagcompound, world, (entity1) -> {
entity1.b(d0, d1, d2, entity1.dm(), entity1.dn()); entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot());
return entity1; return entity1;
}); });
if (entity == null) { if (entity == null) {
@ -113,35 +119,35 @@ public class BBaseSpawnerImpl implements BBaseSpawner {
return; return;
} }
int k = world.a(entity.getClass(), (new AxisAlignedBB(bPos.u(), bPos.v(), bPos.w(), bPos.u() + 1, bPos.v() + 1, bPos.w() + 1)).g(this.spawner.n)).size(); int k = world.getEntitiesOfClass(entity.getClass(), (new AABB(bPos.getX(), bPos.getY(), bPos.getZ(), bPos.getX() + 1, bPos.getY() + 1, bPos.getZ() + 1)).inflate(this.spawner.spawnRange)).size();
if (k >= this.spawner.l) { if (k >= this.spawner.maxNearbyEntities) {
this.delay(world, bPos); this.delay(world, bPos);
return; return;
} }
entity.b(entity.dc(), entity.de(), entity.di(), world.w.nextFloat() * 360.0F, 0.0F); entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), world.random.nextFloat() * 360.0F, 0.0F);
if (entity instanceof EntityInsentient entityinsentient) { if (entity instanceof Mob entityInsentient) {
if (this.spawner.e.b().isEmpty() && !entityinsentient.a(world, EnumMobSpawn.c) || !entityinsentient.a(world)) { if (this.spawner.nextSpawnData.getCustomSpawnRules().isEmpty() && !entityInsentient.checkSpawnRules(world, MobSpawnType.SPAWNER) || !entityInsentient.checkSpawnObstruction(world)) {
break label128; break label128;
} }
if (this.spawner.e.a().e() == 1 && this.spawner.e.a().b("id", 8)) { if (this.spawner.nextSpawnData.getEntityToSpawn().size() == 1 && this.spawner.nextSpawnData.getEntityToSpawn().contains("id", 8)) {
((EntityInsentient) entity).a(world, world.d_(entity.cW()), EnumMobSpawn.c, null, null); ((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null);
} }
if (entityinsentient.t.spigotConfig.nerfSpawnerMobs) { if (entityInsentient.level.spigotConfig.nerfSpawnerMobs) {
entityinsentient.aware = false; entityInsentient.aware = false;
} }
} }
if (CraftEventFactory.callSpawnerSpawnEvent(entity, bPos).isCancelled()) { if (CraftEventFactory.callSpawnerSpawnEvent(entity, bPos).isCancelled()) {
Entity vehicle = entity.cN(); Entity vehicle = entity.getVehicle();
if (vehicle != null) { if (vehicle != null) {
vehicle.ah(); vehicle.discard();
} }
for (Entity passenger : entity.cJ()) { for (Entity passenger : entity.getIndirectPassengers()) {
passenger.ah(); passenger.discard();
} }
} else { } else {
if (!world.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) { if (!world.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) {
@ -149,9 +155,9 @@ public class BBaseSpawnerImpl implements BBaseSpawner {
return; return;
} }
world.c(2004, bPos, 0); world.levelEvent(2004, bPos, 0);
if (entity instanceof EntityInsentient) { if (entity instanceof Mob) {
((EntityInsentient) entity).L(); ((Mob) entity).spawnAnim();
} }
flag = true; flag = true;
@ -164,27 +170,25 @@ public class BBaseSpawnerImpl implements BBaseSpawner {
} }
/** /**
* This method is based on {@link MobSpawnerAbstract#c(World, BlockPosition)}. * This method is based on {@link BaseSpawner#delay(Level, BlockPos)}.
*/ */
@SuppressWarnings("JavadocReference") @SuppressWarnings("JavadocReference")
private void delay(WorldServer world, BlockPosition bPos) { private void delay(ServerLevel world, BlockPos bPos) {
if (this.spawner.i <= this.spawner.h) { if (this.spawner.maxSpawnDelay <= this.spawner.minSpawnDelay) {
this.spawner.c = this.spawner.h; this.spawner.spawnDelay = this.spawner.minSpawnDelay;
} else { } else {
this.spawner.c = this.spawner.h + spawnerFieldO.nextInt(this.spawner.i - this.spawner.h); this.spawner.spawnDelay = this.spawner.minSpawnDelay + spawnerFieldO.nextInt(this.spawner.maxSpawnDelay - this.spawner.minSpawnDelay);
} }
this.spawner.d.b(spawnerFieldO).ifPresent((weightedentry_b) -> { this.spawner.spawnPotentials.getRandom(spawnerFieldO).ifPresent((weightedentry_b) -> this.spawner.setNextSpawnData(world, bPos, weightedentry_b.getData()));
this.spawner.a(world, bPos, weightedentry_b.b()); this.spawner.broadcastEvent(world, bPos, 1);
});
this.spawner.a(world, bPos, 1);
} }
private WorldServer getWorld() { private ServerLevel getWorld() {
return ((CraftWorld) this.bukkitSpawner.getWorld()).getHandle(); return ((CraftWorld) this.bukkitSpawner.getWorld()).getHandle();
} }
private BlockPosition getBlockPosition() { private BlockPos getBlockPosition() {
return ((CraftCreatureSpawner) this.bukkitSpawner).getPosition(); return ((CraftCreatureSpawner) this.bukkitSpawner).getPosition();
} }
} }

View File

@ -40,7 +40,8 @@ public class SSpawnerImpl implements SSpawner {
SpawnData data = new SpawnData(); SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn(); CompoundTag compound = data.getEntityToSpawn();
String name = type.name().toLowerCase().replace("snowman", "snow_golem") String name = type.name().toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom"); .replace("mushroom_cow", "mooshroom");
compound.putString("id", "minecraft:" + name); compound.putString("id", "minecraft:" + name);