mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-29 12:45:18 +01:00
Fix crafter
This commit is contained in:
parent
34958d0a59
commit
c78ed9551b
@ -55,14 +55,11 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
val tool = minion.getTool()
|
||||
|
||||
val recipes = Bukkit.getRecipesFor(tool ?: return)
|
||||
|
||||
val shaped = arrayListOf<ShapedRecipe>()
|
||||
val shapeless = arrayListOf<ShapelessRecipe>()
|
||||
|
||||
for (recipe in recipes) {
|
||||
println("RECIPE!")
|
||||
if (recipe is ShapedRecipe) {
|
||||
println("SHAPED!")
|
||||
shaped.add(recipe)
|
||||
} else if (recipe is ShapelessRecipe) {
|
||||
shapeless.add(recipe)
|
||||
@ -159,13 +156,14 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
private fun canCraftShaped(recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>): Boolean {
|
||||
val clone = contents.clone() as HashMap<ItemStack, Int>
|
||||
for (recipeChoice in recipe.choiceMap.values) {
|
||||
if (recipeChoice == null) continue
|
||||
var hasEnough = false
|
||||
|
||||
val iterator = clone.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (next.key.isSimilar(recipeChoice.itemStack) && next.value >= recipeChoice.itemStack.amount) {
|
||||
if (recipeChoice.test(next.key)) {
|
||||
hasEnough = true
|
||||
val amount = next.value - recipeChoice.itemStack.amount
|
||||
if (amount == 0) {
|
||||
@ -187,6 +185,7 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
|
||||
private fun doCraftShapeless(inventory: Inventory, recipe: ShapelessRecipe, contents: HashMap<ItemStack, Int>) {
|
||||
for (recipeChoice in recipe.choiceList) {
|
||||
if (recipeChoice == null) continue
|
||||
val item = recipeChoice.itemStack.clone()
|
||||
|
||||
inventory.removeItem(item)
|
||||
@ -195,7 +194,7 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (item.isSimilar(next.key)) {
|
||||
if (recipeChoice.test(next.key)) {
|
||||
val amount = next.value - item.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
@ -224,15 +223,22 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
|
||||
private fun doCraftShaped(inventory: Inventory, recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>) {
|
||||
for (recipeChoice in recipe.choiceMap.values) {
|
||||
if (recipeChoice == null) continue
|
||||
val item = recipeChoice.itemStack.clone()
|
||||
|
||||
inventory.removeItem(item)
|
||||
for (content in inventory.contents) {
|
||||
if (content == null || content.type.isAir) continue
|
||||
if (recipeChoice.test(content)) {
|
||||
val clone = content.clone()
|
||||
clone.amount = item.amount
|
||||
|
||||
inventory.removeItem(clone)
|
||||
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (item.isSimilar(next.key)) {
|
||||
if (next.key.isSimilar(clone)) {
|
||||
val amount = next.value - item.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
@ -243,6 +249,8 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val result = recipe.result.clone()
|
||||
inventory.addItem(result)
|
||||
|
@ -62,7 +62,7 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
|
||||
val down = it.getRelative(BlockFace.DOWN).type
|
||||
loot.addAll(it.getDrops(minion.getTool()))
|
||||
|
||||
if (down == Material.DIRT || down == Material.GRASS_BLOCK || down == Material.COARSE_DIRT || down == Material.ROOTED_DIRT || down == Material.DIRT_PATH) {
|
||||
if (down == Material.DIRT || down == Material.GRASS_BLOCK || down == Material.COARSE_DIRT || down == Material.ROOTED_DIRT || down == Material.DIRT_PATH || down == Material.MUD || down == Material.MUDDY_MANGROVE_ROOTS) {
|
||||
it.type = getSaplingType(it.type)
|
||||
} else {
|
||||
it.type = Material.AIR
|
||||
@ -98,6 +98,14 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
|
||||
Material.SPRUCE_SAPLING
|
||||
}
|
||||
|
||||
Material.MANGROVE_LOG -> {
|
||||
Material.MANGROVE_PROPAGULE
|
||||
}
|
||||
|
||||
Material.CHERRY_LOG -> {
|
||||
Material.CHERRY_SAPLING
|
||||
}
|
||||
|
||||
else -> Material.OAK_SAPLING
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user