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.

Featured Replies

Posted

Trying to limit the ability to hold a specific item when the condition isnt met. it works fine although the player cant hold the item when the condition IS met either :/ any ideas, also its set that upon deletion of the item, the relative materials are added back the the players inventory BUT theyre also glitching out and rather then adding only one instance of the materials theyre flooding the inventory by the bucketfull

 

code as follows

 

package com.MCR.MinecraftReloaded.Event;

import com.MCR.MinecraftReloaded.Items.ModItems;
import com.MCR.MinecraftReloaded.LevelingLib.StorageMiningExperience;
import com.MCR.MinecraftReloaded.LevelingLib.StorageMiningLevel;
import com.MCR.MinecraftReloaded.LevelingLib.StorageWoodCuttingExperience;
import com.MCR.MinecraftReloaded.LevelingLib.StorageWoodCuttingLevel;
import com.MCR.MinecraftReloaded.LevelingLib.SyncPlayerPropsPacketMiningLevel;
import com.MCR.MinecraftReloaded.Main.MinecraftReloaded;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;

public class PlayerLivingUpdateEvent 
{


@SubscribeEvent
public void onPlayerUpdate(LivingUpdateEvent event)
{
	if(event.entityLiving instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.entityLiving;


		if(player.inventory.hasItem(ModItems.CastrealmPickaxe) && StorageMiningLevel.get(player).GetLevel() < 5);{
			player.inventory.consumeInventoryItem(ModItems.CastrealmPickaxe);
	  		player.inventory.addItemStackToInventory(new ItemStack(Items.stick, 2));
	  		player.inventory.addItemStackToInventory(new ItemStack(ModItems.CastrealmIngot, 3));
		}

	}

}
} 

You could try:

 

@SubscribeEvent
public void onPlayerUpdate(LivingUpdateEvent event) {
	if(event.entityLiving instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer)event.entityLiving;
                        boolean given = false;
		if(player.inventory.hasItem(ModItems.CastrealmPickaxe) && StorageMiningLevel.get(player).GetLevel() < 5 && !given){
			player.inventory.consumeInventoryItem(ModItems.CastrealmPickaxe);
			player.inventory.addItemStackToInventory(new ItemStack(Items.stick, 2));
			player.inventory.addItemStackToInventory(new ItemStack(ModItems.CastrealmIngot, 3));
                                given = true;
		}
	}
}

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

  • Author

thanks for the advice but it i tried the code and it didnt stop the mass spamming of additions to the inventory nor the inability to hold the pickaxe EVEN if the condition (level) is met :(

 

i dont see why its doing this, the if statement states that IF the players holding both a pickaxe AND has a level lower than 5, run the contents of {} but i dont even have a pickaxe in my inventory and its spamming ingots and sticks into it

I just fixed it, you had ");{" on this line:

 

if(player.inventory.hasItem(ModItems.CastrealmPickaxe) && StorageMiningLevel.get(player).GetLevel() < 5 && !given){

 

Maybe that will help

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

  • Author

OMG thats it! :D thankyou, i cant believe i overlooked something so simple!!! serves me right for being lazy and copying "StorageMiningLevel.get(player).GetLevel());" from another class in my mod to save time :/

 

+1000 karma for you mate :) :) :) :) :) :)

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...

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.