Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Draco18s

Members
  • Joined

  • Last visited

Posts posted by Draco18s

  1. Stop using unlocalized name and start using setRegistryName.  Don't ever use getUnlocalizedName().substring(5) for anything, ever.  Stop doing it.  That's bad.  Really really bad, perpetuated by a shitty tutorial that follows tons of bad practices and should be taken down.

  2. Also, oh god, that if-stack checking whether the item given was equal to an array of stuff.

     

    Jesus christ.

     

     

    Cleaned it up

     

     

     

    public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c)
    {
    	if (!player.isSneaking())
    	{
    		boolean hasSpace = false;
        	int giftedVolume = 0;
        	String giftedItem = "";
        	Random ran = new Random();
        	int randomNum = ran.nextInt(10);
        	int maxStack = 64;
        	giftedVolume = 1;
            
            if (player.inventory.getFirstEmptyStack() != -1)
       			{
       					hasSpace = true;
       			} else {
       				for (int slot = 0; slot < player.inventory.getSizeInventory(); ++slot)
       				{
       					ItemStack itemstack = player.inventory.getStackInSlot(slot);
       					if (itemstack != null && itemstack.isItemEqual(checkStack[randomNum]))
       				    {
       					    int volume = itemstack.stackSize;
       					    if (volume < maxStack)
       					    {
       						    hasSpace = true;
       						    break;
       					    }
       				    }
       				}
       			}		
       			
            if (hasSpace == true)
       			{
    			ItemStack stack;
    			switch(randomNum) {
    				case 0:
    					stack = new ItemStack(Items.coal,1);
    					giftedItem = "Some coal";
    					break;
    				case 1:
    					stack = new ItemStack(Items.rotten_flesh,1);
    					giftedItem = "Some rotten meat";
    					break;
    				case 2:
    					stack = new ItemStack(Items.wheat_seeds,1);
    					giftedItem = "Some seeds";
    					break;
    				case 3:
    					stack = new ItemStack(Items.bone,1);
    					giftedItem = "A bone";
    					break;
    				case 4:
    					stack = new ItemStack(Items.flint,1);
    					giftedItem = "A piece of flint";
    					break;
    				case 5:
    					stack = new ItemStack(Items.fish,1);
    					giftedItem = "Fresh fish";
    					break;
    				case 6:
    					stack = new ItemStack(Items.bread,1);
    					giftedItem = "A loaf of bread";
    					break;
    				case 7:
    					stack = new ItemStack(Items.string,1);
    					giftedItem = "A piece of string";
    					break;
    				case 8:
    					stack = new ItemStack(Items.bowl,1);
    					giftedItem = "A wooden bowl";
    					break;
    			}
    			player.inventory.addItemStackToInventory(stack);
            			        	
            	String successMessage = EnumChatFormatting.YELLOW + ">You searched the crate and discovered... " + giftedItem;
       		   		if(!world.isRemote)
       		   		{	
       		   			player.addChatComponentMessage(new ChatComponentText(successMessage));
       		   		}
       		   			this.func_150185_e(world, x, y, z);
       			}
       		
       			   			   			    
       			if (hasSpace == false)
       			{
       				if(!world.isRemote)
       				{	
       					player.addChatComponentMessage(new ChatComponentText("Searching this crate would be a waste as your inventory is full!"));
       				}
       			}
       			
        	return true;
    	} else {
    		return false;
    	}
    }
    

     

     

  3. What you want is a coremod that operates via ASM.

     

    ASM is a very deep, dark abyss and you will get minimal help figuring out how to make a coremod.  Primarily because:

     

    1) You should not be modifying base classes at all ever, doing so can very easily introduce mod conflicts.

    2) ASM requires understanding Java bytecode, you will need to know this before you can start, at all.

    3) Providing resources on how to coremod will cause more people to go "yay, I can modify base classes!" when they didn't need to.

     

    Given that you are interested in doing this on 1.9, I suggest actually supplying a patch back to Forge as a Pull Request that inserts an event hook where you want it, that way you don't have to modify vanilla classes.

  4. I don't think my for loop is pointless, because it cycles trough all the metadata.

     

    And then doesn't give a shit what the actual value of the metadata was, because it performed the same check on all of them:

    meta == i

    It doesn't matter what value

    meta

    was from the world (because it can only be 0 to 15), at some point during that loop that check will be true.

     

    Following that, because you are doing

    return true

    in the block-check, as soon as it determines that yes, one of these blocks is what we're looking for it never even fucking checks your loop.

  5. You need to look at ClassLoaders.

     

    ClassLoaders are objects that load other classes when needed.  This means that you can write a custom class loader that fetches a class, examines it, makes changes (if it wants), and then passes it off to the JVM.

  6. And some are weirdly related, like seeds.  Seeds are absolutely not the item form of a block, yet when used they create a block, when that block is middle-clicked, you get a seed, and when the block is broken, you get the seed (usually!)

     

    But you can also get seeds from breaking tall grass (which has its own itemblock!)

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.