Jump to content

Recommended Posts

Posted

Hello,

I'm programing my own Gui, this works relative good.

BUT: I cant drag any Item into the Slot of my Gui, it jumps back to the Slot where it came from.How can I make this work ?

Sorry for my English, I am German.

Posted

Block:

public class OreDisgenerator extends BlockContainer{

 

public OreDisgenerator(int id, Material Material) {

super(id, 15, Material.iron);

setStepSound(soundMetalFootstep);

}

 

public String getTextureFile(){

return "/modTextures/Blocks.png";

}

public boolean renderAsNormalBlock() {

return false;

}

@Override

public TileEntity createNewTileEntity(World var1) {

return new TileDisgenerator();

}

 

 

@Override

public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){

 

Object tileD = (TileDisgenerator)par1World.getBlockTileEntity(x, y, z);

par5EntityPlayer.openGui(OreGenerators.instance, 0, par1World, x, y, z);

return true;

 

}

 

@Override

    public void breakBlock(World world, int x, int y, int z, int par5, int par6) {

            dropItems(world, x, y, z);

            super.breakBlock(world, x, y, z, par5, par6);

    }

 

private void dropItems(World world, int x, int y, int z){

        Random rand = new Random();

 

        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if (!(tileEntity instanceof IInventory)) {

                return;

        }

        IInventory inventory = (IInventory) tileEntity;

 

        for (int i = 0; i < inventory.getSizeInventory(); i++) {

                ItemStack item = inventory.getStackInSlot(i);

 

                if (item != null && item.stackSize > 0) {

                        float rx = rand.nextFloat() * 0.8F + 0.1F;

                        float ry = rand.nextFloat() * 0.8F + 0.1F;

                        float rz = rand.nextFloat() * 0.8F + 0.1F;

 

                        EntityItem entityItem = new EntityItem(world,

                                        x + rx, y + ry, z + rz,

                                        new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));

 

                        if (item.hasTagCompound()) {

                                entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());

                        }

 

                        float factor = 0.05F;

                        entityItem.motionX = rand.nextGaussian() * factor;

                        entityItem.motionY = rand.nextGaussian() * factor + 0.2F;

                        entityItem.motionZ = rand.nextGaussian() * factor;

                        world.spawnEntityInWorld(entityItem);

                        item.stackSize = 0;

                }

        }

}

}

 

TileEntity:

 

public class TileDisgenerator extends TileEntity implements IInventory {

 

ItemStack[] items = new ItemStack[1];

 

@Override

public int getSizeInventory() {

return 1;

}

 

@Override

public ItemStack getStackInSlot(int slot) {

return items[slot];

}

 

@Override

public ItemStack decrStackSize(int slot, int amt) {

ItemStack stack = getStackInSlot(slot);

        if (stack != null) {

                if (stack.stackSize <= amt) {

                        setInventorySlotContents(slot, null);

                } else {

                        stack = stack.splitStack(amt);

                        if (stack.stackSize == 0) {

                                setInventorySlotContents(slot, null);

                        }

                }

        }

        return stack;

}

 

@Override

public ItemStack getStackInSlotOnClosing(int slot) {

ItemStack stack = getStackInSlot(slot);

        if (stack != null) {

                setInventorySlotContents(slot, null);

        }

        return stack;

}

 

@Override

public void setInventorySlotContents(int slot, ItemStack stack) {

items[slot] = stack;

        if (stack != null && stack.stackSize > getInventoryStackLimit()) {

                stack.stackSize = getInventoryStackLimit();

        } 

}

 

@Override

public String getInvName() {

return "Ore Disgenerator";

}

 

@Override

public int getInventoryStackLimit() {

return 1;

}

 

@Override

public void onInventoryChanged() {

 

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer var1) {

return true;

}

 

@Override

public void openChest() {

 

}

 

@Override

public void closeChest() {

 

}

 

@Override

