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 tool = minion.getTool()
|
||||||
|
|
||||||
val recipes = Bukkit.getRecipesFor(tool ?: return)
|
val recipes = Bukkit.getRecipesFor(tool ?: return)
|
||||||
|
|
||||||
val shaped = arrayListOf<ShapedRecipe>()
|
val shaped = arrayListOf<ShapedRecipe>()
|
||||||
val shapeless = arrayListOf<ShapelessRecipe>()
|
val shapeless = arrayListOf<ShapelessRecipe>()
|
||||||
|
|
||||||
for (recipe in recipes) {
|
for (recipe in recipes) {
|
||||||
println("RECIPE!")
|
|
||||||
if (recipe is ShapedRecipe) {
|
if (recipe is ShapedRecipe) {
|
||||||
println("SHAPED!")
|
|
||||||
shaped.add(recipe)
|
shaped.add(recipe)
|
||||||
} else if (recipe is ShapelessRecipe) {
|
} else if (recipe is ShapelessRecipe) {
|
||||||
shapeless.add(recipe)
|
shapeless.add(recipe)
|
||||||
@ -159,13 +156,14 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
|||||||
private fun canCraftShaped(recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>): Boolean {
|
private fun canCraftShaped(recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>): Boolean {
|
||||||
val clone = contents.clone() as HashMap<ItemStack, Int>
|
val clone = contents.clone() as HashMap<ItemStack, Int>
|
||||||
for (recipeChoice in recipe.choiceMap.values) {
|
for (recipeChoice in recipe.choiceMap.values) {
|
||||||
|
if (recipeChoice == null) continue
|
||||||
var hasEnough = false
|
var hasEnough = false
|
||||||
|
|
||||||
val iterator = clone.entries.iterator()
|
val iterator = clone.entries.iterator()
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val next = iterator.next()
|
val next = iterator.next()
|
||||||
|
|
||||||
if (next.key.isSimilar(recipeChoice.itemStack) && next.value >= recipeChoice.itemStack.amount) {
|
if (recipeChoice.test(next.key)) {
|
||||||
hasEnough = true
|
hasEnough = true
|
||||||
val amount = next.value - recipeChoice.itemStack.amount
|
val amount = next.value - recipeChoice.itemStack.amount
|
||||||
if (amount == 0) {
|
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>) {
|
private fun doCraftShapeless(inventory: Inventory, recipe: ShapelessRecipe, contents: HashMap<ItemStack, Int>) {
|
||||||
for (recipeChoice in recipe.choiceList) {
|
for (recipeChoice in recipe.choiceList) {
|
||||||
|
if (recipeChoice == null) continue
|
||||||
val item = recipeChoice.itemStack.clone()
|
val item = recipeChoice.itemStack.clone()
|
||||||
|
|
||||||
inventory.removeItem(item)
|
inventory.removeItem(item)
|
||||||
@ -195,7 +194,7 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val next = iterator.next()
|
val next = iterator.next()
|
||||||
|
|
||||||
if (item.isSimilar(next.key)) {
|
if (recipeChoice.test(next.key)) {
|
||||||
val amount = next.value - item.amount
|
val amount = next.value - item.amount
|
||||||
if (amount == 0) {
|
if (amount == 0) {
|
||||||
iterator.remove()
|
iterator.remove()
|
||||||
@ -224,15 +223,22 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
|||||||
|
|
||||||
private fun doCraftShaped(inventory: Inventory, recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>) {
|
private fun doCraftShaped(inventory: Inventory, recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>) {
|
||||||
for (recipeChoice in recipe.choiceMap.values) {
|
for (recipeChoice in recipe.choiceMap.values) {
|
||||||
|
if (recipeChoice == null) continue
|
||||||
val item = recipeChoice.itemStack.clone()
|
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()
|
val iterator = contents.entries.iterator()
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val next = iterator.next()
|
val next = iterator.next()
|
||||||
|
|
||||||
if (item.isSimilar(next.key)) {
|
if (next.key.isSimilar(clone)) {
|
||||||
val amount = next.value - item.amount
|
val amount = next.value - item.amount
|
||||||
if (amount == 0) {
|
if (amount == 0) {
|
||||||
iterator.remove()
|
iterator.remove()
|
||||||
@ -243,6 +249,8 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val result = recipe.result.clone()
|
val result = recipe.result.clone()
|
||||||
inventory.addItem(result)
|
inventory.addItem(result)
|
||||||
|
@ -62,7 +62,7 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
val down = it.getRelative(BlockFace.DOWN).type
|
val down = it.getRelative(BlockFace.DOWN).type
|
||||||
loot.addAll(it.getDrops(minion.getTool()))
|
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)
|
it.type = getSaplingType(it.type)
|
||||||
} else {
|
} else {
|
||||||
it.type = Material.AIR
|
it.type = Material.AIR
|
||||||
@ -98,6 +98,14 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
Material.SPRUCE_SAPLING
|
Material.SPRUCE_SAPLING
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Material.MANGROVE_LOG -> {
|
||||||
|
Material.MANGROVE_PROPAGULE
|
||||||
|
}
|
||||||
|
|
||||||
|
Material.CHERRY_LOG -> {
|
||||||
|
Material.CHERRY_SAPLING
|
||||||
|
}
|
||||||
|
|
||||||
else -> Material.OAK_SAPLING
|
else -> Material.OAK_SAPLING
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user