From 26377b763b2877b033d33ddd865d07faeb590d0c Mon Sep 17 00:00:00 2001 From: Senmori Date: Fri, 18 Nov 2016 11:24:41 +1100 Subject: [PATCH] Get Colors from ShulkerBox; Implement CustomName for Tiles. --- nms-patches/BlockShulkerBox.patch | 9 +++++ .../bukkit/craftbukkit/block/CraftBeacon.java | 10 ++++++ .../craftbukkit/block/CraftBrewingStand.java | 10 ++++++ .../bukkit/craftbukkit/block/CraftChest.java | 2 +- .../craftbukkit/block/CraftDispenser.java | 2 +- .../craftbukkit/block/CraftDropper.java | 2 +- .../craftbukkit/block/CraftFurnace.java | 10 ++++++ .../bukkit/craftbukkit/block/CraftHopper.java | 2 +- .../craftbukkit/block/CraftLootable.java | 35 +++++++++++++++++++ .../craftbukkit/block/CraftShulkerBox.java | 9 ++++- 10 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java diff --git a/nms-patches/BlockShulkerBox.patch b/nms-patches/BlockShulkerBox.patch index ef6b04cde6..7799d7d9ab 100644 --- a/nms-patches/BlockShulkerBox.patch +++ b/nms-patches/BlockShulkerBox.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/server/BlockShulkerBox.java +++ b/net/minecraft/server/BlockShulkerBox.java +@@ -3,7 +3,7 @@ + public class BlockShulkerBox extends BlockTileEntity { + + public static final BlockStateEnum a = BlockStateDirection.of("facing"); +- private final EnumColor b; ++ public final EnumColor b; // PAIL: public, rename + + public BlockShulkerBox(EnumColor enumcolor) { + super(Material.STONE, MaterialMapColor.b); @@ -89,7 +89,32 @@ tileentityshulkerbox.d(entityhuman); } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java index 7dc2978e19..049bae344d 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java @@ -88,4 +88,14 @@ public class CraftBeacon extends CraftContainer implements Beacon { public void setSecondaryEffect(PotionEffectType effect) { beacon.secondaryEffect = (effect != null) ? MobEffectList.fromId(effect.getId()) : null; } + + @Override + public String getCustomName() { + return beacon.hasCustomName() ? beacon.getName() : null; + } + + @Override + public void setCustomName(String name) { + beacon.a(name); // PAIL: setCustomName + } } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java index fbebeab056..e8a66359e5 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java @@ -59,4 +59,14 @@ public class CraftBrewingStand extends CraftContainer implements BrewingStand { public void setFuelLevel(int level) { brewingStand.setProperty(1, level); } + + @Override + public String getCustomName() { + return brewingStand.hasCustomName() ? brewingStand.getName() : null; + } + + @Override + public void setCustomName(String name) { + brewingStand.a(name); // PAIL: setCustomName + } } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java index f15c26bc1f..3de7e14d80 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java @@ -11,7 +11,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest; import org.bukkit.inventory.Inventory; -public class CraftChest extends CraftContainer implements Chest { +public class CraftChest extends CraftLootable implements Chest { private final CraftWorld world; private final TileEntityChest chest; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java index 003381a68b..cc0d28f217 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java @@ -14,7 +14,7 @@ import org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource; import org.bukkit.inventory.Inventory; import org.bukkit.projectiles.BlockProjectileSource; -public class CraftDispenser extends CraftContainer implements Dispenser { +public class CraftDispenser extends CraftLootable implements Dispenser { private final CraftWorld world; private final TileEntityDispenser dispenser; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java index a29eaf9a28..8786d049e7 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java @@ -12,7 +12,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; -public class CraftDropper extends CraftContainer implements Dropper { +public class CraftDropper extends CraftLootable implements Dropper { private final CraftWorld world; private final TileEntityDropper dropper; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java index eb723c80a3..89b7a029d1 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java @@ -53,6 +53,16 @@ public class CraftFurnace extends CraftContainer implements Furnace { furnace.setProperty(2, cookTime); } + @Override + public String getCustomName() { + return furnace.hasCustomName() ? furnace.getName() : null; + } + + @Override + public void setCustomName(String name) { + furnace.a(name); // PAIL: setCustomName + } + @Override public TileEntityFurnace getTileEntity() { return furnace; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java index f155790d1b..b7a04bd847 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java @@ -8,7 +8,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; -public class CraftHopper extends CraftContainer implements Hopper { +public class CraftHopper extends CraftLootable implements Hopper { private final TileEntityHopper hopper; public CraftHopper(final Block block) { diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java new file mode 100644 index 0000000000..6e5ed2dae1 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java @@ -0,0 +1,35 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.server.TileEntity; +import net.minecraft.server.TileEntityLootable; +import org.bukkit.Material; +import org.bukkit.Nameable; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.CraftWorld; + +public class CraftLootable extends CraftContainer implements Nameable { + + private final TileEntityLootable te; + + public CraftLootable(Block block) { + super(block); + + te = (TileEntityLootable) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ()); + } + + public CraftLootable(Material material, TileEntity tileEntity) { + super(material, tileEntity); + + te = (TileEntityLootable) tileEntity; + } + + @Override + public String getCustomName() { + return te.hasCustomName() ? te.getName() : null; + } + + @Override + public void setCustomName(String name) { + te.a(name); // PAIL: setCustomName + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java b/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java index 4ed318319c..8a7ce92bf7 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java @@ -1,7 +1,9 @@ package org.bukkit.craftbukkit.block; +import net.minecraft.server.BlockShulkerBox; import net.minecraft.server.TileEntity; import net.minecraft.server.TileEntityShulkerBox; +import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.ShulkerBox; @@ -9,7 +11,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; -public class CraftShulkerBox extends CraftContainer implements ShulkerBox { +public class CraftShulkerBox extends CraftLootable implements ShulkerBox { private final CraftWorld world; private final TileEntityShulkerBox box; @@ -37,4 +39,9 @@ public class CraftShulkerBox extends CraftContainer implements ShulkerBox { public Inventory getInventory() { return new CraftInventory(box); } + + @Override + public DyeColor getColor() { + return DyeColor.getByWoolData((byte) ((BlockShulkerBox) box.getBlock()).b.getColorIndex()); + } }