Jump to content

Recommended Posts

Posted

Hello, I'm trying to make it so whenever the player is eating my food they go into third person mode, and when they're done, they're put into first person mode.

 

Putting them in third person mode works, but not putting them in first person.

 

Here's how I'm putting the player into first person mode:

if(world.isRemote) {
		MCUtil.getMC().gameSettings.thirdPersonView = 0;
	}

 

I tried placing the code into the onUpdate method and it worked, but I need it in the onFoodEaten or onEaten method.

 

ItemSandvich:

package tf2crates.item;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import tf2crates.ReferenceTC;
import tf2crates.crate.RandomLoot;
import tlhpoeCore.util.MCUtil;

public class ItemSandvich extends ItemFood {
public ItemSandvich() {
	super(20, 0.32F, true);

	this.setUnlocalizedName("sandvich");
	this.setTextureName(ReferenceTC.ID + ":sandvich");
	this.setMaxStackSize(1);
	this.setMaxDamage(6001);
	this.setAlwaysEdible();

	RandomLoot.WEAPONS.add(this);
}

@Override
public int getMaxItemUseDuration(ItemStack itemStack) {
	return 64;
}

@Override
protected void onFoodEaten(ItemStack itemStack, World world, EntityPlayer player) {
	if(!world.isRemote) {
		player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 600, 2));
		player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 600, 2));
		player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 600, 1));

		player.heal(player.getMaxHealth());

		itemStack.setItemDamage(6000);
	} else {
		MCUtil.getMC().gameSettings.thirdPersonView = 0; //No work
	}
}

@Override
public ItemStack onEaten(ItemStack itemStack, World world, EntityPlayer player) {
	player.getFoodStats().func_151686_a(this, itemStack);

	if(world.isRemote) {
		MCUtil.getMC().gameSettings.thirdPersonView = 0; //No work again
	}

	world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);

	this.onFoodEaten(itemStack, world, player);

	return itemStack;
}

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
	if(itemStack.getItemDamage() == 0) {
		player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
	}

	return itemStack;
}

@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int f, boolean f2) {
	int dmg = itemStack.getItemDamage();

	if(dmg > 0) {
		itemStack.setItemDamage(dmg - 1);
	}

	if(entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) entity;

		if(player.isEating()) {
			ItemStack held = player.getHeldItem();

			if(held != null && held.getItem() == this) {
				if(world.isRemote) {
					MCUtil.getMC().gameSettings.thirdPersonView = 1;
				}

				player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 1, 5));
			}
		}
	}
}
}

Kain

Posted

Hi

 

Are you sure your .thirdPersonView code in onFoodEaten or onEaten is being called?  I have a suspicion that onEaten might not be called on the client.

 

You could test that by putting

System.out.println("Side: " + (world.isRemote ? "client" : "server"));

at the top of onEaten.

 

-TGG

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.