Skip to content

Commit

Permalink
Fix crafting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zelytra committed Aug 27, 2021
1 parent cd5c181 commit 49b588f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.zelytra.daedalus.Daedalus;
import fr.zelytra.daedalus.managers.items.CustomItemStack;
import fr.zelytra.daedalus.managers.items.CustomMaterial;
import fr.zelytra.daedalus.managers.languages.Lang;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -66,29 +67,31 @@ public void register() {
CraftPattern[] craftPatterns = new CraftPattern(this.shapedRecipe.getShape()).getAllPossibilities();
int count = 0;
for (CraftPattern pattern : craftPatterns) {
NamespacedKey key;
ShapedRecipe recipe;
if (material != null) {
key = new NamespacedKey(Daedalus.getInstance(), material.getName() + count);
recipe = new ShapedRecipe(key, new CustomItemStack(material, this.amount).getItem());
}else {
key = new NamespacedKey(Daedalus.getInstance(), vanillaMaterial.name() + count);
recipe = new ShapedRecipe(key, new ItemStack(vanillaMaterial, this.amount));
}
recipe.shape(pattern.getShapeArray());
for (Lang lang : Lang.values()) {
NamespacedKey key;
ShapedRecipe recipe;
if (material != null) {
key = new NamespacedKey(Daedalus.getInstance(), material.getName() + count);
recipe = new ShapedRecipe(key, new CustomItemStack(material, lang).getItem());
} else {
key = new NamespacedKey(Daedalus.getInstance(), vanillaMaterial.name() + count);
recipe = new ShapedRecipe(key, new ItemStack(vanillaMaterial, this.amount));
}
recipe.shape(pattern.getShapeArray());

for (Map.Entry<Character, ItemStack> map : this.shapedRecipe.getIngredientMap().entrySet()) {
if (map.getValue() != null) {
if (CustomItemStack.hasTag(map.getValue())) {
RecipeChoice.ExactChoice item = new RecipeChoice.ExactChoice(new CustomItemStack(CustomItemStack.getCustomMaterial(map.getValue()), amount).getItem());
recipe.setIngredient(map.getKey(), item);
} else {
recipe.setIngredient(map.getKey(), map.getValue().getType());
for (Map.Entry<Character, ItemStack> map : this.shapedRecipe.getIngredientMap().entrySet()) {
if (map.getValue() != null) {
if (CustomItemStack.hasTag(map.getValue())) {
RecipeChoice.ExactChoice item = new RecipeChoice.ExactChoice(new CustomItemStack(CustomItemStack.getCustomMaterial(map.getValue()), lang).getItem());
recipe.setIngredient(map.getKey(), item);
} else {
recipe.setIngredient(map.getKey(), map.getValue().getType());
}
}
}
Daedalus.getInstance().getServer().addRecipe(recipe);
count++;
}
Daedalus.getInstance().getServer().addRecipe(recipe);
count++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public void onCraft(PrepareItemCraftEvent e) {
meta.setLore(lore);

result.setItemMeta(meta);

if (result == null)
return;

e.getInventory().setResult(result);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.zelytra.daedalus.events.running.environnement.respawnable;

import fr.zelytra.daedalus.managers.game.settings.BlockCooldownEnum;
import fr.zelytra.daedalus.managers.game.settings.GameSettings;
import fr.zelytra.daedalus.managers.items.CustomItemStack;
import fr.zelytra.daedalus.managers.items.CustomMaterial;
import org.bukkit.Material;
Expand Down Expand Up @@ -65,7 +66,10 @@ public Material getMaterial() {
}

public ItemStack getItemStack() {
return itemStack;
if (CustomItemStack.hasTag(itemStack))
return new CustomItemStack(CustomItemStack.getCustomMaterial(itemStack), GameSettings.LANG).getItem();
else
return itemStack;
}

public boolean hasItemStack() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fr.zelytra.daedalus.Daedalus;
import fr.zelytra.daedalus.managers.game.settings.GameSettings;
import fr.zelytra.daedalus.managers.languages.Lang;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
Expand Down Expand Up @@ -118,6 +119,48 @@ public CustomItemStack(CustomMaterial material) {

}

public CustomItemStack(CustomMaterial material, Lang lang) {

this.customMaterial = material;
switch (material.getItemType()) {
case ARMOR:
this.item = new ItemStack(this.customMaterial.getVanillaMaterial());
ItemMeta meta = this.item.getItemMeta();
assert meta != null;
meta.setCustomModelData(this.customMaterial.getCustomModelData());
meta.setDisplayName(this.customMaterial.getDisplayName(lang));

meta.addAttributeModifier(Attribute.GENERIC_ARMOR, AttributeGenerator.armor(material.getArmor(), material.getSlot()));
meta.addAttributeModifier(Attribute.GENERIC_MAX_HEALTH, AttributeGenerator.extraHeart(material.getExtraHeart(), material.getSlot()));

PersistentDataContainer itemData = meta.getPersistentDataContainer();
itemData.set(itemKey, PersistentDataType.STRING, this.customMaterial.getName());
//itemData.set(descriptionKey, PersistentDataType.STRING, );
//meta.setLore(lore);
this.item.setItemMeta(meta);
break;

default:
this.item = new ItemStack(this.customMaterial.getVanillaMaterial());
meta = this.item.getItemMeta();
assert meta != null;
meta.setCustomModelData(this.customMaterial.getCustomModelData());
meta.setDisplayName(this.customMaterial.getDisplayName(lang));
itemData = meta.getPersistentDataContainer();
itemData.set(itemKey, PersistentDataType.STRING, this.customMaterial.getName());
//itemData.set(descriptionKey, PersistentDataType.STRING, );
//meta.setLore(lore);
this.item.setItemMeta(meta);

if (material == CustomMaterial.DIONYSUS_CUP)
dionysosMugInit();

break;

}

}

private void dionysosMugInit() {
ItemMeta meta = this.item.getItemMeta();
PersistentDataContainer itemData = meta.getPersistentDataContainer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.zelytra.daedalus.managers.items;

import fr.zelytra.daedalus.managers.game.settings.GameSettings;
import fr.zelytra.daedalus.managers.languages.Lang;
import org.bukkit.Material;
import org.bukkit.inventory.EquipmentSlot;

Expand Down Expand Up @@ -89,6 +90,10 @@ public String getDisplayName() {
return GameSettings.LANG.textOf(displayName);
}

public String getDisplayName(Lang lang) {
return lang.textOf(displayName);
}

public String getName() {
return name;
}
Expand Down

0 comments on commit 49b588f

Please sign in to comment.