Created
June 26, 2013 14:49
-
-
Save ralmn/5867990 to your computer and use it in GitHub Desktop.
Spawner, config RUSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.ralmn.rush.object; | |
import net.minecraft.server.v1_5_R3.*; | |
import org.bukkit.ChatColor; | |
import org.bukkit.Location; | |
import org.bukkit.Material; | |
import org.bukkit.craftbukkit.v1_5_R3.CraftWorld; | |
import org.bukkit.craftbukkit.v1_5_R3.block.CraftBlock; | |
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: ralmn | |
* Date: 25/06/13 | |
* Time: 16:48 | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class Spawner { | |
private Location location; | |
private ItemStack item; | |
private int min_delay, max_delay; | |
public Spawner(Location location, ItemStack item, int min_delay, int max_delay) { | |
this.location = location; | |
this.item = item; | |
this.min_delay = min_delay; | |
this.max_delay = max_delay; | |
} | |
public Location getLocation() { | |
return location; | |
} | |
public void setLocation(Location location) { | |
this.location = location; | |
} | |
public ItemStack getItem() { | |
return item; | |
} | |
public void setItem(ItemStack item) { | |
this.item = item; | |
} | |
public int getMin_delay() { | |
return min_delay; | |
} | |
public void setMin_delay(int min_delay) { | |
this.min_delay = min_delay; | |
} | |
public int getMax_delay() { | |
return max_delay; | |
} | |
public void setMax_delay(int max_delay) { | |
this.max_delay = max_delay; | |
} | |
public void createSpawner(){ | |
CraftWorld cw = (CraftWorld) location.getWorld(); | |
CraftBlock cb = (CraftBlock) location.getBlock(); | |
cb.setType(Material.MOB_SPAWNER); | |
TileEntityMobSpawner te = (TileEntityMobSpawner) cw.getTileEntityAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); | |
MobSpawnerAbstract msa = te.a(); | |
//EntityItem itementiy = new EntityItem(cw.getHandle(), location.getX(), location.getY(),location.getZ(), CraftItemStack.asNMSCopy(this.item)); | |
//msa.a(itementiy); | |
NBTTagCompound tag = new NBTTagCompound(); | |
msa.b(tag); | |
tag.setString("EntityId", "Item"); | |
tag.setShort("MinSpawnDelay", (short) min_delay); | |
tag.setShort("MaxSpawnDelay", (short) max_delay); | |
tag.setShort("MaxNearbyEntities", (short) 360); | |
tag.setShort("RequiredPlayerRange", (short) 48); | |
tag.setShort("SpawnCount", (short) 1); | |
tag.setShort("Delay", (short) 0); | |
NBTTagCompound data = new NBTTagCompound(); | |
data.setShort("Age", (short) 0); | |
NBTTagList pos = new NBTTagList(); | |
pos.add(new NBTTagDouble("x", location.getX())); | |
pos.add(new NBTTagDouble("y", location.getY())); | |
pos.add(new NBTTagDouble("z", location.getZ())); | |
data.set("pos", pos); | |
NBTTagCompound item = new NBTTagCompound(); | |
item.setByte("Count", (byte) this.item.getAmount()); | |
item.setShort("id", (short) this.item.getTypeId()); | |
NBTTagCompound tag_Item = new NBTTagCompound(); | |
NBTTagCompound display_Item = new NBTTagCompound(); | |
display_Item.setString("Name", this.item.getItemMeta().getDisplayName()); | |
tag_Item.setCompound("display", display_Item); | |
item.setCompound("tag", tag_Item); | |
data.setCompound("Item", item); | |
tag.setCompound("SpawnData", data); | |
NBTTagList potentials = new NBTTagList(); | |
NBTTagCompound t = new NBTTagCompound(); | |
t.setInt("Weight", 1); | |
t.setString("Type", "Item"); | |
t.setCompound("Properties", data); | |
msa.spawnDelay = 0; | |
msa.a(tag); | |
} | |
public static ItemStack gold(){ | |
ItemStack gold = new ItemStack(Material.GOLD_INGOT); | |
ItemMeta m = gold.getItemMeta(); | |
m.setDisplayName(ChatColor.AQUA + "Gold"); | |
gold.setItemMeta(m); | |
return gold; | |
} | |
public static ItemStack bronze(){ | |
ItemStack gold = new ItemStack(Material.CLAY_BRICK); | |
ItemMeta m = gold.getItemMeta(); | |
m.setDisplayName(ChatColor.AQUA + "Bronze"); | |
gold.setItemMeta(m); | |
return gold; | |
} | |
public static ItemStack silver(){ | |
ItemStack gold = new ItemStack(Material.IRON_INGOT); | |
ItemMeta m = gold.getItemMeta(); | |
m.setDisplayName(ChatColor.AQUA + "Silver"); | |
gold.setItemMeta(m); | |
return gold; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment