use of net.glowstone.datapack.FuelManager in project Glowstone by GlowstoneMC.
the class FurnaceEntity method isBurnable.
private boolean isBurnable() {
GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
if ((burnTime != 0 || !InventoryUtil.isEmpty(inv.getFuel())) && !InventoryUtil.isEmpty(inv.getSmelting())) {
if ((InventoryUtil.isEmpty(inv.getFuel()) || InventoryUtil.isEmpty(inv.getSmelting())) && burnTime == 0) {
return false;
}
RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
if (burnTime != 0 || fm.isFuel(inv.getFuel().getType())) {
Recipe recipe = rm.getRecipe(inv);
if (recipe != null && (InventoryUtil.isEmpty(inv.getResult()) || inv.getResult().getType().equals(recipe.getResult().getType()) && inv.getResult().getAmount() + recipe.getResult().getAmount() <= recipe.getResult().getMaxStackSize())) {
return true;
}
}
}
return false;
}
use of net.glowstone.datapack.FuelManager in project Glowstone by GlowstoneMC.
the class GlowPlayerInventory method handleShiftClick.
@Override
public void handleShiftClick(GlowPlayer player, InventoryView view, int clickedSlot, ItemStack clickedItem) {
GlowInventory top = (GlowInventory) view.getTopInventory();
// If this is the default inventory try to equip the item as armor first
if (GlowInventoryView.isDefault(view)) {
clickedItem = tryToFillSlots(clickedItem, 36, 40);
}
// Check whether the top inventory allows shift clicking in any of it's slots
boolean topAllowsShiftClick = false;
for (int i = 0; i < top.getSize(); i++) {
if (top.itemShiftClickAllowed(i, clickedItem)) {
topAllowsShiftClick = true;
break;
}
}
if (topAllowsShiftClick) {
if (top.getType().equals(InventoryType.FURNACE)) {
RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
if (rm.getRecipe(top.getType(), new ItemStack[] { clickedItem }) != null) {
// move items are be burnable to the input slot
// TODO: Use of variable (INPUT_SLOT) instead of hard coded value ?
clickedItem = top.tryToFillSlots(clickedItem, 0, -1);
} else if (fm.isFuel(clickedItem.getType())) {
// move fuel items direct to fuel slot
// TODO: Use of variable (FUEL_SLOT) instead of hard coded value ?
clickedItem = top.tryToFillSlots(clickedItem, 1, -1);
} else {
// switch them between hotbar and main inventory depending on where they are now
if (view.convertSlot(clickedSlot) < 9 || view.convertSlot(clickedSlot) >= 36) {
// move from hotbar and armor to main inventory
clickedItem = tryToFillSlots(clickedItem, 9, 36);
} else {
// move from main inventory to hotbar
clickedItem = tryToFillSlots(clickedItem, 0, 9);
}
}
} else {
// move items to the top inventory
clickedItem = top.tryToFillSlots(clickedItem, 0, top.getSize());
}
} else {
// switch them between hotbar and main inventory depending on where they are now
if (view.convertSlot(clickedSlot) < 9 || view.convertSlot(clickedSlot) >= 36) {
// move from hotbar and armor to main inventory
clickedItem = tryToFillSlots(clickedItem, 9, 36);
} else {
// move from main inventory to hotbar
clickedItem = tryToFillSlots(clickedItem, 0, 9);
}
}
view.setItem(clickedSlot, clickedItem);
}
use of net.glowstone.datapack.FuelManager in project Glowstone by GlowstoneMC.
the class FurnaceEntity method burn.
/**
* Advances the cooking process for the tick.
*/
// TODO: Change block on burning
public void burn() {
GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
boolean sendChange = false;
if (burnTime > 0) {
burnTime--;
sendChange = true;
}
boolean isBurnable = isBurnable();
if (cookTime > 0 && isBurnable) {
cookTime++;
sendChange = true;
} else if (burnTime != 0) {
cookTime = 0;
sendChange = true;
}
if (cookTime == 0 && isBurnable) {
cookTime = 1;
sendChange = true;
}
if (burnTime == 0) {
if (isBurnable) {
FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
FurnaceBurnEvent burnEvent = new FurnaceBurnEvent(block, inv.getFuel(), fm.getFuelTime(inv.getFuel().getType()));
EventFactory.getInstance().callEvent(burnEvent);
if (!burnEvent.isCancelled() && burnEvent.isBurning()) {
burnTime = (short) burnEvent.getBurnTime();
burnTimeFuel = burnTime;
if (inv.getFuel().getAmount() == 1) {
if (inv.getFuel().getType().equals(Material.LAVA_BUCKET)) {
inv.setFuel(new ItemStack(Material.BUCKET));
} else {
inv.setFuel(null);
}
} else {
inv.getFuel().setAmount(inv.getFuel().getAmount() - 1);
}
sendChange = true;
} else if (cookTime != 0) {
if (cookTime % 2 == 0) {
cookTime = (short) (cookTime - 2);
} else {
cookTime--;
}
sendChange = true;
}
} else if (cookTime != 0) {
if (cookTime % 2 == 0) {
cookTime = (short) (cookTime - 2);
} else {
cookTime--;
}
sendChange = true;
}
}
if (cookTime == 200) {
RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
Recipe recipe = rm.getRecipe(inv);
if (recipe != null) {
FurnaceSmeltEvent smeltEvent = new FurnaceSmeltEvent(block, inv.getSmelting(), recipe.getResult());
EventFactory.getInstance().callEvent(smeltEvent);
if (!smeltEvent.isCancelled()) {
if (inv.getSmelting().getType().equals(Material.SPONGE) && inv.getSmelting().getData().getData() == 1 && inv.getFuel() != null && inv.getFuel().getType().equals(Material.BUCKET) && inv.getFuel().getAmount() == 1) {
inv.setFuel(new ItemStack(Material.WATER_BUCKET));
}
if (inv.getResult() == null || inv.getResult().getType().equals(Material.AIR)) {
inv.setResult(smeltEvent.getResult());
} else if (inv.getResult().getType().equals(smeltEvent.getResult().getType())) {
inv.getResult().setAmount(inv.getResult().getAmount() + smeltEvent.getResult().getAmount());
}
if (inv.getSmelting().getAmount() == 1) {
inv.setSmelting(null);
} else {
inv.getSmelting().setAmount(inv.getSmelting().getAmount() - 1);
}
}
cookTime = 0;
sendChange = true;
}
}
inv.getViewersSet().forEach(human -> {
human.setWindowProperty(Property.BURN_TIME, burnTime);
human.setWindowProperty(Property.TICKS_FOR_CURRENT_FUEL, burnTimeFuel);
human.setWindowProperty(Property.COOK_TIME, cookTime);
human.setWindowProperty(Property.TICKS_FOR_CURRENT_SMELTING, 200);
});
if (!isBurnable && burnTime == 0 && cookTime == 0) {
getState().getBlock().getWorld().cancelPulse(getState().getBlock());
sendChange = true;
}
if (sendChange) {
updateInRange();
}
}
Aggregations