Jump to content

[1.5.1]public boolean used in diffrent class


rasmustof

Recommended Posts

 

 

hello

 

so ...  i need to know how i can check if a boolean from annother class is true and then issue some code ... using a simple if statement, but what do i need to type my boolean is called CheckInventoryTrader1 ... can someone please tell me how to do it

 

 

 

Link to comment
Share on other sites

If it's not a static variable, then you need a reference to an instance of that class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

well here is the boolean:

 

    //checking if the placed item is "Hydrocroconyzx ingot" only retuns false if there is no item in the slot since no othere item/block  is allowed in the slot
   public boolean CheckInventoryTrader1(ItemStack par1ItemStack) {
       
       Item item = par1ItemStack.getItem();
       
       if(par1ItemStack != null && item == EsteticsPLUS.HydrocroconyxIngot){
           return true;
       }
       
       else return false;
   }

 

im not intirely sure on how to do so if you can post the code that would be nice

 

Link to comment
Share on other sites

And where is this function?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

And where is this function?

 

its in my slot class here:

 

package EsteticsPLUS;


import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;



public class SlotTrader1 extends Slot{

    public SlotTrader1(EntityPlayer player, IInventory par1iInventory, int par2, int par3, int par4) {
        super(par1iInventory, par2, par3, par4);
        
    }
    
    @Override
    public boolean isItemValid(ItemStack par1ItemStack) {
            if (par1ItemStack != null)
           {
                    Item item = par1ItemStack.getItem();
                    return item != null && item == EsteticsPLUS.HydrocroconyxIngot;
            }
            return false;
    }
   
    
    //checking if the placed item is "Hydrocroconyzx ingot" only retuns false if there is no item in the slot since no othere item/block  is allowed in the slot
   public boolean CheckInventoryTrader1(ItemStack par1ItemStack) {
       
       Item item = par1ItemStack.getItem();
       
       if(par1ItemStack != null && item == EsteticsPLUS.HydrocroconyxIngot){
           return true;
       }
       
       else return false;
   }
    
    
    
}

Link to comment
Share on other sites

When you put a function in a class it is assumed that you need it in that class.  You're not using it in that class (it is, in fact, identical to the isItemValid function) but you want to call that function from another class....why?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

so im making this slot system where you have 2 slots that are inputs and then have a output that is triggered using that boolean(have one in the other slot too) and then from that i can display a metadata block and have a upp and a down button that can modify the output be adding one to the metadata or remove one(hint: i talked a little bit with Vswe about it)

Link to comment
Share on other sites

That is not how you should be doing things.

 

The two input slots handle whether or not the item is valid, the TileEntity should handle if both slots are filled and put the output item in the output slot.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

okay but then what do i need to add in the tileentity

 

Or the Living Entity.  Whateverthehellentity that lets you open the GUI that has the slots in it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

that will be this entity

package EsteticsPLUS;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTrader extends TileEntity implements IInventory {
    
        
    private ItemStack[] inv;

    public TileEntityTrader(){
            inv = new ItemStack[9];
    }
    
    @Override
    public int getSizeInventory() {
            return inv.length;
    }

    @Override
    public ItemStack getStackInSlot(int slot) {
            return inv[slot];
    }
    
    @Override
    public void setInventorySlotContents(int slot, ItemStack stack) {
            inv[slot] = stack;
            if (stack != null && stack.stackSize > getInventoryStackLimit()) {
                    stack.stackSize = getInventoryStackLimit();
            }               
    }

    @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 int getInventoryStackLimit() {
            return 64;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer player) {
            return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
            player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
    }

    @Override
    public void openChest() {}

    @Override
    public void closeChest() {}
    
    @Override
    public void readFromNBT(NBTTagCompound tagCompound) {
            super.readFromNBT(tagCompound);
            
            NBTTagList tagList = tagCompound.getTagList("Inventory");
            for (int i = 0; i < tagList.tagCount(); i++) {
                    NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
                    byte slot = tag.getByte("Slot");
                    if (slot >= 0 && slot < inv.length) {
                            inv[slot] = ItemStack.loadItemStackFromNBT(tag);
                    }
            }
    }

    @Override
    public void writeToNBT(NBTTagCompound tagCompound) {
            super.writeToNBT(tagCompound);
                            
            NBTTagList itemList = new NBTTagList();
            for (int i = 0; i < inv.length; i++) {
                    ItemStack stack = inv[i];
                    if (stack != null) {
                            NBTTagCompound tag = new NBTTagCompound();
                            tag.setByte("Slot", (byte) i);
                            stack.writeToNBT(tag);
                            itemList.appendTag(tag);
                    }
            }
            
            
            tagCompound.setTag("Inventory", itemList);
    }

            @Override
            public String getInvName() {
                    return "EsteticsPLUS.tileentitytrader";
            }

            @Override
            public boolean isInvNameLocalized() {
                return true;
            }

            @Override
            public boolean isStackValidForSlot(int i, ItemStack itemstack) {
                return false;
            }
       
}

 

so what do i need to add?!?

Link to comment
Share on other sites

/**
     * Called when an the contents of an Inventory change, usually
     */
    public void onInventoryChanged() { ... }

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

That void function is the function that checks the slots to see if both have items, and if so, do whatever needs to be done.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

but then how do i put i item inside the output slot?!?

 

slot.putStack(ItemStack item)

 

Le gasp

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.