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

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

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

  • Author

That's weird... I tried it with the print and it worked. embarrassed.gif

 

Thanks anyways TGG!

Kain

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.