本文整理匯總了Java中org.bukkit.block.BlockState.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockState.getType方法的具體用法?Java BlockState.getType怎麽用?Java BlockState.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.BlockState
的用法示例。
在下文中一共展示了BlockState.getType方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCropState
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
public String getCropState(BlockState blockState) {
switch (blockState.getType()) { // .getBlock().getType()) {
case COCOA:
return ((CocoaPlant) blockState.getData()).getSize().toString();
case NETHER_WARTS:
return ((NetherWarts) blockState.getData()).getState().toString();
case MELON_STEM:
return (int) blockState.getBlock().getData() + "";
case PUMPKIN_STEM:
return (int) blockState.getBlock().getData() + "";
case CACTUS:
return null;
case BROWN_MUSHROOM:
return null;
case RED_MUSHROOM:
return null;
case SUGAR_CANE_BLOCK:
return null;
default:
//CropControl.getPlugin().debug("Unable to find CropState match for {0}", blockState);
return ((Crops) blockState.getData()).getState().toString();
}
}
示例2: onTreeGrow
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
/**
* Prevents trees from growing outside of the protected area.
*
* @param e
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Check world
if (!Util.inWorld(e.getLocation())) {
return;
}
// Check if this is on an island
Island island = plugin.getIslands().getIslandAt(e.getLocation());
if (island == null || island.isSpawn()) {
return;
}
Iterator<BlockState> it = e.getBlocks().iterator();
while (it.hasNext()) {
BlockState b = it.next();
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2
|| b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
if (!island.onIsland(b.getLocation())) {
it.remove();
}
}
}
}
示例3: onTreeGrow
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
/**
* Converts trees to gravel and glowstone
*
* @param e
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG)
plugin.getLogger().info("DEBUG: " + e.getEventName());
if (!Settings.netherTrees) {
return;
}
if (!Settings.netherGenerate || IslandWorld.getNetherWorld() == null) {
return;
}
// Check world
if (!e.getLocation().getWorld().equals(IslandWorld.getNetherWorld())) {
return;
}
for (BlockState b : e.getBlocks()) {
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) {
b.setType(Material.GRAVEL);
} else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
b.setType(Material.GLOWSTONE);
}
}
}
示例4: isValidWool
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private static boolean isValidWool(DyeColor expectedColor, BlockState state) {
return state.getType() == Material.WOOL && expectedColor.getWoolData() == state.getRawData();
}
示例5: doBlockDrops
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
/**
* This is not an event handler. It is called explicitly by BlockTransformListener
* after all event handlers have been called.
*/
@SuppressWarnings("deprecation")
public void doBlockDrops(final BlockTransformEvent event) {
if(!causesDrops(event.getCause())) {
return;
}
final BlockDrops drops = event.getDrops();
if(drops != null) {
event.setCancelled(true);
final BlockState oldState = event.getOldState();
final BlockState newState = event.getNewState();
final Block block = event.getOldState().getBlock();
final int newTypeId = newState.getTypeId();
final byte newData = newState.getRawData();
block.setTypeIdAndData(newTypeId, newData, true);
boolean explosion = false;
MatchPlayer player = ParticipantBlockTransformEvent.getParticipant(event);
if(event.getCause() instanceof EntityExplodeEvent) {
EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
explosion = true;
if(drops.fallChance != null &&
oldState.getType().isBlock() &&
oldState.getType() != Material.AIR &&
this.getMatch().getRandom().nextFloat() < drops.fallChance) {
FallingBlock fallingBlock = event.getOldState().spawnFallingBlock();
fallingBlock.setDropItem(false);
if(drops.landChance != null && this.getMatch().getRandom().nextFloat() >= drops.landChance) {
this.fallingBlocksThatWillNotLand.add(fallingBlock);
}
Vector v = fallingBlock.getLocation().subtract(explodeEvent.getLocation()).toVector();
double distance = v.length();
v.normalize().multiply(BASE_FALL_SPEED * drops.fallSpeed / Math.max(1d, distance));
// A very simple deflection model. Check for a solid
// neighbor block and "bounce" the velocity off of it.
Block west = block.getRelative(BlockFace.WEST);
Block east = block.getRelative(BlockFace.EAST);
Block down = block.getRelative(BlockFace.DOWN);
Block up = block.getRelative(BlockFace.UP);
Block north = block.getRelative(BlockFace.NORTH);
Block south = block.getRelative(BlockFace.SOUTH);
if((v.getX() < 0 && west != null && Materials.isColliding(west.getType())) ||
v.getX() > 0 && east != null && Materials.isColliding(east.getType())) {
v.setX(-v.getX());
}
if((v.getY() < 0 && down != null && Materials.isColliding(down.getType())) ||
v.getY() > 0 && up != null && Materials.isColliding(up.getType())) {
v.setY(-v.getY());
}
if((v.getZ() < 0 && north != null && Materials.isColliding(north.getType())) ||
v.getZ() > 0 && south != null && Materials.isColliding(south.getType())) {
v.setZ(-v.getZ());
}
fallingBlock.setVelocity(v);
}
}
dropObjects(drops, player, newState.getLocation(), 1d, explosion);
}
}
示例6: searchForMarkers
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
/**
* Searches the map for "markers". Most of the time these are implemented as tile entities (skulls)
*
* @param map the map to scan
* @param center the center location
* @param range the range in where to scan
*/
public void searchForMarkers(@Nonnull Map map, @Nonnull Vector3D center, int range, @Nonnull UUID gameid) {
World world = Bukkit.getWorld(map.getLoadedName(gameid));
if (world == null) {
throw new MapException("Could not find world " + map.getLoadedName(gameid) + "(" + map.getInfo().getName() + ")" + ". Is it loaded?");
}
List<Marker> markers = new ArrayList<>();
List<ChestMarker> chestMarkers = new ArrayList<>();
int startX = (int) center.getX();
int startY = (int) center.getZ();
int minX = Math.min(startX - range, startX + range);
int minZ = Math.min(startY - range, startY + range);
int maxX = Math.max(startX - range, startX + range);
int maxZ = Math.max(startY - range, startY + range);
for (int x = minX; x <= maxX; x += 16) {
for (int z = minZ; z <= maxZ; z += 16) {
Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
for (BlockState te : chunk.getTileEntities()) {
if (te.getType() == Material.SKULL) {
Skull skull = (Skull) te;
if (skull.getSkullType() == SkullType.PLAYER) {
String markerData = getMarkerData(skull);
if (markerData == null) continue;
MarkerDefinition markerDefinition = mapHandler.createMarkerDefinition(markerData);
markers.add(new Marker(new Vector3D(skull.getX(), skull.getY(), skull.getZ()),
DirectionUtil.directionToYaw(skull.getRotation()),
markerData, markerDefinition));
}
} else if (te.getType() == Material.CHEST) {
Chest chest = (Chest) te;
String name = chest.getBlockInventory().getName();
ItemStack[] items = new ItemStack[chest.getBlockInventory()
.getStorageContents().length];
for (int i = 0; i < items.length; i++) {
ItemStack is = chest.getBlockInventory().getItem(i);
if (is == null) {
items[i] = new ItemStack(Material.AIR);
} else {
items[i] = is;
}
}
chestMarkers
.add(new ChestMarker(new Vector3D(chest.getX(), chest.getY(), chest.getZ()), name,
items));
}
}
}
}
map.setMarkers(markers);
map.setChestMarkers(chestMarkers);
}