下面列出了org.bukkit.Material#SAND 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public GrindStone(Category category, SlimefunItemStack item) {
super(category, item,
new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
new ItemStack[] {
new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4),
new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4),
new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT),
new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2),
new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL),
new ItemStack(Material.ANDESITE), new ItemStack(Material.GRAVEL),
new ItemStack(Material.DIORITE), new ItemStack(Material.GRAVEL),
new ItemStack(Material.GRANITE), new ItemStack(Material.GRAVEL),
new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK,
new ItemStack(Material.SANDSTONE), new ItemStack(Material.SAND, 4),
new ItemStack(Material.RED_SANDSTONE), new ItemStack(Material.RED_SAND, 4),
new ItemStack(Material.PRISMARINE_BRICKS), new ItemStack(Material.PRISMARINE, 2),
new ItemStack(Material.PRISMARINE), new ItemStack(Material.PRISMARINE_SHARD, 4)
},
BlockFace.SELF
);
}
/**
* Tests if the specified location is valid for a natural spawn position
*
* @param world The world we're testing on
* @param x X-coordinate of the block to test
* @param z Z-coordinate of the block to test
* @return true if the location is valid, otherwise false
*/
public boolean canSpawn(World world, int x, int z) {
Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z);
switch (world.getEnvironment()) {
case NETHER:
return true;
case THE_END:
return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA;
case NORMAL:
default:
return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL;
}
}
@Override
public void populate(World world, Random random, Chunk chunk){
for (int x = 1; x < 15; x++) {
for (int z = 1; z < 15; z++) {
Block block = world.getHighestBlockAt(chunk.getBlock(x, 0, z).getLocation());
Block below = block.getRelative(BlockFace.DOWN);
if (percentage > random.nextInt(100) && (below.getType() == Material.SAND || below.getType() == Material.GRASS)){
Material water = UniversalMaterial.STATIONARY_WATER.getType();
if (
below.getRelative(BlockFace.NORTH).getType() == water ||
below.getRelative(BlockFace.EAST).getType() == water ||
below.getRelative(BlockFace.SOUTH).getType() == water ||
below.getRelative(BlockFace.WEST).getType() == water
){
if (block.getType() == Material.AIR){
int height = random.nextInt(3)+1;
Location location = block.getLocation();
while (height > 0){
world.getBlockAt(location).setType(UniversalMaterial.SUGAR_CANE_BLOCK.getType());
location = location.add(0, 1, 0);
height--;
}
}
}
}
}
}
}
int getHighestSoil(Block highestBlock) {
while ((highestBlock.getY() > 0)
&& (highestBlock.getType() != Material.DIRT)
&& // Includes podzol
(highestBlock.getType() != Material.GRASS)
&& (highestBlock.getType() != Material.MYCELIUM)
&& (highestBlock.getType() != Material.SAND)) {
highestBlock = highestBlock.getRelative(BlockFace.DOWN);
}
return highestBlock.getY();
}
Block getHighestSoil(Block highestBlock) {
while ((highestBlock.getY() > 0)
&& (highestBlock.getType() != Material.DIRT)
&& // Includes podzol
(highestBlock.getType() != Material.GRASS)
&& (highestBlock.getType() != Material.MYCELIUM)
&& (highestBlock.getType() != Material.SAND)) {
highestBlock = highestBlock.getRelative(BlockFace.DOWN);
}
return highestBlock;
}
@Test
public void testEquals() throws Exception {
//Same Material
ItemEntry equalEntry1 = new ItemEntry(Material.STONE);
ItemEntry equalEntry2 = new ItemEntry(Material.STONE);
assertThat(equalEntry1, is(equalEntry2));
assertThat(equalEntry1.hashCode(), is(equalEntry2.hashCode()));
//Same Material + metadata
ItemEntry equalEntry3 = new ItemEntry(Material.STONE, 2);
ItemEntry equalEntry4 = new ItemEntry(Material.STONE, 2);
assertThat(equalEntry3, is(equalEntry4));
assertThat(equalEntry3.hashCode(), is(equalEntry4.hashCode()));
//Different Material
ItemEntry diffEntry1 = new ItemEntry(Material.STONE);
ItemEntry diffEntry2 = new ItemEntry(Material.ANVIL);
assertThat(diffEntry1, not(diffEntry2));
assertThat(diffEntry1.hashCode(), not(diffEntry2.hashCode()));
//Different metadata
ItemEntry diffEntry3 = new ItemEntry(Material.STONE, 4);
ItemEntry diffEntry4 = new ItemEntry(Material.STONE, 7);
assertThat(diffEntry3, not(diffEntry4));
assertThat(diffEntry3.hashCode(), not(diffEntry4.hashCode()));
//Different Material + metadata
ItemEntry diffEntry5 = new ItemEntry(Material.STONE, 4);
ItemEntry diffEntry6 = new ItemEntry(Material.SAND, 2);
assertThat(diffEntry5, not(diffEntry6));
assertThat(diffEntry5.hashCode(), not(diffEntry6.hashCode()));
//HashMap Test
Map<ItemEntry, EnumItem> testMap = new HashMap<ItemEntry, EnumItem>();
testMap.put(equalEntry1, EnumItem.STONE);
assertTrue(testMap.containsKey(equalEntry1));
testMap.put(equalEntry3, EnumItem.POLISHED_GRANITE);
assertTrue(testMap.containsKey(equalEntry4));
assertFalse(testMap.containsKey(diffEntry2));
assertFalse(testMap.containsKey(diffEntry3));
assertFalse(testMap.containsKey(diffEntry6));
}
public OreCrusher(Category category, SlimefunItemStack item) {
super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.IRON_BARS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.IRON_BARS) }, new ItemStack[] { new ItemStack(Material.COBBLESTONE, 8), new ItemStack(Material.SAND, 1), SlimefunItems.GOLD_4K, SlimefunItems.GOLD_DUST, new ItemStack(Material.GRAVEL), new ItemStack(Material.SAND), new ItemStack(Material.MAGMA_BLOCK, 4), SlimefunItems.SULFATE }, BlockFace.SELF);
addItemSetting(doubleOres);
}