Support spawning item stacks
This commit is contained in:
parent
d7d74c552e
commit
b63c890ec2
|
@ -5,10 +5,10 @@ Subject: [PATCH] Mob Spawner API Enhancements
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/block/CreatureSpawner.java b/src/main/java/org/bukkit/block/CreatureSpawner.java
|
||||
index cb447a4ad5a9dce7c98999a5d7fcd6111fc9b10e..35a599ebe9a35dc9570d546d73622da87cb136c4 100644
|
||||
index cb447a4ad5a9dce7c98999a5d7fcd6111fc9b10e..5bbae759ce39d42886994e500fd9454ec328f804 100644
|
||||
--- a/src/main/java/org/bukkit/block/CreatureSpawner.java
|
||||
+++ b/src/main/java/org/bukkit/block/CreatureSpawner.java
|
||||
@@ -199,4 +199,18 @@ public interface CreatureSpawner extends TileState {
|
||||
@@ -199,4 +199,30 @@ public interface CreatureSpawner extends TileState {
|
||||
* @see #getSpawnRange()
|
||||
*/
|
||||
public void setSpawnRange(int spawnRange);
|
||||
|
@ -25,5 +25,17 @@ index cb447a4ad5a9dce7c98999a5d7fcd6111fc9b10e..35a599ebe9a35dc9570d546d73622da8
|
|||
+ * 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
|
||||
}
|
||||
|
|
|
@ -82,10 +82,25 @@ index c3a5db97fd85b31c6b4bce93527b9d0e16a79a45..c2e830db7aa2944a477624e149a3ba66
|
|||
nbttagcompound.setShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
|
||||
nbttagcompound.setShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
|
||||
index 5c4c3c70c7450a3e556d664a1bf6bcaf8e3a571c..e78e3804bad9b0b6004939cadf40465dec68fdba 100644
|
||||
index 5c4c3c70c7450a3e556d664a1bf6bcaf8e3a571c..0bf61322031734039115a93ead841d089ad134b9 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
|
||||
@@ -121,4 +121,16 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
|
||||
@@ -8,6 +8,14 @@ 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 {
|
||||
|
||||
@@ -121,4 +129,30 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
|
||||
public void setSpawnRange(int spawnRange) {
|
||||
this.getSnapshot().getSpawner().spawnRange = spawnRange;
|
||||
}
|
||||
|
@ -100,5 +115,19 @@ index 5c4c3c70c7450a3e556d664a1bf6bcaf8e3a571c..e78e3804bad9b0b6004939cadf40465d
|
|||
+ 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue