I'm trying to create a plugin that will make a furnace remain lit and not require additional fuel when lava is placed on four surrounding sides. To do this, I want to detect when a lava source block is touching the 3 horizontal sides that are not the furnace face as well as the top of the furnace. To do this, I'm currently trying to use an InventoryClickEvent to detect when a certain item is placed in the fuel space then call a method that checks if the furnace is surrounded by lava. If both of these are true, the furnace should become lit and remain that way. For the life of me I can't seem to get this to work.
Current code is here -
Event Method:
Adjacent Block Check:
Current code is here -
Event Method:
Java:
public void furnaceFuelEvent(InventoryClickEvent event) {
Inventory inv = event.getClickedInventory();
if (inv.getType().getDefaultTitle() == "Furnace") {
InventoryHolder invholder = inv.getHolder();
Block c = (Block) invholder;
Material m = c.getType();
Lightable lightable = (Lightable) c.getBlockData();
boolean fplace = new FurnacePlace().onFurnPlace(c);
int x = c.getLocation().getBlockX();
int y = c.getLocation().getBlockY();
int z = c.getLocation().getBlockZ();
Furnace furnace = (Furnace) c;
BlockData furnData = m.createBlockData("lit=true");
BlastFurnace bfurnace = (BlastFurnace) furnace;
InventoryType.SlotType type = event.getSlotType();
ItemStack istack = event.getCurrentItem();
Material fuel = istack.getType();
short burntime = 32000;
if (fuel == Material.CONDUIT) {
if (type == InventoryType.SlotType.FUEL) {
if (fplace == true) {
furnace.setBurnTime(burntime);
lightable.setLit(true);
furnace.update();
}
}
}
} else {
return;
}
}
}
Adjacent Block Check:
Java:
class FurnacePlace {
public boolean onFurnPlace(Block b) {
Material m = b.getType();
BlockData mData = m.createBlockData();
int x = b.getLocation().getBlockX();
int y = b.getLocation().getBlockY();
int z = b.getLocation().getBlockZ();
Block east = b.getRelative(BlockFace.EAST, 1);
Block west = b.getRelative(BlockFace.WEST, 1);
Block north = b.getRelative(BlockFace.NORTH, 1);
Block south = b.getRelative(BlockFace.SOUTH, 1);
Block up = b.getRelative(BlockFace.UP, 1);
Furnace f = (Furnace) b;
Directional furn = (Directional) b;
BlockFace facing = furn.getFacing();
if (facing == BlockFace.WEST && (m == Material.FURNACE || m== Material.BLAST_FURNACE)) {
if (east.getType() == Material.LAVA && north.getType() == Material.LAVA && south.getType() == Material.LAVA && up.getType() == Material.LAVA) {
return true;
}
} else if (facing == BlockFace.NORTH && (m == Material.FURNACE || m== Material.BLAST_FURNACE)) {
if (east.getType() == Material.LAVA && west.getType() == Material.LAVA && south.getType() == Material.LAVA && up.getType() == Material.LAVA) {
return true;
}
} else if (facing == BlockFace.SOUTH && (m == Material.FURNACE || m== Material.BLAST_FURNACE)) {
if (east.getType() == Material.LAVA && north.getType() == Material.LAVA && west.getType() == Material.LAVA && up.getType() == Material.LAVA) {
return true;
}
} else if (facing == BlockFace.EAST && (m == Material.FURNACE || m== Material.BLAST_FURNACE)) {
if (west.getType() == Material.LAVA && north.getType() == Material.LAVA && south.getType() == Material.LAVA && up.getType() == Material.LAVA) {
return true;
}
} else {
return false;
}
return false;
}
}