mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 13:09:11 +00:00
New Anvil Recipe System
This commit is contained in:
1 parent
9cda5503ed
commit
48dd7bedea
15 files changed
+592
-221
No files matched your search
@@ -6,6 +6,7 @@ import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,6 +17,7 @@ public class ContainerManageRecipes extends Container
|
||||
{
|
||||
private InventoryBasic craftingMatrix;
|
||||
public RecipeCarpentry recipe;
|
||||
public RecipeAnvil recipeAnvil;
|
||||
public int size;
|
||||
public int width;
|
||||
private boolean init = false;
|
||||
@@ -25,14 +27,21 @@ public class ContainerManageRecipes extends Container
|
||||
this.width = size;
|
||||
craftingMatrix = new InventoryBasic("crafting", false, this.size + 1);
|
||||
recipe = new RecipeCarpentry("");
|
||||
addSlotToContainer(new Slot(craftingMatrix,0,87,61));
|
||||
recipeAnvil = new RecipeAnvil();
|
||||
|
||||
if(width == 1){
|
||||
addSlotToContainer(new Slot(craftingMatrix,0,102,35));
|
||||
}
|
||||
else {
|
||||
addSlotToContainer(new Slot(craftingMatrix,0,87,61));
|
||||
}
|
||||
|
||||
for(int i = 0; i < size;i++){
|
||||
for(int j = 0; j < size;j++){
|
||||
addSlotToContainer(new Slot(craftingMatrix, i * width + j + 1,j*18 + 8, i*18 + 35));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int i1 = 0; i1 < 3; i1++)
|
||||
{
|
||||
for(int l1 = 0; l1 < 9; l1++)
|
||||
@@ -57,7 +66,7 @@ public class ContainerManageRecipes extends Container
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void setRecipe(RecipeCarpentry recipe) {
|
||||
craftingMatrix.setInventorySlotContents(0,recipe.getRecipeOutput());
|
||||
for(int i = 0; i < width;i++){
|
||||
@@ -70,85 +79,116 @@ public class ContainerManageRecipes extends Container
|
||||
}
|
||||
this.recipe = recipe;
|
||||
}
|
||||
public void saveRecipe(){
|
||||
int nextChar = 0;
|
||||
char[] chars = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
|
||||
Map<ItemStack,Character> nameMapping = new HashMap<ItemStack,Character>();
|
||||
int firstRow = width,lastRow = 0,firstColumn = width,lastColumn = 0;
|
||||
boolean seenRow = false;
|
||||
for(int i = 0; i < width;i++){
|
||||
boolean seenColumn = false;
|
||||
for(int j = 0; j < width;j++){
|
||||
ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1);
|
||||
if(item == null){
|
||||
continue;
|
||||
}else{
|
||||
if(!seenColumn && j < firstColumn){
|
||||
firstColumn = j;
|
||||
}
|
||||
if(j > lastColumn)
|
||||
lastColumn = j;
|
||||
|
||||
seenColumn = true;
|
||||
}
|
||||
Character letter = null;
|
||||
for(ItemStack mapped : nameMapping.keySet()){
|
||||
if(NoppesUtilPlayer.compareItems(mapped, item, recipe.ignoreDamage, recipe.ignoreNBT))
|
||||
letter = nameMapping.get(mapped);
|
||||
}
|
||||
if(letter == null){
|
||||
letter = chars[nextChar];
|
||||
nextChar++;
|
||||
nameMapping.put(item, letter);
|
||||
}
|
||||
}
|
||||
if(seenColumn){
|
||||
if(!seenRow){
|
||||
firstRow = i;
|
||||
lastRow = i;
|
||||
seenRow = true;
|
||||
}
|
||||
else{
|
||||
lastRow = i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ArrayList<Object> recipe = new ArrayList<Object>();
|
||||
|
||||
for(int i = 0; i < width;i++){
|
||||
if(i < firstRow || i > lastRow)
|
||||
continue;
|
||||
String row = "";
|
||||
for(int j = 0; j < width;j++){
|
||||
if(j < firstColumn|| j > lastColumn)
|
||||
continue;
|
||||
ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1);
|
||||
if(item == null){
|
||||
row += " ";
|
||||
continue;
|
||||
}
|
||||
public void setRecipe(RecipeAnvil recipe) {
|
||||
if (recipe.itemToRepair != null) {
|
||||
ItemStack output = recipe.itemToRepair.copy();
|
||||
if (output.isItemStackDamageable()) {
|
||||
output.setItemDamage(0);
|
||||
}
|
||||
craftingMatrix.setInventorySlotContents(0, output);
|
||||
} else {
|
||||
craftingMatrix.setInventorySlotContents(0, null);
|
||||
}
|
||||
|
||||
for(ItemStack mapped : nameMapping.keySet()){
|
||||
if(NoppesUtilPlayer.compareItems(mapped, item, false, false)){
|
||||
row += nameMapping.get(mapped);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
recipe.add(row);
|
||||
}
|
||||
if(nameMapping.isEmpty()){
|
||||
RecipeCarpentry r = new RecipeCarpentry(this.recipe.name);
|
||||
r.copy(this.recipe);
|
||||
this.recipe = r;
|
||||
return;
|
||||
}
|
||||
for(ItemStack mapped : nameMapping.keySet()){
|
||||
Character letter = nameMapping.get(mapped);
|
||||
recipe.add(letter);
|
||||
recipe.add(mapped);
|
||||
}
|
||||
this.recipe = RecipeCarpentry.saveRecipe(this.recipe, craftingMatrix.getStackInSlot(0), recipe.toArray());
|
||||
}
|
||||
craftingMatrix.setInventorySlotContents(1, recipe.repairMaterial);
|
||||
for (int i = 2; i < craftingMatrix.getSizeInventory(); i++) {
|
||||
craftingMatrix.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
this.recipeAnvil = recipe;
|
||||
}
|
||||
|
||||
public void saveRecipe(){
|
||||
if(width == 1){
|
||||
ItemStack output = craftingMatrix.getStackInSlot(0);
|
||||
ItemStack repairMat = craftingMatrix.getStackInSlot(1);
|
||||
if(output == null || repairMat == null){
|
||||
return;
|
||||
}
|
||||
|
||||
RecipeAnvil r = new RecipeAnvil();
|
||||
r.copy(this.recipeAnvil);
|
||||
r.name = this.recipeAnvil.name;
|
||||
r.itemToRepair = output.copy();
|
||||
r.repairMaterial = repairMat.copy();
|
||||
this.recipeAnvil = RecipeAnvil.saveRecipe(r, output, repairMat);
|
||||
return;
|
||||
} else {
|
||||
// Carpentry Recipe save (existing code)
|
||||
int nextChar = 0;
|
||||
char[] chars = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
|
||||
Map<ItemStack, Character> nameMapping = new HashMap<ItemStack, Character>();
|
||||
int firstRow = width, lastRow = 0, firstColumn = width, lastColumn = 0;
|
||||
boolean seenRow = false;
|
||||
for (int i = 0; i < width; i++) {
|
||||
boolean seenColumn = false;
|
||||
for (int j = 0; j < width; j++) {
|
||||
ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1);
|
||||
if (item == null) {
|
||||
continue;
|
||||
} else {
|
||||
if (!seenColumn && j < firstColumn) {
|
||||
firstColumn = j;
|
||||
}
|
||||
if (j > lastColumn)
|
||||
lastColumn = j;
|
||||
seenColumn = true;
|
||||
}
|
||||
Character letter = null;
|
||||
for (ItemStack mapped : nameMapping.keySet()) {
|
||||
if (NoppesUtilPlayer.compareItems(mapped, item, recipe.ignoreDamage, recipe.ignoreNBT))
|
||||
letter = nameMapping.get(mapped);
|
||||
}
|
||||
if (letter == null) {
|
||||
letter = chars[nextChar];
|
||||
nextChar++;
|
||||
nameMapping.put(item, letter);
|
||||
}
|
||||
}
|
||||
if (seenColumn) {
|
||||
if (!seenRow) {
|
||||
firstRow = i;
|
||||
lastRow = i;
|
||||
seenRow = true;
|
||||
} else {
|
||||
lastRow = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
ArrayList<Object> recipeList = new ArrayList<Object>();
|
||||
for (int i = 0; i < width; i++) {
|
||||
if (i < firstRow || i > lastRow)
|
||||
continue;
|
||||
String row = "";
|
||||
for (int j = 0; j < width; j++) {
|
||||
if (j < firstColumn || j > lastColumn)
|
||||
continue;
|
||||
ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1);
|
||||
if (item == null) {
|
||||
row += " ";
|
||||
continue;
|
||||
}
|
||||
for (ItemStack mapped : nameMapping.keySet()) {
|
||||
if (NoppesUtilPlayer.compareItems(mapped, item, false, false)) {
|
||||
row += nameMapping.get(mapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
recipeList.add(row);
|
||||
}
|
||||
if (nameMapping.isEmpty()) {
|
||||
RecipeCarpentry r = new RecipeCarpentry(this.recipe.name);
|
||||
r.copy(this.recipe);
|
||||
this.recipe = r;
|
||||
return;
|
||||
}
|
||||
for (ItemStack mapped : nameMapping.keySet()) {
|
||||
Character letter = nameMapping.get(mapped);
|
||||
recipeList.add(letter);
|
||||
recipeList.add(mapped);
|
||||
}
|
||||
this.recipe = RecipeCarpentry.saveRecipe(this.recipe, craftingMatrix.getStackInSlot(0), recipeList.toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user