Skip to content

Commit

Permalink
FurnaceInventory Support (#2034)
Browse files Browse the repository at this point in the history
* Add Furnace Mechanisms

* Add Furnace Tags

* Fix Code Style
  • Loading branch information
CounterCrysis authored and mcmonkey4eva committed Sep 19, 2019
1 parent fdc4f53 commit 664393a
Showing 1 changed file with 109 additions and 10 deletions.
119 changes: 109 additions & 10 deletions plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java
Expand Up @@ -652,6 +652,20 @@ else if (inventory instanceof HorseInventory) {
return equipmentList;
}

public ItemTag getFuel() {
if (inventory instanceof FurnaceInventory) {
return new ItemTag(((FurnaceInventory) inventory).getFuel());
}
return null;
}

public ItemTag getSmelting() {
if (inventory instanceof FurnaceInventory) {
return new ItemTag(((FurnaceInventory) inventory).getSmelting());
}
return null;
}

public InventoryType getInventoryType() {
return inventory.getType();
}
Expand Down Expand Up @@ -2183,15 +2197,21 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
// @attribute <InventoryTag.result>
// @returns ItemTag
// @description
// Returns the item currently in the result section of a crafting inventory.
// Returns the item currently in the result section of a crafting inventory or furnace inventory.
// -->
registerTag("result", new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
if (!(((InventoryTag) object).inventory instanceof CraftingInventory)) {
ItemStack result;
if ((((InventoryTag) object).inventory instanceof CraftingInventory)) {
result = ((CraftingInventory) ((InventoryTag) object).inventory).getResult();
}
else if ((((InventoryTag) object).inventory instanceof FurnaceInventory)) {
result = ((FurnaceInventory) ((InventoryTag) object).inventory).getResult();
}
else {
return null;
}
ItemStack result = ((CraftingInventory) ((InventoryTag) object).inventory).getResult();
if (result == null) {
return null;
}
Expand Down Expand Up @@ -2249,6 +2269,42 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
}
});

// <--[tag]
// @attribute <InventoryTag.fuel>
// @returns ItemTag
// @mechanism fuel
// @description
// Returns the item currently in the fuel section of a furnace inventory.
// -->
registerTag("fuel", new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
ItemTag fuel = ((InventoryTag) object).getFuel();
if (fuel == null) {
return null;
}
return fuel.getObjectAttribute(attribute.fulfill(1));
}
});

// <--[tag]
// @attribute <InventoryTag.smelting>
// @returns ItemTag
// @mechanism smelting
// @description
// Returns the item currently in the smelting section of a furnace inventory.
// -->
registerTag("smelting", new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
ItemTag smelting = ((InventoryTag) object).getSmelting();
if (smelting == null) {
return null;
}
return smelting.getObjectAttribute(attribute.fulfill(1));
}
});

// <--[tag]
// @attribute <InventoryTag.type>
// @returns ElementTag
Expand Down Expand Up @@ -2327,18 +2383,61 @@ public void adjust(Mechanism mechanism) {
// @name result
// @input ItemTag
// @description
// Sets the item in the result slot of this crafting inventory.
// Sets the item in the result slot of this crafting inventory or furnace inventory.
// @tags
// <InventoryTag.result>
// -->
if (mechanism.matches("result") && mechanism.requireObject(ItemTag.class)) {
if (!(inventory instanceof CraftingInventory)) {
Debug.echoError("Inventory is not a crafting inventory, cannot set result.");
return;
if (inventory instanceof CraftingInventory) {
CraftingInventory craftingInventory = (CraftingInventory) inventory;
craftingInventory.setResult(mechanism.valueAsType(ItemTag.class).getItemStack());
((Player) inventory.getHolder()).updateInventory();
}
else if (inventory instanceof FurnaceInventory) {
FurnaceInventory furnaceInventory = (FurnaceInventory) inventory;
furnaceInventory.setResult(mechanism.valueAsType(ItemTag.class).getItemStack());
}
else {
Debug.echoError("Inventory is not a crafting inventory or furnace inventory, cannot set result.");
}
}

// <--[mechanism]
// @object InventoryTag
// @name fuel
// @input ItemTag
// @description
// Sets the item in the fuel slot of this furnace inventory.
// @tags
// <InventoryTag.fuel>
// -->
if (mechanism.matches("fuel") && mechanism.requireObject(ItemTag.class)) {
if (inventory instanceof FurnaceInventory) {
FurnaceInventory furnaceInventory = (FurnaceInventory) inventory;
furnaceInventory.setFuel(mechanism.valueAsType(ItemTag.class).getItemStack());
}
else {
Debug.echoError("Inventory is not a furnace inventory, cannot set fuel.");
}
}

// <--[mechanism]
// @object InventoryTag
// @name smelting
// @input ItemTag
// @description
// Sets the item in the smelting slot of this furnace inventory.
// @tags
// <InventoryTag.smelting>
// -->
if (mechanism.matches("smelting") && mechanism.requireObject(ItemTag.class)) {
if (inventory instanceof FurnaceInventory) {
FurnaceInventory furnaceInventory = (FurnaceInventory) inventory;
furnaceInventory.setSmelting(mechanism.valueAsType(ItemTag.class).getItemStack());
}
else {
Debug.echoError("Inventory is not a furnace inventory, cannot set smelting.");
}
CraftingInventory craftingInventory = (CraftingInventory) inventory;
craftingInventory.setResult(mechanism.valueAsType(ItemTag.class).getItemStack());
((Player) inventory.getHolder()).updateInventory();
}

// <--[mechanism]
Expand Down

0 comments on commit 664393a

Please sign in to comment.