Created
March 14, 2016 16:34
-
-
Save Cryptite/193f704fc0917f6e078c to your computer and use it in GitHub Desktop.
StringBlock utility class for storing Blocks safely
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
public class StringBlock extends StringLocation { | |
public Material material; | |
public Byte data; | |
public RegenerateType regenerateType = RegenerateType.READY; | |
public StringBlock(Block b, RegenerateType regenerateType) { | |
super(b.getLocation()); | |
material = b.getType(); | |
data = b.getData(); | |
this.regenerateType = regenerateType; | |
} | |
public StringBlock(Block b) { | |
super(b.getLocation()); | |
material = b.getType(); | |
data = b.getData(); | |
} | |
protected StringBlock(String args) { | |
super(args); | |
material = getBlock().getType(); | |
data = getBlock().getData(); | |
} | |
public StringBlock(String args, Material material, byte data) { | |
super(args); | |
this.material = material; | |
this.data = data; | |
} | |
public void setType(Material m) { | |
getBlock().setType(m); | |
} | |
public void setTypeFast(Material m) { | |
getBlock().setType(m, false); | |
// IBlockData blockData = CraftMagicNumbers.getBlock(m.getId()).fromLegacyData(data); | |
// BlockPosition position = new BlockPosition(x, y, z); | |
// | |
// Chunk handle = ((CraftChunk) getChunk()).getHandle(); | |
// return handle.getWorld().setTypeAndData(position, blockData, 3); | |
} | |
public void setTypeAndData(Material m, byte data) { | |
getBlock().setTypeIdAndData(m.getId(), data, false); | |
} | |
public void setTypeIdAndDataFast(int type, byte data) { | |
getBlock().setTypeIdAndData(type, data, false); | |
// IBlockData blockData = CraftMagicNumbers.getBlock(type).fromLegacyData(data); | |
// BlockPosition position = new BlockPosition(x, y, z); | |
// | |
// Chunk handle = ((CraftChunk) getChunk()).getHandle(); | |
// return handle.getWorld().setTypeAndData(position, blockData, 2); | |
} | |
public void setData(byte data) { | |
getBlock().setData(data); | |
} | |
public Material getType() { | |
return getBlock().getType(); | |
} | |
public Byte getData() { | |
return getBlock().getData(); | |
} | |
public Inventory getInventory() { | |
if (isChest()) { | |
Chest c = (Chest) getBlock().getState(); | |
return c.getInventory(); | |
} | |
return null; | |
} | |
private Boolean isChest() { | |
return getBlock().getState() instanceof Chest; | |
} | |
public FurnaceInventory getFurnaceInventory() { | |
Furnace f = (Furnace) getBlock().getState(); | |
return f.getInventory(); | |
} | |
public boolean isSameAs(Block b) { | |
return b.getType().equals(material) && b.getData() == data; | |
} | |
public boolean equals(Block b) { | |
return b.getX() == (int) x | |
&& b.getY() == (int) y | |
&& b.getZ() == (int) z; | |
} | |
public boolean equals(StringBlock b) { | |
return b.x == x | |
&& b.y == y | |
&& b.z == z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment