本文整理汇总了Java中net.minecraft.util.FoodStats.addStats方法的典型用法代码示例。如果您正苦于以下问题:Java FoodStats.addStats方法的具体用法?Java FoodStats.addStats怎么用?Java FoodStats.addStats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.FoodStats
的用法示例。
在下文中一共展示了FoodStats.addStats方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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);
}
}
示例4: onItemRightClick
import net.minecraft.util.FoodStats; //导入方法依赖的package包/类
@Override
public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer player){
int lunchCarried=MAX_FOOD_CARRIED-stack.getItemDamage();
FoodStats stats=player.getFoodStats();
int playerHunger=20-stats.getFoodLevel();
//feed the player until either they are full or the luncher is out of food
int toFeedToPlayer=Math.min(lunchCarried, playerHunger);
if(toFeedToPlayer>0){ //if player is hungry and luncher isn't empty
w.playSoundAtEntity(player, "random.burp", 0.5F, w.rand.nextFloat() * 0.1F + 0.9F);
stats.addStats(toFeedToPlayer, 0);
stack.setItemDamage(stack.getItemDamage()+toFeedToPlayer);
//Debug.dbg("Luncher omnomnomnom! Ate "+toFeedToPlayer);
}else{
int foodGathered=0;
boolean full=false;
for(int i=0; i<player.inventory.mainInventory.length; i++){
ItemStack stk=player.inventory.mainInventory[i];
if(stk!=null && stk.getItem() instanceof ItemFood){ //check if food
ItemFood item=(ItemFood) stk.getItem();
int foodPerItem=item.func_150905_g(stk);
int numberCanConsume=(int) Math.floor( (double)stack.getItemDamage() /foodPerItem );
int eating=stack.getItemDamage()-foodPerItem*Math.min(numberCanConsume, stk.stackSize);
//Debug.dbg("Can eat "+numberCanConsume + " of " + stk.stackSize +". Eating "+eating );
stack.setItemDamage(Math.max(eating,0));
if(numberCanConsume>=stk.stackSize){
player.inventory.mainInventory[i]=null;
}else{
stk.stackSize-=numberCanConsume;
}
}
if(full)break;
}
}
return stack;
}
示例5: setFoodData
import net.minecraft.util.FoodStats; //导入方法依赖的package包/类
private void setFoodData (FoodStats foodStats, int foodLevel, float saturationLevel) {
foodStats.addStats(1, (saturationLevel - foodStats.getSaturationLevel()) / 2);
foodStats.addStats(foodLevel - foodStats.getFoodLevel(), 0);
}