Merge pull request #85 in MIN/mineplex from virizion_utils to master
* commit 'bf92af647abceb78596f9fd1922d3522e61ff053': Fixed the skull bug where it gave you the wrong skull type. Now gets the meta of the block as well. Also can return multiple items if the block is made up of multiple items (flower pots, ender portal frames).
This commit is contained in:
commit
fc0cae8e0f
@ -6,18 +6,35 @@ import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.BrewingStand;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Dropper;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.material.Bed;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.Blocks;
|
||||
import net.minecraft.server.v1_8_R3.EnumDirection;
|
||||
import net.minecraft.server.v1_8_R3.Item;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.TileEntityFlowerPot;
|
||||
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||
|
||||
public class UtilBlock
|
||||
@ -844,9 +861,11 @@ public class UtilBlock
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static ItemStack blockToInventoryItemStack(Block block)
|
||||
public static ArrayList<ItemStack> blockToInventoryItemStacks(Block block)
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(block.getType(), 1, block.getData());
|
||||
ArrayList<ItemStack> itemStacks = new ArrayList<ItemStack>();
|
||||
itemStacks.add(itemStack);
|
||||
|
||||
switch (block.getType())
|
||||
{
|
||||
@ -877,6 +896,17 @@ public class UtilBlock
|
||||
break;
|
||||
case DISPENSER:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Dispenser dispenser = (Dispenser) block.getState();
|
||||
|
||||
for (ItemStack is : dispenser.getInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case BED_BLOCK:
|
||||
itemStack.setType(Material.BED);
|
||||
@ -921,6 +951,17 @@ public class UtilBlock
|
||||
break;
|
||||
case CHEST:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Chest chest = (Chest) block.getState();
|
||||
|
||||
for (ItemStack is : chest.getBlockInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case REDSTONE_WIRE:
|
||||
itemStack.setType(Material.REDSTONE);
|
||||
@ -936,10 +977,32 @@ public class UtilBlock
|
||||
break;
|
||||
case FURNACE:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Furnace furnace = (Furnace) block.getState();
|
||||
|
||||
for (ItemStack is : furnace.getInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case BURNING_FURNACE:
|
||||
itemStack.setType(Material.FURNACE);
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Furnace burningFurnace = (Furnace) block.getState();
|
||||
|
||||
for (ItemStack is : burningFurnace.getInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case SIGN_POST:
|
||||
itemStack.setType(Material.SIGN);
|
||||
@ -1001,6 +1064,12 @@ public class UtilBlock
|
||||
break;
|
||||
case JUKEBOX:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Jukebox jukebox = (Jukebox) block.getState();
|
||||
|
||||
if (jukebox.getPlaying() != Material.AIR)
|
||||
itemStacks.add(new ItemStack(jukebox.getPlaying()));
|
||||
|
||||
break;
|
||||
case PORTAL:
|
||||
itemStack.setType(Material.AIR);
|
||||
@ -1057,10 +1126,25 @@ public class UtilBlock
|
||||
case BREWING_STAND:
|
||||
itemStack.setType(Material.BREWING_STAND_ITEM);
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
BrewingStand brewingStand = (BrewingStand) block.getState();
|
||||
|
||||
for (ItemStack is : brewingStand.getInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case CAULDRON:
|
||||
itemStack.setType(Material.CAULDRON_ITEM);
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
if (block.getData() != 0)
|
||||
itemStacks.add(new ItemStack(Material.WATER_BUCKET));
|
||||
|
||||
break;
|
||||
case ENDER_PORTAL:
|
||||
itemStack.setType(Material.AIR);
|
||||
@ -1068,6 +1152,10 @@ public class UtilBlock
|
||||
break;
|
||||
case ENDER_PORTAL_FRAME:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
if ((block.getData() & 0x4) != 0)
|
||||
itemStacks.add(new ItemStack(Material.EYE_OF_ENDER));
|
||||
|
||||
break;
|
||||
case REDSTONE_LAMP_ON:
|
||||
itemStack.setType(Material.REDSTONE_LAMP_OFF);
|
||||
@ -1111,6 +1199,27 @@ public class UtilBlock
|
||||
case FLOWER_POT:
|
||||
itemStack.setType(Material.FLOWER_POT_ITEM);
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
//The FlowerPot class is outdated and doesn't work so we do some NBT checking
|
||||
TileEntityFlowerPot tefp = (TileEntityFlowerPot) ((CraftWorld) block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
tefp.b(c);
|
||||
|
||||
ItemStack blockInPot = new ItemStack(Material.AIR);
|
||||
|
||||
if (c.hasKey("Item"))
|
||||
{
|
||||
MinecraftKey mk = new MinecraftKey(c.getString("Item"));
|
||||
blockInPot = CraftItemStack.asNewCraftStack(Item.REGISTRY.get(mk));
|
||||
}
|
||||
|
||||
if (c.hasKey("Data"))
|
||||
blockInPot.setDurability(c.getShort("Data"));
|
||||
|
||||
if (blockInPot.getType() != Material.AIR)
|
||||
itemStacks.add(blockInPot);
|
||||
|
||||
break;
|
||||
case CARROT:
|
||||
itemStack.setType(Material.CARROT_ITEM);
|
||||
@ -1125,9 +1234,31 @@ public class UtilBlock
|
||||
break;
|
||||
case SKULL:
|
||||
itemStack.setType(Material.SKULL_ITEM);
|
||||
|
||||
Skull skull = (Skull) block.getState();
|
||||
itemStack.setDurability((short) skull.getSkullType().ordinal());
|
||||
|
||||
if (skull.getSkullType() == SkullType.PLAYER && skull.hasOwner())
|
||||
{
|
||||
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
|
||||
skullMeta.setOwner(skull.getOwner());
|
||||
itemStack.setItemMeta(skullMeta);
|
||||
}
|
||||
|
||||
break;
|
||||
case TRAPPED_CHEST:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Chest trappedChest = (Chest) block.getState();
|
||||
|
||||
for (ItemStack is : trappedChest.getBlockInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case GOLD_PLATE:
|
||||
itemStack.setDurability((short) 0);
|
||||
@ -1148,6 +1279,17 @@ public class UtilBlock
|
||||
break;
|
||||
case HOPPER:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Hopper hopper = (Hopper) block.getState();
|
||||
|
||||
for (ItemStack is : hopper.getInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case QUARTZ_STAIRS:
|
||||
itemStack.setDurability((short) 0);
|
||||
@ -1157,6 +1299,17 @@ public class UtilBlock
|
||||
break;
|
||||
case DROPPER:
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Dropper dropper = (Dropper) block.getState();
|
||||
|
||||
for (ItemStack is : dropper.getInventory().getContents())
|
||||
{
|
||||
if (is == null)
|
||||
continue;
|
||||
|
||||
itemStacks.add(is);
|
||||
}
|
||||
|
||||
break;
|
||||
case LEAVES_2:
|
||||
itemStack.setDurability((short) (itemStack.getDurability() % 4));
|
||||
@ -1178,11 +1331,27 @@ public class UtilBlock
|
||||
break;
|
||||
case STANDING_BANNER:
|
||||
itemStack.setType(Material.BANNER);
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Banner banner = (Banner) block.getState();
|
||||
itemStack.setDurability(banner.getBaseColor().getDyeData());
|
||||
|
||||
BannerMeta bannerMeta = (BannerMeta) itemStack.getItemMeta();
|
||||
bannerMeta.setBaseColor(bannerMeta.getBaseColor());
|
||||
bannerMeta.setPatterns(banner.getPatterns());
|
||||
itemStack.setItemMeta(bannerMeta);
|
||||
|
||||
break;
|
||||
case WALL_BANNER:
|
||||
itemStack.setType(Material.BANNER);
|
||||
itemStack.setDurability((short) 0);
|
||||
|
||||
Banner wallBanner = (Banner) block.getState();
|
||||
itemStack.setDurability(wallBanner.getBaseColor().getDyeData());
|
||||
|
||||
BannerMeta wallBannerMeta = (BannerMeta) itemStack.getItemMeta();
|
||||
wallBannerMeta.setBaseColor(wallBannerMeta.getBaseColor());
|
||||
wallBannerMeta.setPatterns(wallBanner.getPatterns());
|
||||
itemStack.setItemMeta(wallBannerMeta);
|
||||
|
||||
break;
|
||||
case DAYLIGHT_DETECTOR_INVERTED:
|
||||
itemStack.setType(Material.DAYLIGHT_DETECTOR);
|
||||
@ -1235,6 +1404,6 @@ public class UtilBlock
|
||||
break;
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
return itemStacks;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user