-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Repair Kit and a crafting recipe with it to repair tools
- Loading branch information
Showing
10 changed files
with
134 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/com/github/kill05/recipe/RecipeEntryRepairTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.github.kill05.recipe; | ||
|
||
import com.github.kill05.ArchitectTools; | ||
import com.github.kill05.items.part.ArchitectPart; | ||
import com.github.kill05.items.part.PartType; | ||
import com.github.kill05.items.tool.ArchitectTool; | ||
import com.github.kill05.items.tool.ToolPartInfo; | ||
import com.github.kill05.materials.ArchitectMaterial; | ||
import net.minecraft.core.data.registry.recipe.SearchQuery; | ||
import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCraftingDynamic; | ||
import net.minecraft.core.item.ItemStack; | ||
import net.minecraft.core.player.inventory.InventoryCrafting; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Map; | ||
|
||
public class RecipeEntryRepairTool extends RecipeEntryCraftingDynamic { | ||
|
||
@Override | ||
public boolean matches(InventoryCrafting inv) { | ||
ItemStack repairKit = getRepairKit(inv); | ||
ItemStack tool = getTool(inv); | ||
|
||
if(repairKit == null || tool == null) return false; | ||
for(int i = 0; i < inv.getSizeInventory(); i++) { | ||
ItemStack itemStack = inv.getStackInSlot(i); | ||
if(itemStack != null && itemStack != tool && itemStack != repairKit) return false; | ||
} | ||
|
||
ArchitectMaterial kitMaterial = ArchitectTools.getPartMaterial(repairKit); | ||
if(kitMaterial == null) return false; | ||
|
||
for (Map.Entry<@NotNull ToolPartInfo, @Nullable ArchitectMaterial> entry : ArchitectTools.getToolParts(tool, PartType.HEAD).entrySet()) { | ||
if(entry.getValue() == kitMaterial) return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean matchesQuery(SearchQuery searchQuery) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ItemStack getCraftingResult(InventoryCrafting inv) { | ||
ItemStack tool = getTool(inv); | ||
if(tool == null) throw new AssertionError(); | ||
|
||
ItemStack itemStack = tool.copy(); | ||
itemStack.setMetadata(0); | ||
return itemStack; | ||
} | ||
|
||
@Override | ||
public int getRecipeSize() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public ItemStack[] onCraftResult(InventoryCrafting inv) { | ||
ItemStack[] items = new ItemStack[inv.getSizeInventory()]; | ||
|
||
for(int i = 0; i < inv.getSizeInventory(); i++) { | ||
ItemStack itemStack = inv.getStackInSlot(i); | ||
if(itemStack == null) continue; | ||
|
||
if(--itemStack.stackSize <= 0) { | ||
inv.setInventorySlotContents(i, null); | ||
} | ||
} | ||
|
||
return items; | ||
} | ||
|
||
|
||
private ItemStack getTool(InventoryCrafting inv) { | ||
ItemStack tool = null; | ||
|
||
for(int i = 0; i < inv.getSizeInventory(); i++) { | ||
ItemStack itemStack = inv.getStackInSlot(i); | ||
if(itemStack == null) continue; | ||
|
||
if(itemStack.getItem() instanceof ArchitectTool) { | ||
if(tool != null) return null; | ||
tool = itemStack; | ||
} | ||
} | ||
|
||
return tool; | ||
} | ||
|
||
private ItemStack getRepairKit(InventoryCrafting inv) { | ||
ItemStack repairKit = null; | ||
|
||
for(int i = 0; i < inv.getSizeInventory(); i++) { | ||
ItemStack itemStack = inv.getStackInSlot(i); | ||
if(itemStack == null) continue; | ||
|
||
if(itemStack.getItem() == ArchitectPart.REPAIR_KIT) { | ||
if(repairKit != null) return null; | ||
repairKit = itemStack; | ||
} | ||
} | ||
|
||
return repairKit; | ||
} | ||
|
||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters