Jump to content

[1.7.2] issue with Events [SOLVED]


zacharyjaiden

Recommended Posts

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));
		}

	}

}
} 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.