use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRedstone method extraUpdate.
private void extraUpdate(GlowBlock block) {
ItemTable itemTable = ItemTable.instance();
for (BlockFace face : calculateConnections(block)) {
GlowBlock target = block.getRelative(face);
if (target.getType().isSolid()) {
for (BlockFace face2 : ADJACENT) {
GlowBlock target2 = target.getRelative(face2);
BlockType notifyType = itemTable.getBlock(target2.getTypeId());
if (notifyType != null) {
if (target2.getFace(block) == null) {
notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
}
notifyType.onRedstoneUpdate(target2);
}
}
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockLiquid method flow.
private void flow(GlowBlock source, BlockFace direction) {
// if we're not going down
BlockFromToEvent fromToEvent = new BlockFromToEvent(source, direction);
if (fromToEvent.isCancelled()) {
return;
}
byte strength = fromToEvent.getBlock().getState().getRawData();
if (DOWN != fromToEvent.getFace()) {
if (Byte.compare(strength, isWater(fromToEvent.getBlock().getType()) || fromToEvent.getBlock().getBiome() == Biome.HELL ? STRENGTH_MIN_WATER : STRENGTH_MIN_LAVA) < 0) {
// decrease the strength
strength += 1;
} else {
// no strength, can't flow
return;
}
} else {
// reset the strength if we're going down
strength = STRENGTH_MAX;
}
// flow to the target
GlowBlock toBlock = (GlowBlock) fromToEvent.getToBlock();
toBlock.setType(fromToEvent.getBlock().getType(), strength, false);
toBlock.getWorld().requestPulse(toBlock);
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockDoor method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
// place the door and calculate the facing
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (!(data instanceof Door)) {
warnMaterialData(Door.class, data);
return;
}
BlockFace facing = player.getDirection();
((Door) data).setFacingDirection(facing.getOppositeFace());
// modify facing for double-doors
GlowBlock leftBlock = null;
switch(facing) {
case NORTH:
leftBlock = state.getBlock().getRelative(BlockFace.WEST);
break;
case WEST:
leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
break;
case SOUTH:
leftBlock = state.getBlock().getRelative(BlockFace.EAST);
break;
case EAST:
leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
break;
}
if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
switch(facing) {
case NORTH:
data.setData((byte) 6);
break;
case WEST:
data.setData((byte) 5);
break;
case SOUTH:
data.setData((byte) 4);
break;
case EAST:
data.setData((byte) 7);
break;
}
}
// place top half of door
GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
topState.setType(state.getType());
MaterialData topData = topState.getData();
if (!(topData instanceof Door)) {
warnMaterialData(Door.class, data);
} else {
((Door) topData).setTopHalf(true);
topState.update(true);
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockHopper method pushItems.
private boolean pushItems(GlowBlock block, HopperEntity hopper) {
if (hopper.getInventory() == null || hopper.getInventory().getContents().length == 0) {
return false;
}
GlowBlock target = block.getRelative(((Hopper) block.getState().getData()).getFacing());
if (target.getType() != null && target.getBlockEntity() instanceof ContainerEntity) {
if (target.getState() instanceof GlowHopper) {
if (((Hopper) block.getState().getData()).getFacing() == BlockFace.DOWN) {
// If the hopper is facing downwards, the target hopper can do the pulling task itself
return false;
}
}
ItemStack item = getFirstItem(hopper);
if (item == null) {
return false;
}
ItemStack clone = item.clone();
clone.setAmount(1);
if (((ContainerEntity) target.getBlockEntity()).getInventory().addItem(clone).size() > 0) {
return false;
}
if (item.getAmount() - 1 == 0) {
hopper.getInventory().remove(item);
} else {
item.setAmount(item.getAmount() - 1);
}
return true;
}
return false;
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockLeaves method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlockState state = block.getState();
if ((state.getRawData() & 0x08) != 0 && (state.getRawData() & 0x04) == 0) {
// check decay is on and decay is on
GlowWorld world = block.getWorld();
// build a 9x9x9 box to map neighboring blocks
for (int x = 0; x < 9; x++) {
for (int z = 0; z < 9; z++) {
for (int y = 0; y < 9; y++) {
GlowBlock b = world.getBlockAt(block.getLocation().add(x - 4, y - 4, z - 4));
byte val = 127;
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) {
val = 0;
} else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
val = -1;
}
setBlockInMap(val, x, y, z);
}
}
}
// to another connected leaves block will decay
for (int i = 0; i < 4; i++) {
for (int x = 0; x < 9; x++) {
for (int z = 0; z < 9; z++) {
for (int y = 0; y < 9; y++) {
if (getBlockInMap(x, y, z) == i) {
if (getBlockInMap(x - 1, y, z) == -1) {
setBlockInMap((byte) (i + 1), x - 1, y, z);
}
if (getBlockInMap(x, y - 1, z) == -1) {
setBlockInMap((byte) (i + 1), x, y - 1, z);
}
if (getBlockInMap(x, y, z - 1) == -1) {
setBlockInMap((byte) (i + 1), x, y, z - 1);
}
if (getBlockInMap(x + 1, y, z) == -1) {
setBlockInMap((byte) (i + 1), x + 1, y, z);
}
if (getBlockInMap(x, y + 1, z) == -1) {
setBlockInMap((byte) (i + 1), x, y + 1, z);
}
if (getBlockInMap(x, y, z + 1) == -1) {
setBlockInMap((byte) (i + 1), x, y, z + 1);
}
}
}
}
}
}
if (getBlockInMap(4, 4, 4) < 0) {
// leaf decay
LeavesDecayEvent decayEvent = new LeavesDecayEvent(block);
EventFactory.callEvent(decayEvent);
if (!decayEvent.isCancelled()) {
block.breakNaturally();
}
} else {
// cancel decay check on this leaves block
state.setRawData((byte) (state.getRawData() & -0x09));
state.update(true);
}
}
}
Aggregations