Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kyros.testMod.container;
- import kyros.testMod.testMod;
- import kyros.testMod.crafting.WorlSurfaceCraftingManager;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.InventoryCraftResult;
- import net.minecraft.inventory.InventoryCrafting;
- import net.minecraft.inventory.Slot;
- import net.minecraft.inventory.SlotCrafting;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- public class ContainerCCrafter extends Container {
- public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
- public IInventory craftResult = new InventoryCraftResult();
- private World worldObj;
- private int posX;
- private int posY;
- private int posZ;
- public ContainerCCrafter(InventoryPlayer invPlayer, World world, int x, int y, int z) {
- worldObj = world;
- posX = x;
- posY = y;
- posZ = z;
- this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 124, 35));
- this.addSlotToContainer(new Slot(craftMatrix, 0, 48, 17));
- this.addSlotToContainer(new Slot(craftMatrix, 0, 30, 35));
- this.addSlotToContainer(new Slot(craftMatrix, 0, 66, 35));
- this.addSlotToContainer(new Slot(craftMatrix, 0, 48, 53));
- for (int i = 0; i < 3; ++i) {
- for (int k = 0; k < 9; ++k) {
- this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));
- }
- }
- for (int i = 0; i < 9; ++i) {
- this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
- }
- onCraftMatrixChanged(craftMatrix);
- }
- public void onCraftingMatrixChanged(IInventory iinv) {
- craftResult.setInventorySlotContents(0,
- WorlSurfaceCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
- }
- public boolean canInteractWith(EntityPlayer player) {
- return this.worldObj.getBlock(this.posX, this.posY, this.posZ) != Blocks.crafting_table ? false
- : player.getDistanceSq((double) this.posX + 0.5D, (double) this.posY + 0.5D,
- (double) this.posZ + 0.5D) <= 64.0D;
- }
- public void onContainerClosed(EntityPlayer player) {
- super.onContainerClosed(player);
- if (!this.worldObj.isRemote) {
- for (int i = 0; i < 9; ++i) {
- ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
- if (itemstack != null) {
- player.dropPlayerItemWithRandomChoice(itemstack, false);
- }
- }
- }
- }
- public ItemStack transferStackInSlot(EntityPlayer player, int INT1) {
- ItemStack itemstack = null;
- Slot slot = (Slot) this.inventorySlots.get(INT1);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- if (INT1 == 0) {
- if (!this.mergeItemStack(itemstack1, 10, 46, true)) {
- return null;
- }
- slot.onSlotChange(itemstack1, itemstack);
- } else if (INT1 >= 10 && INT1 < 37) {
- if (!this.mergeItemStack(itemstack1, 37, 46, false)) {
- return null;
- }
- } else if (INT1 >= 37 && INT1 < 46) {
- if (!this.mergeItemStack(itemstack1, 10, 37, false)) {
- return null;
- }
- } else if (!this.mergeItemStack(itemstack1, 10, 46, false)) {
- return null;
- }
- if (itemstack1.stackSize == 0) {
- slot.putStack((ItemStack) null);
- } else {
- slot.onSlotChanged();
- }
- if (itemstack1.stackSize == itemstack.stackSize) {
- return null;
- }
- slot.onPickupFromSlot(player, itemstack1);
- }
- return itemstack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment