mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Added MaterialData from BlockState
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
5488422237
commit
4d7b10c59d
2 changed files with 14 additions and 18 deletions
|
@ -40,14 +40,7 @@ public class ItemStack {
|
|||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.damage = damage;
|
||||
|
||||
Material mat = Material.getMaterial(type);
|
||||
|
||||
if (mat == null) {
|
||||
this.data = new MaterialData(type, data);
|
||||
} else {
|
||||
this.data = mat.getNewData(data);
|
||||
}
|
||||
createData(data);
|
||||
}
|
||||
|
||||
public ItemStack(final Material type, final int amount, final byte damage, final byte data) {
|
||||
|
@ -92,14 +85,7 @@ public class ItemStack {
|
|||
*/
|
||||
public void setTypeID(int type) {
|
||||
this.type = type;
|
||||
|
||||
Material mat = Material.getMaterial(type);
|
||||
|
||||
if (mat == null) {
|
||||
data = new MaterialData(type, (byte)0);
|
||||
} else {
|
||||
data = mat.getNewData((byte)0);
|
||||
}
|
||||
createData((byte)0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,6 +171,15 @@ public class ItemStack {
|
|||
return -1;
|
||||
}
|
||||
|
||||
private void createData(final byte data) {
|
||||
Material mat = Material.getMaterial(type);
|
||||
if (mat == null) {
|
||||
this.data = new MaterialData(type, data);
|
||||
} else {
|
||||
this.data = mat.getNewData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemStack{"+getType().name()+" x "+getAmount()+"}";
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.bukkit.Block;
|
|||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
/**
|
||||
* Represents a captured state of a block, which will not change automatically.
|
||||
|
@ -27,7 +28,7 @@ public interface BlockState {
|
|||
*
|
||||
* @return block specific metadata
|
||||
*/
|
||||
byte getData();
|
||||
MaterialData getData();
|
||||
|
||||
/**
|
||||
* Gets the type of this block
|
||||
|
@ -90,7 +91,7 @@ public interface BlockState {
|
|||
*
|
||||
* @param data New block specific metadata
|
||||
*/
|
||||
void setData(byte data);
|
||||
void setData(MaterialData data);
|
||||
|
||||
/**
|
||||
* Sets the type of this block
|
||||
|
|
Loading…
Reference in a new issue