本文整理汇总了Java中net.minecraft.util.FoodStats类的典型用法代码示例。如果您正苦于以下问题:Java FoodStats类的具体用法?Java FoodStats怎么用?Java FoodStats使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FoodStats类属于net.minecraft.util包,在下文中一共展示了FoodStats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHeal
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOW)
public static void onHeal(LivingHealEvent event) {
EntityLivingBase entity = event.getEntityLiving();
if (!entity.hasCapability(CapabilityExtendedHealthSystem.INSTANCE, null))
return;
event.setCanceled(true);
if (!FirstAid.activeHealingConfig.allowOtherHealingItems)
return;
float amount = event.getAmount();
//Hacky shit to reduce vanilla regen
if (FirstAid.activeHealingConfig.allowNaturalRegeneration && Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(stackTraceElement -> stackTraceElement.getClassName().equals(FoodStats.class.getName())))
amount = amount * (float) FirstAid.activeHealingConfig.naturalRegenMultiplier;
else
amount = amount * (float) FirstAid.activeHealingConfig.otherRegenMultiplier;
HealthDistribution.distributeHealth(amount, (EntityPlayer) entity, true);
}
示例2: onUpdate
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@Override
public void onUpdate(EntityPlayerSP player) {
ItemStack curStack = player.inventory.getCurrentItem();
if(isEnabled()) {
if(!shouldEat()) {
Wrapper.getMinecraft().gameSettings.keyBindUseItem.pressed = false;
return;
}
FoodStats foodStats = player.getFoodStats();
if (foodStats.getFoodLevel() <= hungerFactor.getValue() && shouldEat())
{
eatFood();
}
}
}
示例3: getExhaustion
import net.minecraft.util.FoodStats; //导入依赖的package包/类
public static float getExhaustion(EntityPlayer of)
{
FoodStats stats = of.getFoodStats();
if (!foodExhaustionLevelFld.isAccessible())
{
foodExhaustionLevelFld.setAccessible(true);
}
try
{
return foodExhaustionLevelFld.getFloat(stats);
}
catch (Exception ex)
{
FMLCommonHandler.instance().raiseException(ex, "ExPetrum was unable to reflect player's FoodStats!", true);
return -1;
}
}
示例4: setExhaustion
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@SuppressWarnings("SameParameterValue")
public static void setExhaustion(EntityPlayer of, float f)
{
FoodStats stats = of.getFoodStats();
if (!foodExhaustionLevelFld.isAccessible())
{
foodExhaustionLevelFld.setAccessible(true);
}
try
{
foodExhaustionLevelFld.setFloat(stats, f);
}
catch (Exception ex)
{
FMLCommonHandler.instance().raiseException(ex, "ExPetrum was unable to reflect player's FoodStats!", true);
}
}
示例5: addNutrition
import net.minecraft.util.FoodStats; //导入依赖的package包/类
public static void addNutrition(FoodStats fs, ItemStack is)
{
IFoodStatsTFC stats = (IFoodStatsTFC)fs;
TFCFood food = FoodRegistry.getInstance().getFood(is.getItem(), is.getItemDamage());
if(food != null && is.getItem() instanceof ItemFood)
{
ItemFood item = (ItemFood)is.getItem();
Iterator iter = food.foodGroup.iterator();
while(iter.hasNext())
{
FoodGroupPair pair = (FoodGroupPair) iter.next();
float amount = pair.amount;
if(pair.foodGroup != EnumFoodGroup.None)
{
amount = Math.min(stats.getNutritionMap().get(pair.foodGroup) + (item.getHealAmount(is) * (pair.amount / 100f)*0.25f), 20);
stats.getNutritionMap().put(pair.foodGroup, amount);
}
}
}
}
示例6: handleHunger
import net.minecraft.util.FoodStats; //导入依赖的package包/类
/** Handles the hunger setting, returns if hunger is enabled. */
private boolean handleHunger(EntityPlayer player, FoodStats foodStats) {
EnumHunger hunger = AdvHealthOptions.config.<EnumHunger>get(AHOWorldConfig.miscHunger);
if (hunger == EnumHunger.ENABLE) return true;
// Make direct changes to the food meter affect health directly.
if ((hunger == EnumHunger.HEALTH) && foodLevelSet) {
int change = (foodStats.getFoodLevel() - 8);
if (change > 0) player.heal(change);
else if (change < 0) player.attackEntityFrom(DamageSource.starve, -change);
}
// Reset the food level and saturation.
setFoodLevel(player, 0);
foodStats.addStats(8, 20.0F);
foodLevelSet = true;
return false;
}
示例7: doOnServer
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@Override
public void doOnServer(EntityPlayer player, NBTTagCompound dataFromClient)
{
FoodStats food = player.getFoodStats();
switch (dataFromClient.getInteger(OPERATION_KEY))
{
case ADD:
food.addStats((int) dataFromClient.getFloat(AMOUNT_KEY), 0);
break;
case SUBTRACT:
food.addStats((int) -dataFromClient.getFloat(AMOUNT_KEY), 0);
break;
case SET:
food.addStats(-food.getFoodLevel(), 0);
food.addStats((int) dataFromClient.getFloat(AMOUNT_KEY), 0);
break;
}
}
示例8: setFoodStats
import net.minecraft.util.FoodStats; //导入依赖的package包/类
public static void setFoodStats(EntityPlayer player, FoodStats stats)
{
Field[] fields = EntityPlayer.class.getDeclaredFields();
for (Field f : fields)
{
if (f.getType() == FoodStats.class)
{
f.setAccessible(true);
try
{
f.set(player, stats);
}
catch (Exception e)
{
System.out.println(e);
}
}
}
}
示例9: onFoodEaten
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@Override
public void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
if (stack.getTagCompound() == null) {
stack.setTagCompound(new NBTTagCompound()); //not really supposed to happen ingame since you only get the stews with NBT values assigned but it prevents crashing
}
final FoodStats foodStats = player.getFoodStats();
foodStats.setFoodLevel(foodStats.getFoodLevel() + stack.getTagCompound().getInteger("hunger"));
foodStats.setFoodSaturationLevel(foodStats.getFoodLevel() + stack.getTagCompound().getFloat("saturation"));
player.addItemStackToInventory(new ItemStack(Items.BOWL, 1));
}
示例10: onUpdate
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@SubscribeEvent
public void onUpdate(LocalPlayerUpdateEvent event) {
FoodStats foodStats = getLocalPlayer().getFoodStats();
int foodSlot = -1;
ItemStack foodStack = null;
for (int i = 0; i < 9; i++) {
ItemStack stack = getLocalPlayer().inventory.getStackInSlot(i);
if (stack != null &&
stack.getItem() instanceof ItemFood) {
foodSlot = i;
foodStack = stack;
break;
}
}
if (foodStack != null) {
ItemFood itemFood = (ItemFood) foodStack.getItem();
if (20 - foodStats.getFoodLevel() >= itemFood.getHealAmount(foodStack)
&& !getLocalPlayer().isHandActive()
&& FastReflection.Fields.Minecraft_rightClickDelayTimer.get(MC) == 0) {
isEating = true;
MC.player.inventory.currentItem = foodSlot;
// need to fake use key to stop code that stops the eating
Bindings.use.setPressed(true);
FastReflection.Methods.Minecraft_rightClickMouse.invoke(MC);
return;
}
}
if(isEating && !getLocalPlayer().isHandActive()) {
isEating = false;
Bindings.use.setPressed(false);
}
}
示例11: getFoodStats
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@Override
public FoodStats getFoodStats() {
if (m_realPlayer == null) {
return super.getFoodStats();
} else {
syncToRealPlayer();
return syncPublicFieldsFromRealAndReturn(m_realPlayer.getFoodStats());
}
}
示例12: getFoodStats
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@Override
public FoodStats getFoodStats() {
if (m_realPlayer == null) {
return super.getFoodStats();
} else {
return m_realPlayer.getFoodStats();
}
}
示例13: entityUpdate
import net.minecraft.util.FoodStats; //导入依赖的package包/类
@SubscribeEvent
public void entityUpdate(LivingEvent.LivingUpdateEvent event)
{
if(!isPlayer(event.entityLiving))
{
return;
}
EntityPlayer player = (EntityPlayer)event.entityLiving;
PlayerCapabilities capabilities = player.capabilities;
IAttributeInstance movementSpeed = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
if(!checkEquips(player))
{
event.entityLiving.stepHeight = 0.5F;
capabilities.allowFlying = player.capabilities.isCreativeMode;
if(!ModConfig.useSpeedPotion)
{
movementSpeed.setBaseValue(0.1);
}
FoodStats fs = player.getFoodStats();
if(fs != null)
{
fs.addStats(20, 5);
}
return;
}
player.stepHeight = 1;
capabilities.allowFlying = true;
if(!ModConfig.useSpeedPotion)
{
movementSpeed.setBaseValue(ModConfig.speedMultiplicator);
}
}
示例14: resetFoodTimer
import net.minecraft.util.FoodStats; //导入依赖的package包/类
/** Reset the "food timer" to disable Vanilla natural regeneration. */
private void resetFoodTimer(FoodStats foodStats) {
if (foodTimerField == null)
foodTimerField = ReflectionHelper.findField(FoodStats.class, "field_75123_d", "foodTimer");
if (foodStats.getFoodLevel() > 0) {
try { foodTimerField.set(foodStats, 0); }
catch (Exception ex) { throw new RuntimeException(ex); }
}
}
示例15: reset
import net.minecraft.util.FoodStats; //导入依赖的package包/类
public void reset()
{
float exp = 0;
boolean keepInventory = this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory");
if (this.keepLevel || keepInventory)
{
exp = this.experience;
this.newTotalExp = this.experienceTotal;
this.newLevel = this.experienceLevel;
}
this.setHealth(this.getMaxHealth());
this.fire = 0;
this.fallDistance = 0;
this.foodStats = new FoodStats(this);
this.experienceLevel = this.newLevel;
this.experienceTotal = this.newTotalExp;
this.experience = 0;
this.deathTime = 0;
this.clearActivePotions(); // Should be remapped: removeAllEffects should be remapped to this.
super.potionsNeedUpdate = true; // Cauldron - change to super to temporarily workaround remapping bug with SpecialSource
this.openContainer = this.inventoryContainer;
this.attackingPlayer = null;
this.entityLivingToAttack = null;
this._combatTracker = new CombatTracker(this);
this.lastExperience = -1;
if (this.keepLevel || keepInventory)
{
this.experience = exp;
}
else
{
this.addExperience(this.newExp);
}
this.keepLevel = false;
}