use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method canAbsorb.
@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
MaterialData data = block.getState().getData();
BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
if (data instanceof DoublePlant) {
DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
if (species == DoublePlantSpecies.DOUBLE_TALLGRASS || species == DoublePlantSpecies.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(block, face)) {
block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
}
return true;
}
if (species == DoublePlantSpecies.PLANT_APEX) {
GlowBlock under = block.getRelative(BlockFace.DOWN);
MaterialData underData = under.getState().getData();
if (underData instanceof DoublePlant) {
DoublePlantSpecies underSpecies = ((DoublePlant) underData).getSpecies();
if (underSpecies == DoublePlantSpecies.DOUBLE_TALLGRASS || underSpecies == DoublePlantSpecies.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(block, face)) {
under.setType(Material.AIR, (byte) 0, false);
}
return true;
}
}
}
} else {
warnMaterialData(DoublePlant.class, data);
}
return false;
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockHopper method pullItems.
private void pullItems(GlowBlock block, HopperEntity hopper) {
GlowBlock source = block.getRelative(BlockFace.UP);
MaterialData data = source.getState().getData();
if (!source.getType().isSolid() || (data instanceof Step && !((Step) data).isInverted()) || (data instanceof WoodenStep && !((WoodenStep) data).isInverted()) || (data instanceof Sign) || (data instanceof Rails)) {
GlowItem item = getFirstDroppedItem(source.getLocation());
if (item == null) {
return;
}
ItemStack stack = item.getItemStack();
HashMap<Integer, ItemStack> add = hopper.getInventory().addItem(stack);
if (add.size() > 0) {
item.setItemStack(add.get(0));
} else {
item.remove();
}
} else if (source.getBlockEntity() != null && source.getBlockEntity() instanceof ContainerEntity) {
ContainerEntity sourceContainer = (ContainerEntity) source.getBlockEntity();
if (sourceContainer.getInventory() == null || sourceContainer.getInventory().getContents().length == 0) {
return;
}
ItemStack item = getFirstItem(sourceContainer);
if (item == null) {
return;
}
ItemStack clone = item.clone();
clone.setAmount(1);
if (hopper.getInventory().addItem(clone).size() > 0) {
return;
}
if (item.getAmount() - 1 == 0) {
sourceContainer.getInventory().remove(item);
} else {
item.setAmount(item.getAmount() - 1);
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockLever method extraUpdate.
private void extraUpdate(GlowBlock block) {
Lever lever = (Lever) block.getState().getData();
ItemTable itemTable = ItemTable.instance();
GlowBlock target = block.getRelative(lever.getAttachedFace());
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 BlockLog method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
// vanilla set leaf decay check in a 9x9x9 neighboring when a log block is removed
GlowWorld world = block.getWorld();
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));
if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
GlowBlockState state = b.getState();
if ((state.getRawData() & 0x08) == 0 && (state.getRawData() & 0x04) == 0) {
// check decay is off and decay is on
// set decay check on for this leaves block
state.setRawData((byte) (state.getRawData() | 0x08));
state.update(true);
}
}
}
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRails method getRailDirection.
private static RailDirection getRailDirection(GlowBlock rail) {
// north - 0, south - 1, east - 2, west - 3, ascending_north - 4, ascending_south - 5, ascending_east - 6, ascending_west - 7
boolean[] unstableRails = new boolean[8];
GlowBlock north = rail.getRelative(BlockFace.NORTH);
GlowBlock south = rail.getRelative(BlockFace.SOUTH);
GlowBlock east = rail.getRelative(BlockFace.EAST);
GlowBlock west = rail.getRelative(BlockFace.WEST);
unstableRails[NORTH] = isUnstable(north, rail) || isUnstable(north.getRelative(BlockFace.DOWN), rail);
unstableRails[SOUTH] = isUnstable(south, rail) || isUnstable(south.getRelative(BlockFace.DOWN), rail);
unstableRails[EAST] = isUnstable(east, rail) || isUnstable(east.getRelative(BlockFace.DOWN), rail);
unstableRails[WEST] = isUnstable(west, rail) || isUnstable(west.getRelative(BlockFace.DOWN), rail);
unstableRails[ASCENDING_NORTH] = isUnstable(north.getRelative(BlockFace.UP), rail);
unstableRails[ASCENDING_SOUTH] = isUnstable(south.getRelative(BlockFace.UP), rail);
unstableRails[ASCENDING_WEST] = isUnstable(east.getRelative(BlockFace.UP), rail);
unstableRails[ASCENDING_EAST] = isUnstable(west.getRelative(BlockFace.UP), rail);
// north && east || ascending_north && ascending_east || north && ascending_east || ascending_north && east
if (unstableRails[NORTH] && unstableRails[EAST] || unstableRails[ASCENDING_NORTH] && unstableRails[ASCENDING_EAST] || unstableRails[NORTH] && unstableRails[ASCENDING_EAST] || unstableRails[ASCENDING_NORTH] && unstableRails[EAST]) {
return RailDirection.NORTH_EAST;
}
// north && west || ascending_north && ascending_west || north && ascending_west || ascending_north && west
if (unstableRails[NORTH] && unstableRails[WEST] || unstableRails[ASCENDING_NORTH] && unstableRails[ASCENDING_WEST] || unstableRails[NORTH] && unstableRails[ASCENDING_WEST] || unstableRails[ASCENDING_NORTH] && unstableRails[WEST]) {
return RailDirection.NORTH_WEST;
}
// south && west || ascending_south && ascending_west || south && ascending_west || ascending_south && west
if (unstableRails[SOUTH] && unstableRails[WEST] || unstableRails[ASCENDING_SOUTH] && unstableRails[ASCENDING_WEST] || unstableRails[SOUTH] && unstableRails[ASCENDING_WEST] || unstableRails[ASCENDING_SOUTH] && unstableRails[WEST]) {
return RailDirection.SOUTH_WEST;
}
// south && east || ascending_south && ascending_east || south && ascending_east || ascending_south && east
if (unstableRails[SOUTH] && unstableRails[EAST] || unstableRails[ASCENDING_SOUTH] && unstableRails[ASCENDING_EAST] || unstableRails[SOUTH] && unstableRails[ASCENDING_EAST] || unstableRails[ASCENDING_SOUTH] && unstableRails[EAST]) {
return RailDirection.SOUTH_EAST;
}
// ascending_north && south || ascending_north
if (unstableRails[ASCENDING_NORTH] && unstableRails[SOUTH] || unstableRails[ASCENDING_NORTH]) {
return RailDirection.ASCENDING_NORTH;
}
// ascending_south && north || ascending_south
if (unstableRails[ASCENDING_SOUTH] && unstableRails[NORTH] || unstableRails[ASCENDING_SOUTH]) {
return RailDirection.ASCENDING_SOUTH;
}
// ascending_east && west || ascending_east
if (unstableRails[ASCENDING_EAST] && unstableRails[WEST] || unstableRails[ASCENDING_EAST]) {
return RailDirection.ASCENDING_EAST;
}
// ascending_west && east || ascending_west
if (unstableRails[ASCENDING_WEST] && unstableRails[EAST] || unstableRails[ASCENDING_WEST]) {
return RailDirection.ASCENDING_WEST;
}
// north || south
if (unstableRails[NORTH] || unstableRails[SOUTH]) {
return RailDirection.NORTH_SOUTH;
}
// east || west
if (unstableRails[EAST] || unstableRails[WEST]) {
return RailDirection.EAST_WEST;
}
// return current rail direction.
return RailDirection.getRailDirection(rail);
}
Aggregations