2022-12-27 10:59:46 -08:00
|
|
|
package net.minecraft.inventory;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
/**+
|
|
|
|
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
|
|
|
|
*
|
|
|
|
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
|
|
|
|
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
|
|
|
|
*
|
|
|
|
* EaglercraftX 1.8 patch files are (c) 2022 LAX1DUDE. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
|
|
|
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
|
|
|
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
|
|
|
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
|
|
|
*
|
|
|
|
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
2023-01-01 10:26:38 -08:00
|
|
|
*
|
2022-12-27 10:59:46 -08:00
|
|
|
* (please read the 'LICENSE' file this repo's root directory for more info)
|
2023-01-01 10:26:38 -08:00
|
|
|
*
|
2022-12-27 10:59:46 -08:00
|
|
|
*/
|
|
|
|
public class ContainerWorkbench extends Container {
|
2023-01-01 10:26:38 -08:00
|
|
|
/**
|
|
|
|
* +
|
|
|
|
* The crafting matrix inventory (3x3).
|
|
|
|
*/
|
|
|
|
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
|
|
|
|
public IInventory craftResult = new InventoryCraftResult();
|
|
|
|
private final World worldObj;
|
|
|
|
private final BlockPos pos;
|
|
|
|
|
|
|
|
public ContainerWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos posIn) {
|
|
|
|
this.worldObj = worldIn;
|
|
|
|
this.pos = posIn;
|
|
|
|
this.addSlotToContainer(
|
|
|
|
new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
for (int j = 0; j < 3; ++j) {
|
|
|
|
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
|
2022-12-27 10:59:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int k = 0; k < 3; ++k) {
|
|
|
|
for (int i1 = 0; i1 < 9; ++i1) {
|
|
|
|
this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int l = 0; l < 9; ++l) {
|
|
|
|
this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onCraftMatrixChanged(this.craftMatrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**+
|
|
|
|
* Callback for when the crafting matrix is changed.
|
|
|
|
*/
|
|
|
|
public void onCraftMatrixChanged(IInventory var1) {
|
|
|
|
this.craftResult.setInventorySlotContents(0,
|
|
|
|
CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer) {
|
2023-01-01 10:26:38 -08:00
|
|
|
return this.worldObj.getBlockState(this.pos).getBlock() == Blocks.crafting_table && entityplayer.getDistanceSq((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D,
|
|
|
|
(double) this.pos.getZ() + 0.5D) <= 64.0D;
|
2022-12-27 10:59:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**+
|
|
|
|
* Take a stack from the specified inventory slot.
|
|
|
|
*/
|
|
|
|
public ItemStack transferStackInSlot(EntityPlayer entityplayer, int i) {
|
2023-01-01 10:26:38 -08:00
|
|
|
ItemStack itemstack = null;
|
|
|
|
Slot slot = this.inventorySlots.get(i);
|
2022-12-27 10:59:46 -08:00
|
|
|
if (slot != null && slot.getHasStack()) {
|
|
|
|
ItemStack itemstack1 = slot.getStack();
|
|
|
|
itemstack = itemstack1.copy();
|
|
|
|
if (i == 0) {
|
|
|
|
if (!this.mergeItemStack(itemstack1, 10, 46, true)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot.onSlotChange(itemstack1, itemstack);
|
|
|
|
} else if (i >= 10 && i < 37) {
|
|
|
|
if (!this.mergeItemStack(itemstack1, 37, 46, false)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else if (i >= 37 && i < 46) {
|
|
|
|
if (!this.mergeItemStack(itemstack1, 10, 37, false)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else if (!this.mergeItemStack(itemstack1, 10, 46, false)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack1.stackSize == 0) {
|
2023-01-01 10:26:38 -08:00
|
|
|
slot.putStack(null);
|
2022-12-27 10:59:46 -08:00
|
|
|
} else {
|
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack1.stackSize == itemstack.stackSize) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot.onPickupFromSlot(entityplayer, itemstack1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**+
|
|
|
|
* Called to determine if the current slot is valid for the
|
|
|
|
* stack merging (double-click) code. The stack passed in is
|
|
|
|
* null for the initial slot that was double-clicked.
|
|
|
|
*/
|
|
|
|
public boolean canMergeSlot(ItemStack itemstack, Slot slot) {
|
|
|
|
return slot.inventory != this.craftResult && super.canMergeSlot(itemstack, slot);
|
|
|
|
}
|
|
|
|
}
|