    public void readFromNBT(NBTTagCompound tagCompound) {

            super.readFromNBT(tagCompound);

            this.setInventorySlotContents(0, new ItemStack(tagCompound.getInteger("ItemID"), tagCompound.getInteger("StackSize"), 0));

    }

 

@Override

    public void writeToNBT(NBTTagCompound tagCompound) {

            super.writeToNBT(tagCompound);

            tagCompound.setInteger("ItemID", this.getStackInSlot(0).itemID); 

            tagCompound.setInteger("StackSize", this.getStackInSlot(0).stackSize);

    }

 

}

 

Container:

 

public class ContainerDisgenerator extends Container{

 

 

private TileDisgenerator inv;

 

public ContainerDisgenerator(InventoryPlayer inventory, TileDisgenerator entity) {

inv = entity;

addSlotToContainer(new Slot(entity, 0, 10, 29));

for (int i = 0; i < 3; i++) {

for (int k = 0; k < 9; k++) {

        addSlotToContainer(new Slot(inventory, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));

    }

}

 

for (int j = 0; j < 9; j++) {

addSlotToContainer(new Slot(inventory, j, 8 + j * 18, 142));

}

 

}

 

@Override

public boolean canInteractWith(EntityPlayer var1) {

inv.isUseableByPlayer(var1);

return false;

}

 

@Override

    public ItemStack transferStackInSlot(EntityPlayer player, int i) {

Slot slot = (Slot) getSlot(i);

ItemStack itemstack1 = slot.getStack();

Slot slot1 = (Slot)this.getSlot(0);

slot1.putStack(itemstack1);

slot.putStack(null);

return itemstack1;

 

}

}

 

GUIHandler:

 

public class GuiHandler implements IGuiHandler {

 

        @Override

        public Object getServerGuiElement(int id, EntityPlayer player, World world,

                        int x, int y, int z) {

                TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

                if(tileEntity instanceof TileDisgenerator){

                        return new ContainerDisgenerator(player.inventory, (TileDisgenerator) tileEntity);

                }

                return null;

        }

        @Override

        public Object getClientGuiElement(int id, EntityPlayer player, World world,

                        int x, int y, int z) {

                TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

                if(tileEntity instanceof TileDisgenerator){

                        return new GUIDisgenerator(player.inventory, (TileDisgenerator) tileEntity);

                }

                return null;

 

        }

}

 

GUI:

 

public class GUIDisgenerator extends GuiContainer{

 

Container DisCon;

int x;

int y;

 

public GUIDisgenerator(InventoryPlayer inventory, TileDisgenerator tileD) {

super(new ContainerDisgenerator(inventory,tileD));

DisCon = new ContainerDisgenerator(inventory,tileD);

}

 

protected void drawGuiContainerForegroundLayer() {

fontRenderer.drawString("Ore Disgenerator", x+10, y+10, 0xffffff);

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float var1, int var2,

int var3) {

x = (width - xSize) / 2;

y = (height - ySize) / 2;

int i = mc.renderEngine.getTexture("/modTextures/GUIDisgen.png");

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

mc.renderEngine.bindTexture(i);

drawTexturedModalRect(x, y, 0, 0, xSize, ySize);

}

 

    @Override

    public void initGui() {

            super.initGui();

            controlList.add(new GuiButton(1, x + (width -150)/2, y + 95, 150, 20, "Disgenerate"));//id,x,y,w,h,n

    }

 

    protected void actionPerformed(GuiButton guibutton) {

            System.out.println("geht");

    }

}

Posted

If i write:

if(!par1World.isRemote){

Object tileD = (TileDisgenerator)par1World.getBlockTileEntity(x, y, z);

par5EntityPlayer.openGui(OreGenerators.instance, 0, par1World, x, y, z);

}

Into the onBlockActivated Method, Nothing happens when I rightclicK the Block

Posted

So you say you are never gonna update because of RedPower2? Just use Project Red, a good alternative to RedPower2. RedPower2 is never gonna be updated because Eloraam, the writer of the mod, decided to go missing and not update the mod anymore.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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