Skip to content

Commit

Permalink
add tags material.is_fuel, fuel_burn_time
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 26, 2020
1 parent 5240ef1 commit 34a31e4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
Expand Up @@ -17,6 +17,8 @@

public abstract class ItemHelper {

public abstract Integer burnTime(Material material);

public abstract Recipe getRecipeById(NamespacedKey key);

public abstract void removeRecipe(NamespacedKey key);
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.denizenscript.denizen.utilities.blocks.ModernBlockData;
import com.denizenscript.denizen.nms.interfaces.BlockData;
import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.Attribute;
Expand Down Expand Up @@ -741,6 +742,29 @@ public static void registerTags() {
return new ElementTag(object.material.isFlammable());
});

// <--[tag]
// @attribute <MaterialTag.is_fuel>
// @returns ElementTag(Boolean)
// @description
// Returns whether the material is a block that can be burned in a furnace as fuel.
// -->
registerTag("is_fuel", (attribute, object) -> {
return new ElementTag(object.material.isFuel());
});

// <--[tag]
// @attribute <MaterialTag.fuel_burn_time>
// @returns DurationTag
// @description
// Returns the duration that a burnable fuel block will burn in a furnace for.
// -->
registerTag("fuel_burn_time", (attribute, object) -> {
Integer ticks = NMSHandler.getItemHelper().burnTime(object.getMaterial());
if (ticks != null) {
return new DurationTag(ticks.longValue());
}
});

// <--[tag]
// @attribute <MaterialTag.is_occluding>
// @returns ElementTag(Boolean)
Expand Down
Expand Up @@ -25,6 +25,11 @@

public class ItemHelperImpl extends ItemHelper {

@Override
public Integer burnTime(Material material) {
throw new UnsupportedOperationException();
}

@Override
public Recipe getRecipeById(NamespacedKey key) {
throw new UnsupportedOperationException();
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftNamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
Expand All @@ -38,6 +39,11 @@ public static IRecipe getNMSRecipe(NamespacedKey key) {
return recipeMap.get(nmsKey);
}

@Override
public Integer burnTime(Material material) {
return TileEntityFurnace.p().get(CraftMagicNumbers.getItem(material));
}

@Override
public Recipe getRecipeById(NamespacedKey key) {
IRecipe recipe = getNMSRecipe(key);
Expand Down
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryPlayer;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNamespacedKey;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
Expand All @@ -42,6 +43,11 @@ public static IRecipe<?> getNMSRecipe(NamespacedKey key) {
return null;
}

@Override
public Integer burnTime(Material material) {
return TileEntityFurnace.f().get(CraftMagicNumbers.getItem(material));
}

@Override
public Recipe getRecipeById(NamespacedKey key) {
IRecipe<?> recipe = getNMSRecipe(key);
Expand Down
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryPlayer;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftNamespacedKey;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
Expand All @@ -42,6 +43,11 @@ public static IRecipe<?> getNMSRecipe(NamespacedKey key) {
return null;
}

@Override
public Integer burnTime(Material material) {
return TileEntityFurnace.f().get(CraftMagicNumbers.getItem(material));
}

@Override
public Recipe getRecipeById(NamespacedKey key) {
IRecipe<?> recipe = getNMSRecipe(key);
Expand Down

0 comments on commit 34a31e4

Please sign in to comment.