mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-25 12:05:56 +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,22 +223,31 @@ 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
|
||||
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
inventory.removeItem(clone)
|
||||
|
||||
if (item.isSimilar(next.key)) {
|
||||
val amount = next.value - item.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (next.key.isSimilar(clone)) {
|
||||
val amount = next.value - item.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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