use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRedstone method calculateConnections.
public static List<BlockFace> calculateConnections(GlowBlock block) {
List<BlockFace> value = new ArrayList<>();
List<BlockFace> connections = new ArrayList<>();
value.add(BlockFace.DOWN);
for (BlockFace face : SIDES) {
GlowBlock target = block.getRelative(face);
switch(target.getType()) {
case DIODE_BLOCK_ON:
case DIODE_BLOCK_OFF:
Diode diode = (Diode) target.getState().getData();
if (face == diode.getFacing() || face == diode.getFacing().getOppositeFace()) {
connections.add(face);
}
break;
case REDSTONE_BLOCK:
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
case REDSTONE_WIRE:
case WOOD_BUTTON:
case STONE_BUTTON:
case LEVER:
case OBSERVER:
connections.add(face);
break;
default:
if (target.getType().isSolid() && !block.getRelative(BlockFace.UP).getType().isSolid() && target.getRelative(BlockFace.UP).getType() == Material.REDSTONE_WIRE) {
connections.add(face);
} else if (!target.getType().isSolid() && target.getRelative(BlockFace.DOWN).getType() == Material.REDSTONE_WIRE) {
connections.add(face);
}
break;
}
}
if (connections.isEmpty()) {
value.addAll(Arrays.asList(SIDES));
} else {
value.addAll(connections);
if (connections.size() == 1) {
value.add(connections.get(0).getOppositeFace());
}
}
return value;
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRedstone method updatePhysics.
@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
for (BlockFace face : ADJACENT) {
GlowBlock target = me.getRelative(face);
switch(target.getType()) {
case LEVER:
Lever lever = (Lever) target.getState().getData();
if (lever.isPowered()) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
break;
case STONE_BUTTON:
case WOOD_BUTTON:
Button button = (Button) target.getState().getData();
if (button.isPowered()) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
break;
case DIODE_BLOCK_ON:
Diode diode = (Diode) target.getState().getData();
if (face == diode.getFacing().getOppositeFace()) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
break;
case REDSTONE_BLOCK:
case REDSTONE_TORCH_ON:
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
case OBSERVER:
boolean powered = BlockObserver.isPowered(target);
BlockFace outputFace = BlockObserver.getFace(target).getOppositeFace();
if (powered && target.getRelative(outputFace).getLocation().equals(me.getLocation())) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
break;
default:
if (target.getType().isSolid() && target.getRelative(BlockFace.DOWN).getType() == Material.REDSTONE_TORCH_ON) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
if (target.getType().isSolid()) {
for (BlockFace face2 : ADJACENT) {
GlowBlock target2 = target.getRelative(face2);
if (target2.getType() == Material.DIODE_BLOCK_ON && ((Diode) target2.getState().getData()).getFacing() == target2.getFace(target)) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
} else if (target2.getType() == Material.STONE_BUTTON || target2.getType() == Material.WOOD_BUTTON) {
Button button2 = (Button) target2.getState().getData();
if (button2.isPowered() && button2.getAttachedFace() == target2.getFace(target)) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
} else if (target2.getType() == Material.LEVER) {
Lever lever2 = (Lever) target2.getState().getData();
if (lever2.isPowered() && lever2.getAttachedFace() == target2.getFace(target)) {
if (me.getData() != 15) {
me.setData((byte) 15);
extraUpdate(me);
}
return;
}
}
}
}
}
}
byte power = 0;
for (BlockFace face : calculateConnections(me)) {
if (face == BlockFace.DOWN) {
continue;
}
GlowBlock target = me.getRelative(face);
if (target.getType() != Material.REDSTONE_WIRE) {
if (!target.getType().isSolid()) {
target = target.getRelative(BlockFace.DOWN);
} else if (!me.getRelative(BlockFace.UP).getType().isSolid()) {
target = target.getRelative(BlockFace.UP);
}
if (target.getType() != Material.REDSTONE_WIRE) {
// There is no redstone wire here..
continue;
}
}
if (target.getData() > power) {
power = (byte) (target.getData() - 1);
}
}
if (power != me.getData()) {
me.setData(power);
extraUpdate(me);
new PulseTask(me, true, 1, true).startPulseTask();
}
}
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);
}
}
Aggregations