mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 05:45:03 +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
@@ -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