Jump to content

Recommended Posts

Posted

I was having trouble getting an item to do some things, namely change state via keypress and not slow down the player when they are charging it, so I (probably stupidly) moved alot of it's code to my PlayerTickHandler class and had it run if the player held the item and was right clicking/pressing the right button. I immediately ran into a problem. Much of the code I have set to run on the occasions specified will sometimes only run part of the way through only SOMETIMES.

 

Here's the first set of code, it is called when the player has the item in their hand and right click. I have some debug messages in it and it will either stop after initializing all the projectiles, or go all the way through:

 

 

if (player.getHeldItem() != null) {

			if (player.getHeldItem().getItem() instanceof ItemBeam) {
			ItemBeam Beam = (ItemBeam) player.getHeldItem().getItem();
				System.out.println("IsBeamInUse = " + isBeamInUse);
				System.out.println("Mousebuttondown = " + Mouse.isButtonDown(1));
					Beam.t = t;
					Beam.mode = mode;

				if(Mouse.isButtonDown(1)){
					t = t + 1;
					isBeamInUse = true;
				} 

				if(!Mouse.isButtonDown(1) && isBeamInUse){
					player.addChatMessage(new ChatComponentText("Calling onPlayerStoppedUsing!!"));
					if(world == null){
					player.addChatMessage(new ChatComponentText("World null!!"));
					}



					EntityPowerBolt entitypowerbolt = new EntityPowerBolt(world,
							player);
					player.addChatMessage(new ChatComponentText("Initalized powerbolt"));

					EntityChargedPowerBolt entitychargedpowerbolt = new EntityChargedPowerBolt(
							world, player);
					player.addChatMessage(new ChatComponentText("Initalized charged powerbolt"));

					EntityIceBolt entityicebolt = new EntityIceBolt(world,
							player);
					player.addChatMessage(new ChatComponentText("Initalized icebolt"));

					EntityChargedIceBolt entitychargedicebolt = new EntityChargedIceBolt(
							world, player);
					player.addChatMessage(new ChatComponentText("Initalized charged iceboltbolt"));

					EntityWaveBolt entitywavebolt = new EntityWaveBolt(world,
							player);
					player.addChatMessage(new ChatComponentText("Initalized wavebolt"));

					EntityChargedWaveBolt entitychargedwavebolt = new EntityChargedWaveBolt(
							world, player);
					player.addChatMessage(new ChatComponentText("Initalized charged wavebolt"));


					EntityPlasmaBolt entityplasmabolt = new EntityPlasmaBolt(world,
							player);
					player.addChatMessage(new ChatComponentText("Initalized plasmabolt"));

					EntityChargedPlasmaBolt entitychargedplasmabolt = new EntityChargedPlasmaBolt(
							world, player);
					player.addChatMessage(new ChatComponentText("Initalized charged plasmabolt"));

					EntityLightBolt entitylightbolt = new EntityLightBolt(world,
							player);
					EntityChargedLightBolt entitychargedlightbolt = new EntityChargedLightBolt(
							world, player);

					EntityDarkBolt entitydarkbolt = new EntityDarkBolt(world,
							player);
					EntityChargedDarkBolt entitychargeddarkbolt = new EntityChargedDarkBolt(
							world, player);

					EntityAnnihilatorBolt entityannihilatorbolt = new EntityAnnihilatorBolt(
							world, player);
					EntityChargedAnnihilatorBolt entitychargedannihilatorbolt = new EntityChargedAnnihilatorBolt(
							world, player);

					EntityUnchargedNovaBolt entityunchargednovabolt = new EntityUnchargedNovaBolt(
							world, player);

					EntityFlamethrower entityflamethrower = new EntityFlamethrower(
							world, player);
					EntityWaveBuster entitywavebuster = new EntityWaveBuster(world,
							player);
					EntityIceSpreader entityicespreader = new EntityIceSpreader(world,
							player);
					EntityNovaBolt entitynovabolt = new EntityNovaBolt(world,
							player);

					// Insert fireing sound here
					player.addChatMessage(new ChatComponentText("Initalized everything"));

					if (!world.isRemote) {
						player.addChatMessage(new ChatComponentText("World isn't remote!!"));




						if (t < 60) {
							player.addChatMessage(new ChatComponentText("Time less than 60"));

							if (mode == 1) {
								player.addChatMessage(new ChatComponentText("Spawning powerbolt"));

								world.spawnEntityInWorld(entitypowerbolt);
							}
							if (mode == 2) {
								world.spawnEntityInWorld(entityicebolt);
							}
							if (mode == 3) {
								world.spawnEntityInWorld(entitywavebolt);
							}
							if (mode == 4) {
								world.spawnEntityInWorld(entityplasmabolt);
							}
							if (mode == 5) {
								world.spawnEntityInWorld(entitydarkbolt);
							}
							if (mode == 6) {
								world.spawnEntityInWorld(entityannihilatorbolt);
							}
							if (mode == 7) {
								world.spawnEntityInWorld(entitylightbolt);
							}
							if (mode ==  {
								world.spawnEntityInWorld(entityunchargednovabolt);
							}
							t = 0;



						} else if (t >= 60) {
							player.addChatMessage(new ChatComponentText("Time more than 60"));

							if (mode == 1) {
								world.spawnEntityInWorld(entitychargedpowerbolt);
							}
							if (mode == 2) {
								world.spawnEntityInWorld(entitychargedicebolt);
							}
							if (mode == 3) {
								world.spawnEntityInWorld(entitychargedwavebolt);
							}
							if (mode == 4) {
								world.spawnEntityInWorld(entitychargedplasmabolt);
							}
							if (mode == 5) {
								world.spawnEntityInWorld(entitychargeddarkbolt);
							}
							if (mode == 6) {
								world.spawnEntityInWorld(entitychargedannihilatorbolt);
							}
							if (mode == 7) {
								world.spawnEntityInWorld(entitychargedlightbolt);
							}
							if (mode ==  {
								world.spawnEntityInWorld(entitynovabolt);
							}
							t = 0;

						}
					}




					isBeamInUse = false;
					t = 0;

				}

 

 

 

The second set of code (relating to changing a variable called mode depending on different keybinds) behaves the EXACT same way as the first, only working about half the time. Anyone know what the heck is causing this, or a better solution I could use instead of moving the code to my playertickhandler? (Keeping the code in my item class isn't an option as far as I know, as the only time onStoppedUsingItem is called is when the player stopped 'using' it, which means the player must start 'using' it, which slows down the player while they're 'using' it. I've tried to stop or counter this slowdown by boosting the players speed, and using player.setEating(false);, both to no avail)

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Posted

Keep in mind that keys / mouse are only available CLIENT side, so you must send a packet to the server letting it know what the key states are or what to do, and then let your tick handler go from there.

 

One option to keep the code in your Item class is to use the onUpdate method that maps use, as that's called every tick while the item is in inventory whether or not it is in use or held. You will still need to send packets if you don't use the vanilla system for using items, and set a custom using item flag either in your player's IExtendedEntityProperties or the ItemStack's NBT. The former is probably best, especially if you plan on having other items with a similar mechanic.

 

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) {
// check if the item is held, if entity is a player and "isCustomItemInUse" or whatever
// then do what you want with no move slowdown, since the item is not in use as far as vanilla is concerned
}

Posted

Keep in mind that keys / mouse are only available CLIENT side, so you must send a packet to the server letting it know what the key states are or what to do, and then let your tick handler go from there.

 

One option to keep the code in your Item class is to use the onUpdate method that maps use, as that's called every tick while the item is in inventory whether or not it is in use or held. You will still need to send packets if you don't use the vanilla system for using items, and set a custom using item flag either in your player's IExtendedEntityProperties or the ItemStack's NBT. The former is probably best, especially if you plan on having other items with a similar mechanic.

 

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) {
// check if the item is held, if entity is a player and "isCustomItemInUse" or whatever
// then do what you want with no move slowdown, since the item is not in use as far as vanilla is concerned
}

Thanks! This makes a hell of a lot more sense then putting my item code in a tickhandler :P

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Posted

Keep in mind that keys / mouse are only available CLIENT side, so you must send a packet to the server letting it know what the key states are or what to do, and then let your tick handler go from there.

 

One option to keep the code in your Item class is to use the onUpdate method that maps use, as that's called every tick while the item is in inventory whether or not it is in use or held. You will still need to send packets if you don't use the vanilla system for using items, and set a custom using item flag either in your player's IExtendedEntityProperties or the ItemStack's NBT. The former is probably best, especially if you plan on having other items with a similar mechanic.

 

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) {
// check if the item is held, if entity is a player and "isCustomItemInUse" or whatever
// then do what you want with no move slowdown, since the item is not in use as far as vanilla is concerned
}

I transferred it into my items onUpdate method, and it's still acting the same as it was, spawning the projectile about half the time and getting exactly as far as it did before when it doesn't... I'm probs REALLY stupid for having to ask this but what do I need to use packets for? I'm really not 100% sure what I would be telling the server that it doesn't already know, the bullets that DO spawn do damage to mobs, which do die and drop their items...

 

EDIT: Confirmed, i'm an idiot. The reason the entities are spawning half the time is because the other half the world is remote, meaning i'd have to send packets to the server those times, right? Time to set up a packet handler... Still not sure what differentiates the times where the world is and isn't remote, seems arbitrary to me...

 

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

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.