use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockIce method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (block.getLightFromBlocks() > 11 - block.getMaterialValues().getLightOpacity()) {
Material type = block.getWorld().getEnvironment() == Environment.NETHER ? Material.AIR : Material.STATIONARY_WATER;
GlowBlockState state = block.getState();
state.setType(type);
state.setData(new MaterialData(type));
BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
EventFactory.callEvent(fadeEvent);
if (!fadeEvent.isCancelled()) {
state.update(true);
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockLadder method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Ladder) {
if (face != BlockFace.DOWN && face != BlockFace.UP && isTargetOccluding(state, face.getOppositeFace())) {
((Ladder) data).setFacingDirection(face.getOppositeFace());
} else {
if (isTargetOccluding(state, BlockFace.SOUTH)) {
((Ladder) data).setFacingDirection(BlockFace.SOUTH);
} else if (isTargetOccluding(state, BlockFace.WEST)) {
((Ladder) data).setFacingDirection(BlockFace.WEST);
} else if (isTargetOccluding(state, BlockFace.NORTH)) {
((Ladder) data).setFacingDirection(BlockFace.NORTH);
} else if (isTargetOccluding(state, BlockFace.EAST)) {
((Ladder) data).setFacingDirection(BlockFace.EAST);
} else {
return;
}
}
state.setData(data);
} else {
warnMaterialData(Ladder.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockOpenable method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
GlowBlockState blockState = block.getState();
MaterialData materialData = blockState.getData();
if (materialData instanceof Openable) {
Openable toOpen = (Openable) materialData;
boolean wasOpen = toOpen.isOpen();
toOpen.setOpen(!wasOpen);
if (wasOpen) {
onClosed(player, block, face, clickedLoc, blockState, materialData);
} else {
onOpened(player, block, face, clickedLoc, blockState, materialData);
}
blockState.update(true);
return true;
} else {
warnMaterialData(Openable.class, materialData);
return false;
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockPumpkinBase method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Pumpkin) {
((Pumpkin) data).setFacingDirection(player.getDirection());
state.setData(data);
} else {
warnMaterialData(Pumpkin.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class ChunkManager method generateChunk.
/**
* Initialize a single chunk from the chunk generator.
*/
private void generateChunk(GlowChunk chunk, int x, int z) {
Random random = new Random(x * 341873128712L + z * 132897987541L);
BiomeGrid biomes = new BiomeGrid();
int[] biomeValues = biomeGrid[0].generateValues(x * GlowChunk.WIDTH, z * GlowChunk.HEIGHT, GlowChunk.WIDTH, GlowChunk.HEIGHT);
for (int i = 0; i < biomeValues.length; i++) {
biomes.biomes[i] = (byte) biomeValues[i];
}
// extended sections with data
GlowChunkData glowChunkData = null;
if (generator instanceof GlowChunkGenerator) {
glowChunkData = (GlowChunkData) generator.generateChunkData(world, random, x, z, biomes);
} else {
ChunkGenerator.ChunkData chunkData = generator.generateChunkData(world, random, x, z, biomes);
if (chunkData != null) {
glowChunkData = new GlowChunkData(world);
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
int maxHeight = chunkData.getMaxHeight();
for (int k = 0; k < maxHeight; ++k) {
MaterialData materialData = chunkData.getTypeAndData(i, k, j);
if (materialData != null) {
glowChunkData.setBlock(i, k, j, materialData);
} else {
glowChunkData.setBlock(i, k, j, new MaterialData(Material.AIR));
}
}
}
}
}
}
if (glowChunkData != null) {
short[][] extSections = glowChunkData.getSections();
if (extSections != null) {
ChunkSection[] sections = new ChunkSection[extSections.length];
for (int i = 0; i < extSections.length; ++i) {
if (extSections[i] != null) {
sections[i] = ChunkSection.fromStateArray(extSections[i]);
}
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
return;
}
}
// extended sections
short[][] extSections = generator.generateExtBlockSections(world, random, x, z, biomes);
if (extSections != null) {
ChunkSection[] sections = new ChunkSection[extSections.length];
for (int i = 0; i < extSections.length; ++i) {
if (extSections[i] != null) {
sections[i] = ChunkSection.fromIdArray(extSections[i]);
}
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
return;
}
// normal sections
byte[][] blockSections = generator.generateBlockSections(world, random, x, z, biomes);
if (blockSections != null) {
ChunkSection[] sections = new ChunkSection[blockSections.length];
for (int i = 0; i < blockSections.length; ++i) {
if (blockSections[i] != null) {
sections[i] = ChunkSection.fromIdArray(blockSections[i]);
}
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
return;
}
// deprecated flat generation
byte[] types = generator.generate(world, random, x, z);
ChunkSection[] sections = new ChunkSection[8];
for (int sy = 0; sy < sections.length; ++sy) {
// We can't use a normal constructor here due to the "interesting"
// choices used for this deprecated API (blocks are in vertical columns)
ChunkSection sec = new ChunkSection();
int by = 16 * sy;
for (int cx = 0; cx < 16; ++cx) {
for (int cz = 0; cz < 16; ++cz) {
for (int cy = by; cy < by + 16; ++cy) {
char type = (char) types[(((cx << 4) + cz) << 7) + cy];
sec.setType(cx, cy, cz, (char) (type << 4));
}
}
}
sections[sy] = sec;
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
}
Aggregations