mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 09:37:29 +00:00
Fix recipe pre-event pickup checks
This commit is contained in:
1 parent
5fdb507784
commit
c2b92a836d
2 files changed
+94
-17
No files matched your search
@@ -217,6 +217,10 @@ public class ContainerAnvilRepair extends Container {
|
||||
ItemStack stack = slot.getStack();
|
||||
copy = stack.copy();
|
||||
if (index == 0) { // output slot
|
||||
SlotAnvilOutput resultSlot = (SlotAnvilOutput) slot;
|
||||
if (!resultSlot.preEvent(player)) {
|
||||
return null;
|
||||
}
|
||||
if (player.experienceTotal < this.repairCost) {
|
||||
return null;
|
||||
}
|
||||
@@ -259,12 +263,35 @@ public class ContainerAnvilRepair extends Container {
|
||||
// subtracts one from the damaged item stack.
|
||||
public class SlotAnvilOutput extends Slot {
|
||||
private final ContainerAnvilRepair container;
|
||||
private boolean preChecked = false;
|
||||
private boolean canPickup = true;
|
||||
|
||||
public SlotAnvilOutput(ContainerAnvilRepair container, IInventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public boolean preEvent(EntityPlayer player) {
|
||||
preChecked = true;
|
||||
if (!container.worldObj.isRemote) {
|
||||
RecipeAnvil recipe = container.currentRecipe;
|
||||
if (recipe != null) {
|
||||
ItemStack[] items = new ItemStack[]{
|
||||
container.anvilMatrix.getStackInRowAndColumn(0, 0),
|
||||
container.anvilMatrix.getStackInRowAndColumn(1, 0)
|
||||
};
|
||||
canPickup = !EventHooks.onRecipeScriptPre(player, recipe.getScriptHandler(), recipe, items);
|
||||
if (!canPickup) {
|
||||
container.updateRepairResult();
|
||||
preChecked = false; // reset for next attempt
|
||||
}
|
||||
} else {
|
||||
canPickup = true;
|
||||
}
|
||||
}
|
||||
return canPickup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return false;
|
||||
@@ -272,20 +299,27 @@ public class ContainerAnvilRepair extends Container {
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
return player.experienceTotal >= container.repairCost;
|
||||
if (!preChecked) {
|
||||
preEvent(player);
|
||||
}
|
||||
return canPickup && player.experienceTotal >= container.repairCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack stack) {
|
||||
if (!preChecked) {
|
||||
if (!preEvent(player))
|
||||
return;
|
||||
}
|
||||
if (!canPickup) {
|
||||
return;
|
||||
}
|
||||
RecipeAnvil recipe = container.currentRecipe;
|
||||
ItemStack[] items = new ItemStack[]{
|
||||
container.anvilMatrix.getStackInRowAndColumn(0, 0),
|
||||
container.anvilMatrix.getStackInRowAndColumn(1, 0)
|
||||
};
|
||||
if (recipe != null) {
|
||||
if (EventHooks.onRecipeScriptPre(player, recipe.getScriptHandler(), recipe, items)) {
|
||||
return;
|
||||
}
|
||||
if (!container.worldObj.isRemote && recipe != null) {
|
||||
container.updateRepairResult();
|
||||
stack = EventHooks.onRecipeScriptPost(player, recipe.getScriptHandler(), recipe, items, stack);
|
||||
}
|
||||
@@ -319,6 +353,8 @@ public class ContainerAnvilRepair extends Container {
|
||||
}
|
||||
container.repairCost = 0;
|
||||
container.updateRepairResult();
|
||||
preChecked = false;
|
||||
canPickup = true;
|
||||
super.onPickupFromSlot(player, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,10 @@ public class ContainerCarpentryBench extends Container {
|
||||
var2 = var4.copy();
|
||||
|
||||
if (par1 == 0) {
|
||||
SlotCarpentryResult resultSlot = (SlotCarpentryResult) var3;
|
||||
if (!resultSlot.preEvent(par1EntityPlayer)) {
|
||||
return null;
|
||||
}
|
||||
if (!this.mergeItemStack(var4, 17, 53, true)) {
|
||||
return null;
|
||||
}
|
||||
@@ -143,8 +147,8 @@ public class ContainerCarpentryBench extends Container {
|
||||
}
|
||||
|
||||
// Update client-side inventory
|
||||
if (!this.worldObj.isRemote && player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).sendContainerToPlayer(this);
|
||||
if (!this.worldObj.isRemote && par1EntityPlayer instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) par1EntityPlayer).sendContainerToPlayer(this);
|
||||
}
|
||||
|
||||
return var2;
|
||||
@@ -159,6 +163,8 @@ public class ContainerCarpentryBench extends Container {
|
||||
private class SlotCarpentryResult extends SlotCrafting {
|
||||
private final ContainerCarpentryBench container;
|
||||
private final InventoryCrafting matrix;
|
||||
private boolean preChecked = false;
|
||||
private boolean canPickup = true;
|
||||
|
||||
public SlotCarpentryResult(ContainerCarpentryBench container, EntityPlayer player, InventoryCrafting matrix, IInventory result, int index, int x, int y) {
|
||||
super(player, matrix, result, index, x, y);
|
||||
@@ -166,20 +172,55 @@ public class ContainerCarpentryBench extends Container {
|
||||
this.matrix = matrix;
|
||||
}
|
||||
|
||||
public boolean preEvent(EntityPlayer player) {
|
||||
preChecked = true;
|
||||
if (!container.worldObj.isRemote) {
|
||||
RecipeCarpentry recipe = container.currentRecipe;
|
||||
if (recipe != null) {
|
||||
ItemStack[] items = new ItemStack[matrix.getSizeInventory()];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = matrix.getStackInSlot(i);
|
||||
}
|
||||
canPickup = !EventHooks.onRecipeScriptPre(player, recipe.getScriptHandler(), recipe, items);
|
||||
if (!canPickup) {
|
||||
container.onCraftMatrixChanged(matrix);
|
||||
preChecked = false; // reset for next attempt
|
||||
}
|
||||
} else {
|
||||
canPickup = true;
|
||||
}
|
||||
}
|
||||
return canPickup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
if (!preChecked) {
|
||||
preEvent(player);
|
||||
}
|
||||
return canPickup && super.canTakeStack(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack stack) {
|
||||
RecipeCarpentry recipe = container.currentRecipe;
|
||||
ItemStack[] items = new ItemStack[matrix.getSizeInventory()];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = matrix.getStackInSlot(i);
|
||||
}
|
||||
if (recipe != null) {
|
||||
if (EventHooks.onRecipeScriptPre(player, recipe.getScriptHandler(), recipe, items)) {
|
||||
container.onCraftMatrixChanged(matrix);
|
||||
if (!preChecked) {
|
||||
if (!preEvent(player))
|
||||
return;
|
||||
}
|
||||
stack = EventHooks.onRecipeScriptPost(player, recipe.getScriptHandler(), recipe, items, stack);
|
||||
}
|
||||
if (!canPickup)
|
||||
return;
|
||||
if (!container.worldObj.isRemote) {
|
||||
RecipeCarpentry recipe = container.currentRecipe;
|
||||
if (recipe != null) {
|
||||
ItemStack[] items = new ItemStack[matrix.getSizeInventory()];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = matrix.getStackInSlot(i);
|
||||
}
|
||||
stack = EventHooks.onRecipeScriptPost(player, recipe.getScriptHandler(), recipe, items, stack);
|
||||
}
|
||||
}
|
||||
preChecked = false;
|
||||
canPickup = true;
|
||||
super.onPickupFromSlot(player, stack);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user