SPIGOT-5146: BlockDataMeta does not work

This commit is contained in:
md_5 2019-07-09 10:47:07 +10:00
parent 608609835d
commit 7ad3a1f468
3 changed files with 58 additions and 14 deletions

View File

@ -21,18 +21,52 @@
itemstack.subtract(1);
return EnumInteractionResult.SUCCESS;
}
@@ -120,8 +125,15 @@
@@ -89,6 +94,21 @@
if (nbttagcompound != null) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("BlockStateTag");
+ // CraftBukkit start
+ iblockdata1 = getBlockState(iblockdata1, nbttagcompound1);
+ }
+
+ if (iblockdata1 != iblockdata) {
+ world.setTypeAndData(blockposition, iblockdata1, 2);
+ }
+
+ return iblockdata1;
+ }
+
+ public static IBlockData getBlockState(IBlockData iblockdata, NBTTagCompound nbttagcompound1) {
+ IBlockData iblockdata1 = iblockdata;
+ {
+ // CraftBukkit end
BlockStateList<Block, IBlockData> blockstatelist = iblockdata.getBlock().getStates();
Iterator iterator = nbttagcompound1.getKeys().iterator();
@@ -103,11 +123,6 @@
}
}
}
-
- if (iblockdata1 != iblockdata) {
- world.setTypeAndData(blockposition, iblockdata1, 2);
- }
-
return iblockdata1;
}
@@ -120,8 +135,15 @@
protected boolean b(BlockActionContext blockactioncontext, IBlockData iblockdata) {
EntityHuman entityhuman = blockactioncontext.getEntity();
VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.a() : VoxelShapeCollision.a((Entity) entityhuman);
+ // CraftBukkit start - store default return
+ boolean defaultReturn = (!this.d() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && blockactioncontext.getWorld().a(iblockdata, blockactioncontext.getClickPosition(), voxelshapecollision);
+ org.bukkit.entity.Player player = (blockactioncontext.getEntity() instanceof EntityPlayer) ? (org.bukkit.entity.Player) blockactioncontext.getEntity().getBukkitEntity() : null;
- return (!this.d() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && blockactioncontext.getWorld().a(iblockdata, blockactioncontext.getClickPosition(), voxelshapecollision);
+
+ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(blockactioncontext.getWorld(), blockactioncontext.getClickPosition()), player, CraftBlockData.fromData(iblockdata), defaultReturn);
+ blockactioncontext.getWorld().getServer().getPluginManager().callEvent(event);
+
- return (!this.d() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && blockactioncontext.getWorld().a(iblockdata, blockactioncontext.getClickPosition(), voxelshapecollision);
+ return event.isBuildable();
+ // CraftBukkit end
}

View File

@ -22,6 +22,7 @@ import net.minecraft.server.IBlockData;
import net.minecraft.server.IBlockState;
import net.minecraft.server.INamable;
import net.minecraft.server.IRegistry;
import net.minecraft.server.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
@ -275,8 +276,16 @@ public class CraftBlockData implements BlockData {
return stateString.toString();
}
public String toStates() {
return ((BlockDataAbstract) state).getStateMap().entrySet().stream().map(BlockDataAbstract.STATE_TO_VALUE).collect(Collectors.joining(",")).toString();
public NBTTagCompound toStates() {
NBTTagCompound compound = new NBTTagCompound();
for (Map.Entry<IBlockState<?>, Comparable<?>> entry : state.getStateMap().entrySet()) {
IBlockState iblockstate = (IBlockState) entry.getKey();
compound.setString(iblockstate.a(), iblockstate.a(entry.getValue()));
}
return compound;
}
@Override

View File

@ -41,6 +41,7 @@ import net.minecraft.server.EnumChatFormat;
import net.minecraft.server.EnumItemSlot;
import net.minecraft.server.GenericAttributes;
import net.minecraft.server.IChatBaseComponent;
import net.minecraft.server.ItemBlock;
import net.minecraft.server.NBTBase;
import net.minecraft.server.NBTCompressedStreamTools;
import net.minecraft.server.NBTTagCompound;
@ -263,7 +264,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
private IChatBaseComponent locName;
private List<IChatBaseComponent> lore;
private Integer customModelData;
private String blockData;
private NBTTagCompound blockData;
private Map<Enchantment, Integer> enchantments;
private Multimap<Attribute, AttributeModifier> attributeModifiers;
private int repairCost;
@ -356,8 +357,8 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
if (tag.hasKeyOfType(CUSTOM_MODEL_DATA.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
customModelData = tag.getInt(CUSTOM_MODEL_DATA.NBT);
}
if (tag.hasKeyOfType(BLOCK_DATA.NBT, CraftMagicNumbers.NBT.TAG_STRING)) {
blockData = tag.getString(BLOCK_DATA.NBT);
if (tag.hasKeyOfType(BLOCK_DATA.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
blockData = tag.getCompound(BLOCK_DATA.NBT);
}
this.enchantments = buildEnchantments(tag, ENCHANTMENTS);
@ -484,9 +485,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
setCustomModelData(customModelData);
}
String blockData = SerializableMeta.getObject(String.class, map, BLOCK_DATA.BUKKIT, true);
Map blockData = SerializableMeta.getObject(Map.class, map, BLOCK_DATA.BUKKIT, true);
if (blockData != null) {
this.blockData = blockData;
this.blockData = (NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(blockData);
}
enchantments = buildEnchantments(map, ENCHANTMENTS);
@ -627,7 +628,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
}
if (hasBlockData()) {
itemTag.setString(BLOCK_DATA.NBT, blockData);
itemTag.set(BLOCK_DATA.NBT, blockData);
}
if (hideFlag != 0) {
@ -919,7 +920,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
@Override
public BlockData getBlockData(Material material) {
return CraftBlockData.newData(material, '[' + blockData + ']');
return CraftBlockData.fromData(ItemBlock.getBlockState(CraftMagicNumbers.getBlock(material).getBlockData(), blockData));
}
@Override
@ -1225,7 +1226,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData);
}
if (hasBlockData()) {
builder.put(BLOCK_DATA.BUKKIT, blockData);
builder.put(BLOCK_DATA.BUKKIT, CraftNBTTagConfigSerializer.serialize(blockData));
}
serializeEnchantments(enchantments, builder, ENCHANTMENTS);