13
0
geforkt von Mirrors/Paper

Support spawning item stacks

Dieser Commit ist enthalten in:
Mariell Hoversholm 2020-11-14 19:11:20 +01:00
Ursprung d0f7408554
Commit 542d7df36b
2 geänderte Dateien mit 41 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -25,5 +25,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Resets the spawn delay timer within the min/max range
+ */
+ public void resetTimer();
+
+ /**
+ * Sets the {@link EntityType} to {@link EntityType#DROPPED_ITEM} and sets the data to the given
+ * {@link org.bukkit.inventory.ItemStack ItemStack}.
+ * <p>
+ * {@link #setSpawnCount(int)} does not dictate the amount of items in the stack spawned, but rather how many
+ * stacks should be spawned.
+ *
+ * @param itemStack The item to spawn. Must not {@link org.bukkit.Material#isAir be air}.
+ * @see #setSpawnedType(EntityType)
+ */
+ void setSpawnedItem(@NotNull org.bukkit.inventory.ItemStack itemStack);
+ // Paper end
}

Datei anzeigen

@ -85,6 +85,21 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.jav
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
@@ -0,0 +0,0 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
+// Paper start
+import net.minecraft.server.IRegistry;
+import net.minecraft.server.MobSpawnerData;
+import net.minecraft.server.NBTTagCompound;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+import org.bukkit.inventory.ItemStack;
+// Paper end
public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpawner> implements CreatureSpawner {
@@ -0,0 +0,0 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
public void setSpawnRange(int spawnRange) {
this.getSnapshot().getSpawner().spawnRange = spawnRange;
@ -100,5 +115,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public void resetTimer() {
+ this.getSnapshot().getSpawner().resetTimer();
+ }
+
+ @Override
+ public void setSpawnedItem(ItemStack itemStack) {
+ Preconditions.checkArgument(itemStack != null && !itemStack.getType().isAir(), "spawners cannot spawn air");
+ net.minecraft.server.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
+ NBTTagCompound compound = new NBTTagCompound();
+ NBTTagCompound entity = new NBTTagCompound();
+ entity.setString("id", IRegistry.ENTITY_TYPE.getKey(EntityTypes.ITEM).toString());
+ entity.set("Item", item.save(new NBTTagCompound()));
+ compound.set("Entity", entity);
+ compound.setInt("Weight", this.getSnapshotNBT().hasKeyOfType("Weight", CraftMagicNumbers.NBT.TAG_ANY_NUMBER) ? this.getSnapshotNBT().getInt("Weight") : 1);
+ this.getSnapshot().getSpawner().setSpawnData(new MobSpawnerData(compound));
+ this.getSnapshot().getSpawner().mobs.clear();
+ }
+ // Paper end
}