mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 12:42:19 +00:00
Availability Options for Recipe & Anvil Recipes
This commit is contained in:
1 parent
48dd7bedea
commit
d45e550321
6 files changed
+339
-133
No files matched your search
@@ -12,6 +12,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.SubGuiNpcAvailability;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
|
||||
@@ -43,7 +44,14 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
|
||||
setBackground("inventorymenu.png");
|
||||
slot = getResource("slot.png");
|
||||
ySize = 200;
|
||||
tab = 1;
|
||||
|
||||
if(container.width == 1){
|
||||
tab = 2;
|
||||
} else if (container.width == 3){
|
||||
tab = 0;
|
||||
} else {
|
||||
tab = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,8 +81,13 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
|
||||
this.addButton(new GuiNpcButtonYesNo(5, guiLeft + 235, buttonPos - 5, 40, 20, container.recipe.ignoreDamage));
|
||||
this.addLabel(new GuiNpcLabel(1, "gui.ignoreNBT", guiLeft + 131, buttonPos += 22));
|
||||
this.addButton(new GuiNpcButtonYesNo(6, guiLeft + 235, buttonPos - 5, 40, 20, container.recipe.ignoreNBT));
|
||||
|
||||
buttonPos += 22;
|
||||
this.addButton(new GuiNpcButton(15, guiLeft + 172, buttonPos - 5, 103, 20, "availability.options"));
|
||||
|
||||
this.getButton(5).setEnabled(false);
|
||||
this.getButton(6).setEnabled(false);
|
||||
this.getButton(15).setEnabled(false);
|
||||
|
||||
this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name));
|
||||
this.getTextField(0).enabled = false;
|
||||
@@ -102,9 +115,13 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
|
||||
this.getTextField(2).setMinMaxDefault(0, Integer.MAX_VALUE, container.recipeAnvil.getXpCost());
|
||||
this.getTextField(2).enabled = false;
|
||||
|
||||
buttonPos += 22;
|
||||
this.addButton(new GuiNpcButton(15, guiLeft + 172, buttonPos - 5, 103, 20, "availability.options"));
|
||||
|
||||
this.getButton(7).setEnabled(false);
|
||||
this.getButton(8).setEnabled(false);
|
||||
this.getButton(9).setEnabled(false);
|
||||
this.getButton(15).setEnabled(false);
|
||||
|
||||
this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipeAnvil.name));
|
||||
this.getTextField(0).enabled = false;
|
||||
@@ -177,6 +194,14 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
|
||||
if (button.id == 9) {
|
||||
container.recipeAnvil.ignoreRepairItemNBT = button.getValue() == 1;
|
||||
}
|
||||
if(button.id == 15){
|
||||
save();
|
||||
if(container.width == 1){
|
||||
setSubGui(new SubGuiNpcAvailability(container.recipeAnvil.availability));
|
||||
} else {
|
||||
setSubGui(new SubGuiNpcAvailability(container.recipe.availability));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,43 +235,62 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (compound.hasKey("IsAnvil")) {
|
||||
RecipeAnvil recipe = RecipeAnvil.read(compound);
|
||||
getTextField(0).setText(recipe.name);
|
||||
getTextField(1).setText(recipe.getRepairPercentage() + "");
|
||||
getTextField(2).setText(recipe.getXpCost() + "");
|
||||
container.setRecipe(recipe);
|
||||
container.width = 1;
|
||||
tab = 2;
|
||||
fixButtons();
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
container.setRecipe(recipe);
|
||||
fixButtons();
|
||||
}
|
||||
}
|
||||
|
||||
setSelected(recipe.name);
|
||||
private void fixButtons(){
|
||||
if(tab == 2){
|
||||
getTextField(0).setText(container.recipeAnvil.name);
|
||||
getTextField(1).setText(container.recipeAnvil.getRepairPercentage() + "");
|
||||
getTextField(2).setText(container.recipeAnvil.getXpCost() + "");
|
||||
|
||||
setSelected(container.recipeAnvil.name);
|
||||
getTextField(0).enabled = true;
|
||||
getTextField(1).enabled = true;
|
||||
getTextField(2).enabled = true;
|
||||
|
||||
container.width = 1;
|
||||
|
||||
GuiNpcButtonYesNo btnMatDamage = (GuiNpcButtonYesNo)this.getButton(7);
|
||||
GuiNpcButtonYesNo btnMatNBT = (GuiNpcButtonYesNo)this.getButton(8);
|
||||
GuiNpcButtonYesNo btnItemNBT = (GuiNpcButtonYesNo)this.getButton(9);
|
||||
if (btnMatDamage != null) {
|
||||
btnMatDamage.setDisplay(recipe.ignoreRepairMaterialDamage ? 1 : 0);
|
||||
btnMatDamage.setDisplay(container.recipeAnvil.ignoreRepairMaterialDamage ? 1 : 0);
|
||||
btnMatDamage.setEnabled(true);
|
||||
}
|
||||
if (btnMatNBT != null) {
|
||||
btnMatNBT.setDisplay(recipe.ignoreRepairMaterialNBT ? 1 : 0);
|
||||
btnMatNBT.setDisplay(container.recipeAnvil.ignoreRepairMaterialNBT ? 1 : 0);
|
||||
btnMatNBT.setEnabled(true);
|
||||
}
|
||||
if (btnItemNBT != null) {
|
||||
btnItemNBT.setDisplay(recipe.ignoreRepairItemNBT ? 1 : 0);
|
||||
btnItemNBT.setDisplay(container.recipeAnvil.ignoreRepairItemNBT ? 1 : 0);
|
||||
btnItemNBT.setEnabled(true);
|
||||
}
|
||||
|
||||
GuiNpcButton avail = this.getButton(15);
|
||||
if(avail != null)
|
||||
avail.setEnabled(true);
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
getTextField(0).setText(recipe.name);
|
||||
container.setRecipe(recipe);
|
||||
getTextField(0).setText(container.recipe.name);
|
||||
|
||||
this.getTextField(0).enabled = true;
|
||||
this.getButton(5).setEnabled(true);
|
||||
this.getButton(5).setDisplay(recipe.ignoreDamage ? 1 : 0);
|
||||
this.getButton(5).setDisplay(container.recipe.ignoreDamage ? 1 : 0);
|
||||
this.getButton(6).setEnabled(true);
|
||||
this.getButton(6).setDisplay(recipe.ignoreNBT ? 1 : 0);
|
||||
setSelected(recipe.name);
|
||||
this.getButton(6).setDisplay(container.recipe.ignoreNBT ? 1 : 0);
|
||||
setSelected(container.recipe.name);
|
||||
|
||||
if(!container.recipe.isGlobal){
|
||||
GuiNpcButton avail = this.getButton(15);
|
||||
if(avail != null)
|
||||
avail.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,6 +401,7 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui){
|
||||
|
||||
if(subgui instanceof SubGuiNpcAvailability)
|
||||
fixButtons();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
@@ -122,13 +123,18 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
|
||||
private static class TextOverlayData {
|
||||
public final int x, y, width, height;
|
||||
public final String text;
|
||||
public final List<String> textLines;
|
||||
|
||||
public TextOverlayData(int x, int y, int width, int height, String text) {
|
||||
this(x, y, width, height, Arrays.asList(text));
|
||||
}
|
||||
|
||||
public TextOverlayData(int x, int y, int width, int height, List<String> textLines) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.text = text;
|
||||
this.textLines = textLines;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +162,9 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
RecipeAnvil recipe = recipes.get(i);
|
||||
if(!recipe.isValid())
|
||||
continue;
|
||||
|
||||
int localIndex = i - startIndex; // 0 to 7
|
||||
int col = localIndex / 4; // 0 for left column, 1 for right column
|
||||
int row = localIndex % 4; // rows 0..3
|
||||
@@ -222,6 +231,51 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
textOverlays.add(new TextOverlayData(percentTextX, percentTextY, percentWidth, fontRendererObj.FONT_HEIGHT, String.valueOf(recipe.getRepairPercentage())));
|
||||
}
|
||||
|
||||
if(!recipe.availability.isDefault()){
|
||||
if(!recipe.availability.isAvailable(this.player)){
|
||||
String helpChar = "?";
|
||||
float scale = 1F; // Adjust for a very small size
|
||||
int questionWidth = (int)(fontRendererObj.getStringWidth(helpChar) * scale);
|
||||
int questionHeight = (int)(fontRendererObj.FONT_HEIGHT * scale);
|
||||
// Center the "?" under the percentage text.
|
||||
int questionX = percentCenterX - (questionWidth / 2) - 1 - row;
|
||||
int questionY = percentTextY + fontRendererObj.FONT_HEIGHT; // You can tweak the vertical offset if needed
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(questionX, questionY, 0);
|
||||
GL11.glScalef(scale, scale, 1.0F);
|
||||
|
||||
fontRendererObj.drawString(helpChar, 0, 0, 0xbd3e35);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
if (func_146978_c(questionX - guiLeft, questionY - guiTop, questionWidth, questionHeight, mouseX, mouseY)) {
|
||||
List<String> availableText = recipe.availability.isAvailableText(this.player);
|
||||
textOverlays.add(new TextOverlayData(questionX, questionY, questionWidth, questionHeight, availableText));
|
||||
}
|
||||
} else {
|
||||
// Draw a very small "?" under the percentage text.
|
||||
String helpChar = "!";
|
||||
float scale = 1F; // Adjust for a very small size
|
||||
int questionWidth = (int)(fontRendererObj.getStringWidth(helpChar) * scale);
|
||||
int questionHeight = (int)(fontRendererObj.FONT_HEIGHT * scale);
|
||||
// Center the "?" under the percentage text.
|
||||
int questionX = percentCenterX - (questionWidth / 2) - 1 - row;
|
||||
int questionY = percentTextY + fontRendererObj.FONT_HEIGHT; // You can tweak the vertical offset if needed
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(questionX, questionY, 0);
|
||||
GL11.glScalef(scale, scale, 1.0F);
|
||||
|
||||
fontRendererObj.drawString(helpChar, 0, 0, CustomNpcResourceListener.DefaultTextColor);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
// When the "!" is hovered, add its tooltip overlay.
|
||||
if (func_146978_c(questionX - guiLeft, questionY - guiTop, questionWidth, questionHeight, mouseX, mouseY)) {
|
||||
textOverlays.add(new TextOverlayData(questionX, questionY, questionWidth, questionHeight, StatCollector.translateToLocal("gui.available")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw XP cost with scaling.
|
||||
String xpCostStr = formatXpCost(recipe.getXpCost());
|
||||
int digitCount = xpCostStr.length();
|
||||
@@ -249,7 +303,7 @@ public class GuiAnvilRecipes extends GuiNPCInterface {
|
||||
}
|
||||
|
||||
for (TextOverlayData tod : textOverlays) {
|
||||
this.drawHoveringText(java.util.Arrays.asList(tod.text), mouseX, mouseY, this.fontRendererObj);
|
||||
this.drawHoveringText(tod.textLines, mouseX, mouseY, this.fontRendererObj);
|
||||
}
|
||||
}
|
||||
protected boolean func_146978_c(int p_146978_1_, int p_146978_2_, int p_146978_3_, int p_146978_4_, int p_146978_5_, int p_146978_6_) {
|
||||
|
||||
@@ -9,6 +9,8 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
@@ -16,6 +18,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -97,6 +100,33 @@ public class GuiRecipes extends GuiNPCInterface
|
||||
updateButton();
|
||||
}
|
||||
|
||||
private static class ItemOverlayData {
|
||||
public final int x, y;
|
||||
public final ItemStack item;
|
||||
public ItemOverlayData(int x, int y, ItemStack item) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TextOverlayData {
|
||||
public final int x, y, width, height;
|
||||
public final List<String> textLines;
|
||||
|
||||
public TextOverlayData(int x, int y, int width, int height, String text) {
|
||||
this(x, y, width, height, Arrays.asList(text));
|
||||
}
|
||||
|
||||
public TextOverlayData(int x, int y, int width, int height, List<String> textLines) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.textLines = textLines;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int xMouse, int yMouse, float f){
|
||||
super.drawScreen(xMouse, yMouse, f);
|
||||
@@ -104,57 +134,95 @@ public class GuiRecipes extends GuiNPCInterface
|
||||
|
||||
label.label = page + 1 + "/" + MathHelper.ceiling_float_int(recipes.size() / 4f);
|
||||
label.x = guiLeft + (256 - Minecraft.getMinecraft().fontRenderer.getStringWidth(label.label)) / 2;
|
||||
for(int i = 0; i < 4; i++){
|
||||
int index = i + page * 4;
|
||||
if(index >= recipes.size())
|
||||
break;
|
||||
IRecipe irecipe = recipes.get(index);
|
||||
if(irecipe.getRecipeOutput() == null)
|
||||
continue;
|
||||
int x = guiLeft + 5 + i / 2 * 126;
|
||||
int y = guiTop + 15 + i % 2 * 76;
|
||||
drawItem(irecipe.getRecipeOutput(), x + 98, y + 28, xMouse, yMouse);
|
||||
if(irecipe instanceof RecipeCarpentry){
|
||||
RecipeCarpentry recipe = (RecipeCarpentry) irecipe;
|
||||
x += (72 - recipe.recipeWidth * 18) / 2;
|
||||
y += (72 - recipe.recipeHeight * 18) / 2;
|
||||
for(int j = 0; j < recipe.recipeWidth; j++){
|
||||
for(int k = 0; k < recipe.recipeHeight; k++){
|
||||
mc.renderEngine.bindTexture(resource);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(x + j * 18, y + k * 18, 0, 0, 18, 18);
|
||||
ItemStack item = recipe.getCraftingItem(j + k * recipe.recipeWidth);
|
||||
if(item == null)
|
||||
continue;
|
||||
drawItem(item, x + j * 18 + 1, y + k * 18 + 1, xMouse, yMouse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 4; i++){
|
||||
int index = i + page * 4;
|
||||
if(index >= recipes.size())
|
||||
break;
|
||||
IRecipe irecipe = recipes.get(index);
|
||||
if(irecipe instanceof RecipeCarpentry){
|
||||
RecipeCarpentry recipe = (RecipeCarpentry) irecipe;
|
||||
if(recipe.getRecipeOutput() == null)
|
||||
continue;
|
||||
int x = guiLeft + 5 + i / 2 * 126;
|
||||
int y = guiTop + 15 + i % 2 * 76;
|
||||
drawOverlay(recipe.getRecipeOutput(), x + 98, y + 22, xMouse, yMouse);
|
||||
x += (72 - recipe.recipeWidth * 18) / 2;
|
||||
y += (72 - recipe.recipeHeight * 18) / 2;
|
||||
for(int j = 0; j < recipe.recipeWidth; j++){
|
||||
for(int k = 0; k < recipe.recipeHeight; k++){
|
||||
ItemStack item = recipe.getCraftingItem(j + k * recipe.recipeWidth);
|
||||
if(item == null)
|
||||
continue;
|
||||
drawOverlay(item, x + j * 18 + 1, y + k * 18 + 1, xMouse, yMouse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemOverlayData> itemOverlays = new ArrayList<ItemOverlayData>();
|
||||
List<TextOverlayData> textOverlays = new ArrayList<TextOverlayData>();
|
||||
|
||||
// Loop through recipes.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int index = i + page * 4;
|
||||
if (index >= recipes.size())
|
||||
break;
|
||||
IRecipe irecipe = recipes.get(index);
|
||||
if (irecipe.getRecipeOutput() == null)
|
||||
continue;
|
||||
int x = guiLeft + 5 + (i / 2) * 126;
|
||||
int y = guiTop + 15 + (i % 2) * 76;
|
||||
|
||||
drawItem(irecipe.getRecipeOutput(), x + 98, y + 28, xMouse, yMouse);
|
||||
if (func_146978_c((x+98) - guiLeft, (y+28) - guiTop, 16, 16, xMouse, yMouse)) {
|
||||
itemOverlays.add(new ItemOverlayData(x+98, y+28, irecipe.getRecipeOutput()));
|
||||
}
|
||||
|
||||
if (irecipe instanceof RecipeCarpentry) {
|
||||
RecipeCarpentry recipe = (RecipeCarpentry) irecipe;
|
||||
if (!recipe.isGlobal && recipe.availability != null && !recipe.availability.isDefault()) {
|
||||
int outputX = x + 98;
|
||||
int outputY = y + 38;
|
||||
float scale = 1.0F;
|
||||
String iconStr;
|
||||
int iconColor;
|
||||
if (!recipe.availability.isAvailable(mc.thePlayer)) {
|
||||
iconStr = "?";
|
||||
iconColor = 0xbd3e35;
|
||||
} else {
|
||||
iconStr = "!";
|
||||
iconColor = CustomNpcResourceListener.DefaultTextColor;
|
||||
}
|
||||
int iconWidth = (int)(fontRendererObj.getStringWidth(iconStr) * scale);
|
||||
int iconHeight = (int)(fontRendererObj.FONT_HEIGHT * scale);
|
||||
// Center the icon below the output slot (16x16 slot).
|
||||
int iconX = outputX + (16 - iconWidth) / 2;
|
||||
int iconY = outputY + 16;
|
||||
|
||||
// Render the icon.
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(iconX, iconY, 0);
|
||||
GL11.glScalef(scale, scale, 1.0F);
|
||||
fontRendererObj.drawString(iconStr, 0, 0, iconColor);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
// Instead of rendering the tooltip immediately, add it as a text overlay.
|
||||
if (func_146978_c(iconX - guiLeft, iconY - guiTop, iconWidth, iconHeight, xMouse, yMouse)) {
|
||||
List<String> tooltipLines = recipe.availability.isAvailableText(mc.thePlayer);
|
||||
if (tooltipLines.isEmpty()) {
|
||||
tooltipLines.add(StatCollector.translateToLocal("gui.available"));
|
||||
}
|
||||
textOverlays.add(new TextOverlayData(iconX, iconY, iconWidth, iconHeight, tooltipLines));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the recipe grid (for RecipeCarpentry recipes).
|
||||
if (irecipe instanceof RecipeCarpentry) {
|
||||
RecipeCarpentry recipe = (RecipeCarpentry) irecipe;
|
||||
int gridX = x + (72 - recipe.recipeWidth * 18) / 2;
|
||||
int gridY = y + (72 - recipe.recipeHeight * 18) / 2;
|
||||
for (int j = 0; j < recipe.recipeWidth; j++) {
|
||||
for (int k = 0; k < recipe.recipeHeight; k++) {
|
||||
mc.renderEngine.bindTexture(resource);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(gridX + j * 18, gridY + k * 18, 0, 0, 18, 18);
|
||||
ItemStack item = recipe.getCraftingItem(j + k * recipe.recipeWidth);
|
||||
if (item == null)
|
||||
continue;
|
||||
drawItem(item, gridX + j * 18 + 1, gridY + k * 18 + 1, xMouse, yMouse);
|
||||
if (func_146978_c((gridX+j*18+1)-guiLeft, (gridY+k*18+1)-guiTop, 16, 16, xMouse, yMouse)) {
|
||||
itemOverlays.add(new ItemOverlayData(gridX+j*18+1, gridY+k*18+1, item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Render any item tooltips.
|
||||
for (ItemOverlayData iod : itemOverlays) {
|
||||
this.renderToolTip(iod.item, xMouse, yMouse);
|
||||
}
|
||||
// Render all text overlays (each line from the availability tooltip will be on its own line).
|
||||
for (TextOverlayData tod : textOverlays) {
|
||||
this.drawHoveringText(tod.textLines, xMouse, yMouse, this.fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawItem(ItemStack item, int x, int y, int xMouse, int yMouse){
|
||||
|
||||
@@ -3,7 +3,6 @@ package noppes.npcs.containers;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -11,7 +10,6 @@ import net.minecraft.inventory.InventoryCraftResult;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.server.S2FPacketSetSlot;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.api.handler.data.IAnvilRecipe;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
@@ -27,10 +25,7 @@ public class ContainerAnvilRepair extends Container {
|
||||
private World worldObj;
|
||||
private int posX, posY, posZ;
|
||||
|
||||
// These fields are used for syncing the repair cost message.
|
||||
public String repairStatus = "";
|
||||
public int repairCost = 0;
|
||||
// How many repair material items are used during the repair calculation.
|
||||
public int repairMaterialConsumed = 0;
|
||||
|
||||
public ContainerAnvilRepair(InventoryPlayer playerInv, World world, int x, int y, int z) {
|
||||
@@ -70,63 +65,6 @@ public class ContainerAnvilRepair extends Container {
|
||||
}
|
||||
|
||||
updateRepairResult();
|
||||
|
||||
// For testing: clear recipes and add a test recipe.
|
||||
RecipeController.Instance.anvilRecipes.clear();
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"Test",
|
||||
new ItemStack(Items.iron_pickaxe),
|
||||
new ItemStack(Items.paper),
|
||||
50,
|
||||
23));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"Okay",
|
||||
new ItemStack(Items.diamond_pickaxe),
|
||||
new ItemStack(Items.paper),
|
||||
21,
|
||||
10));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"Bob",
|
||||
new ItemStack(Items.golden_pickaxe),
|
||||
new ItemStack(Items.paper),
|
||||
1200,
|
||||
40));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"Dude",
|
||||
new ItemStack(Items.iron_chestplate),
|
||||
new ItemStack(Items.paper),
|
||||
40000,
|
||||
23));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"Oas",
|
||||
new ItemStack(Items.golden_pickaxe),
|
||||
new ItemStack(Items.diamond),
|
||||
12,
|
||||
1));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"awd",
|
||||
new ItemStack(Items.golden_sword),
|
||||
new ItemStack(Items.gold_ingot),
|
||||
80,
|
||||
14));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"fawd",
|
||||
new ItemStack(Items.bow),
|
||||
new ItemStack(Items.string),
|
||||
4,
|
||||
3));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"cxzs",
|
||||
new ItemStack(Items.bow),
|
||||
new ItemStack(Items.diamond),
|
||||
4,
|
||||
3));
|
||||
RecipeController.Instance.addAnvilRecipe(new RecipeAnvil(
|
||||
"awdawdwa",
|
||||
new ItemStack(Items.iron_sword),
|
||||
new ItemStack(Items.blaze_rod),
|
||||
4,
|
||||
3));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,6 +114,10 @@ public class ContainerAnvilRepair extends Container {
|
||||
|
||||
ItemStack output = null;
|
||||
if (matchingRecipe != null) {
|
||||
if(!matchingRecipe.availability.isAvailable(player)){
|
||||
return;
|
||||
}
|
||||
|
||||
int baseXpCost = matchingRecipe.getXpCost();
|
||||
// Assume repairPercentage is given as a percent (e.g. 20 for 20% per material)
|
||||
float repairPercentage = matchingRecipe.getRepairPercentage() / 100.0f;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.ICompatibilty;
|
||||
import noppes.npcs.VersionCompatibility;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
@@ -13,6 +16,9 @@ import noppes.npcs.controllers.PlayerQuestController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Availability implements ICompatibilty, IAvailability {
|
||||
public int version = VersionCompatibility.ModRev;
|
||||
|
||||
@@ -124,6 +130,31 @@ public class Availability implements ICompatibilty, IAvailability {
|
||||
compound.setInteger("AvailabilityMinPlayerLevel", minPlayerLevel);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return dialogAvailable == EnumAvailabilityDialog.Always &&
|
||||
dialog2Available == EnumAvailabilityDialog.Always &&
|
||||
dialog3Available == EnumAvailabilityDialog.Always &&
|
||||
dialog4Available == EnumAvailabilityDialog.Always &&
|
||||
dialogId == -1 &&
|
||||
|
||||
questAvailable == EnumAvailabilityQuest.Always &&
|
||||
quest2Available == EnumAvailabilityQuest.Always &&
|
||||
quest3Available == EnumAvailabilityQuest.Always &&
|
||||
quest4Available == EnumAvailabilityQuest.Always &&
|
||||
questId == -1 &&
|
||||
|
||||
factionAvailable == EnumAvailabilityFactionType.Always &&
|
||||
faction2Available == EnumAvailabilityFactionType.Always &&
|
||||
factionId == -1 &&
|
||||
faction2Id == -1 &&
|
||||
factionStance == EnumAvailabilityFaction.Friendly &&
|
||||
faction2Stance == EnumAvailabilityFaction.Friendly &&
|
||||
|
||||
daytime == EnumDayTime.Always &&
|
||||
minPlayerLevel == 0;
|
||||
}
|
||||
|
||||
public void setFactionAvailability(int value) {
|
||||
factionAvailable = EnumAvailabilityFactionType.values()[value];
|
||||
}
|
||||
@@ -177,6 +208,64 @@ public class Availability implements ICompatibilty, IAvailability {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<String> isAvailableText(EntityPlayer player) {
|
||||
List<String> errors = new ArrayList<String>();
|
||||
|
||||
// Check daytime conditions.
|
||||
if (daytime == EnumDayTime.Day) {
|
||||
long time = player.worldObj.getWorldTime() % 24000;
|
||||
if (time > 12000) {
|
||||
errors.add(StatCollector.translateToLocal("availability.error.day"));
|
||||
}
|
||||
} else if (daytime == EnumDayTime.Night) {
|
||||
long time = player.worldObj.getWorldTime() % 24000;
|
||||
if (time < 12000) {
|
||||
errors.add(StatCollector.translateToLocal("availability.error.night"));
|
||||
}
|
||||
}
|
||||
|
||||
// Check dialog conditions.
|
||||
if (!dialogAvailable(dialogId, dialogAvailable, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialogAvailable.toString(), dialogId));
|
||||
}
|
||||
if (!dialogAvailable(dialog2Id, dialog2Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog2Available.toString(), dialog2Id));
|
||||
}
|
||||
if (!dialogAvailable(dialog3Id, dialog3Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog3Available.toString(), dialog3Id));
|
||||
}
|
||||
if (!dialogAvailable(dialog4Id, dialog4Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog4Available.toString(), dialog4Id));
|
||||
}
|
||||
|
||||
// Check quest conditions.
|
||||
if (!questAvailable(questId, questAvailable, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", questAvailable.toString(), questId));
|
||||
}
|
||||
if (!questAvailable(quest2Id, quest2Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest2Available.toString(), quest2Id));
|
||||
}
|
||||
if (!questAvailable(quest3Id, quest3Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest3Available.toString(), quest3Id));
|
||||
}
|
||||
if (!questAvailable(quest4Id, quest4Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest4Available.toString(), quest4Id));
|
||||
}
|
||||
|
||||
// Check faction conditions.
|
||||
if (!factionAvailable(factionId, factionStance, factionAvailable, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.faction", factionAvailable.toString(), factionStance.toString(), factionId));
|
||||
}
|
||||
if (!factionAvailable(faction2Id, faction2Stance, faction2Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.faction", faction2Available.toString(), faction2Stance.toString(), faction2Id));
|
||||
}
|
||||
if (player.experienceLevel < minPlayerLevel) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.xp", minPlayerLevel));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
private boolean factionAvailable(int id, EnumAvailabilityFaction stance, EnumAvailabilityFactionType available, EntityPlayer player) {
|
||||
if(available == EnumAvailabilityFactionType.Always)
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user