Jump to content

[Solved] [1.10.2] Items in GUI not movable


abused_master

Recommended Posts

Hello Everyone,

so today I was working on a new mod of mine, creating a new GUI, I added the slots, as well as the inventory slots, registered my GUI on the server and client, but for some reason whenever I have an item in my inventory and I open the GUI, i'm not able to move it around, as soon as I click it, it hops back right into that slot, and I have not been able to figure out a fix for this.

Yes I have registered my TE

Yes i'm registering the Guihandler class in the CommonProxy

if you need anything else just ask

 

GUI Code:

package abused_master.JATMA.GUI;

import abused_master.JATMA.Info;
import abused_master.JATMA.TE.PulverizerContainer;
import abused_master.JATMA.TE.TilePulverizer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerFurnace;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class GuiPulverizer extends GuiContainer {

private static final ResourceLocation Pulverizer = new ResourceLocation(Info.MODID, "textures/gui/Pulverizer.png");
    public static final int WIDTH = 176;
    public static final int HEIGHT = 166;

    public GuiPulverizer(TilePulverizer tileEntity, PulverizerContainer container) {
        super(container);
        xSize = WIDTH;
        ySize = HEIGHT;
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        mc.getTextureManager().bindTexture(Pulverizer);
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    }
    
}

 

Pulverizer Code:

package abused_master.JATMA.Blocks;

import abused_master.JATMA.JATMA;
import abused_master.JATMA.GUI.GuiHandler;
import abused_master.JATMA.TE.TilePulverizer;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class Pulverizer extends BlockContainer {

public Pulverizer(Material material) {
	super(material);
	this.setCreativeTab(JATMA.JATMA);
	this.setUnlocalizedName("Pulverizer");
	this.setHardness(2.0F);
}

    @Override
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TilePulverizer();
}


@Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side,    
    		float hitX, float hitY, float hitZ) {
	if (world.isRemote) {
        player.openGui(JATMA.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
        }
	return true;
}
}

 

Container Code:

package abused_master.JATMA.TE;

import javax.annotation.Nullable;

import abused_master.JATMA.GUI.RemoveOnlySlot;
import abused_master.JATMA.GUI.SlotValidated;
import abused_master.JATMA.GUI.SlotValidator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class PulverizerContainer extends Container implements SlotValidator {

TilePulverizer TP;

public PulverizerContainer(InventoryPlayer inventory, TileEntity tile) {
	super();
	TP = (TilePulverizer) tile;
	addSlotToContainer(new SlotValidated(this, TP, 0, 56, 26));
	addSlotToContainer(new RemoveOnlySlot(TP, 1, 116, 26));

    for (int y = 0; y < 3; ++y) {
        for (int x = 0; x < 9; ++x) {
            this.addSlotToContainer(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
        }
    }

    for (int x = 0; x < 9; ++x) {
        this.addSlotToContainer(new Slot(inventory, x, 8 + x * 18, 142));
    }
}
	@Override
	public boolean isItemValid(ItemStack stack) {
		return false;
	}

@Override
public boolean canInteractWith(EntityPlayer playerIn) {
	return TP.canInteractWith(playerIn);
}



  @Override
   public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slot) {
      Slot slotObject = (Slot) inventorySlots.get(slot);
      if(slotObject != null && slotObject.getHasStack()) {
         ItemStack stackInSlot = slotObject.getStack();
         ItemStack stack = stackInSlot.copy();
         if(slot <= 1) {
            if(!mergeItemStack(stackInSlot, 2, inventorySlots.size(), true))
               return null;
         } else {
            return null;
         }

         if(stackInSlot.stackSize == 0)
            slotObject.putStack(null);
         else
            slotObject.onSlotChanged();

         return stack;
      }
      return null;
   }
}

 

TE Code:

package abused_master.JATMA.TE;

import javax.annotation.Nullable;

import cofh.api.energy.EnergyStorage;
import cofh.api.energy.TileEnergyHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TilePulverizer extends TileEnergyHandler implements IInventory {

protected EnergyStorage storage = new EnergyStorage(50000);
    public static final int SIZE = 9;


@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	storage.readFromNBT(nbt);

	if (nbt.hasKey("items")) {
            itemStackHandler.deserializeNBT((NBTTagCompound) nbt.getTag("items"));
        }
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
        nbt.setTag("items", itemStackHandler.serializeNBT());
	return storage.writeToNBT(nbt);
}

/* IEnergyConnection */
@Override
public boolean canConnectEnergy(EnumFacing from) {

	return true;
}

/* IEnergyReceiver */
@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {

	return storage.receiveEnergy(maxReceive, simulate);
}

/* IEnergyProvider */
@Override
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
	return 0;
	//return storage.extractEnergy(maxExtract, simulate);
}

/* IEnergyHandler */
@Override
public int getEnergyStored(EnumFacing from) {

	return storage.getEnergyStored();
}

@Override
public int getMaxEnergyStored(EnumFacing from) {

	return storage.getMaxEnergyStored();
}





    private ItemStackHandler itemStackHandler = new ItemStackHandler(SIZE) {
        @Override
        protected void onContentsChanged(int slot) {
            // We need to tell the tile entity that something has changed so
            // that the chest contents is persisted
            TilePulverizer.this.markDirty();
        }
    };
    
    
    public boolean canInteractWith(EntityPlayer playerIn) {
        // If we are too far away from this tile entity you cannot use it
        return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
    }

    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return true;
        }
        return super.hasCapability(capability, facing);
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return (T) itemStackHandler;
        }
        return super.getCapability(capability, facing);
    }
    
    
    
    

@Override
public String getName() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean hasCustomName() {
	// TODO Auto-generated method stub
	return false;
}

@Override
public int getSizeInventory() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public ItemStack getStackInSlot(int index) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public ItemStack decrStackSize(int index, int count) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public ItemStack removeStackFromSlot(int index) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	// TODO Auto-generated method stub

}

@Override
public int getInventoryStackLimit() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public void openInventory(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void closeInventory(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public int getField(int id) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void setField(int id, int value) {
	// TODO Auto-generated method stub

}

@Override
public int getFieldCount() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void clear() {
	// TODO Auto-generated method stub

}

public Object getChargeSlot() {
	// TODO Auto-generated method stub
	return null;
}

}

 

GuiHandler Code:

package abused_master.JATMA.GUI;

import abused_master.JATMA.TE.PulverizerContainer;
import abused_master.JATMA.TE.TilePulverizer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {

public static final int GUI_Pulverizer = 0;

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	 BlockPos pos = new BlockPos(x, y, z);
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TilePulverizer) {
            return new PulverizerContainer(player.inventory, (TilePulverizer) te);
        }
       
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        BlockPos pos = new BlockPos(x, y, z);
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TilePulverizer) {
        	TilePulverizer containerTileEntity = (TilePulverizer) te;
            return new GuiPulverizer(containerTileEntity, new PulverizerContainer(player.inventory, containerTileEntity));
        }
	return null;
}
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.