use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
MaterialData data = block.getState().getData();
if (data instanceof DoublePlant) {
DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
if (species == DoublePlantSpecies.PLANT_APEX) {
GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
if (!(blockUnder.getState().getData() instanceof DoublePlant)) {
return;
}
blockUnder.setType(Material.AIR);
} else {
GlowBlock blockTop = block.getRelative(BlockFace.UP);
if (!(blockTop.getState().getData() instanceof DoublePlant)) {
return;
}
blockTop.setType(Material.AIR);
}
} else {
warnMaterialData(DoublePlant.class, data);
}
}
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);
}
}
}
}
}
}
Aggregations