mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed and balanced food effects for changelings
This commit is contained in:
parent
502ac54dfd
commit
eaa2790116
5 changed files with 109 additions and 7 deletions
|
@ -6,7 +6,6 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
|
@ -239,12 +238,30 @@ public class Unicopia implements IGuiHandler {
|
|||
Commands.init(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onItemUseBegin(LivingEntityUseItemEvent.Start event) {
|
||||
Entity e = event.getEntity();
|
||||
|
||||
if (!event.isCanceled() && e instanceof EntityPlayer) {
|
||||
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).getFood().begin(event.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onItemUseCancel(LivingEntityUseItemEvent.Stop event) {
|
||||
Entity e = event.getEntity();
|
||||
|
||||
if (!event.isCanceled() && e instanceof EntityPlayer) {
|
||||
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).getFood().end();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onItemUseFinish(LivingEntityUseItemEvent.Finish event) {
|
||||
Entity e = event.getEntity();
|
||||
|
||||
if (!event.isCanceled() && e instanceof EntityPlayer && event.getItem().getItemUseAction() == EnumAction.EAT) {
|
||||
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).onEntityEat();
|
||||
if (!event.isCanceled() && e instanceof EntityPlayer) {
|
||||
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).getFood().finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
src/main/java/com/minelittlepony/unicopia/player/IFood.java
Normal file
11
src/main/java/com/minelittlepony/unicopia/player/IFood.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package com.minelittlepony.unicopia.player;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IFood {
|
||||
void begin(ItemStack stack);
|
||||
|
||||
void end();
|
||||
|
||||
void finish();
|
||||
}
|
|
@ -2,6 +2,8 @@ package com.minelittlepony.unicopia.player;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.model.anim.IInterpolator;
|
||||
import com.minelittlepony.unicopia.UClient;
|
||||
import com.minelittlepony.unicopia.enchanting.IPageOwner;
|
||||
|
@ -10,6 +12,8 @@ import com.minelittlepony.unicopia.spell.ICaster;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPlayer>, ITransmittable, IPageOwner {
|
||||
|
@ -20,6 +24,8 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
|
|||
|
||||
IView getCamera();
|
||||
|
||||
IFood getFood();
|
||||
|
||||
IInterpolator getInterpolator();
|
||||
|
||||
float getExertion();
|
||||
|
@ -44,7 +50,7 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
|
|||
|
||||
void copyFrom(IPlayer oldPlayer);
|
||||
|
||||
void onEntityEat();
|
||||
void onEntityEat(ItemStack stack, @Nullable ItemFood food);
|
||||
|
||||
boolean stepOnCloud();
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@ package com.minelittlepony.unicopia.player;
|
|||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.minelittlepony.model.anim.BasicEasingInterpolator;
|
||||
import com.minelittlepony.model.anim.IInterpolator;
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.UEffects;
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.network.EffectSync;
|
||||
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
|
||||
|
@ -19,6 +21,8 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
|
@ -27,6 +31,7 @@ import net.minecraft.network.datasync.EntityDataManager;
|
|||
import net.minecraft.network.play.server.SPacketSetPassengers;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
|
||||
class PlayerCapabilities implements IPlayer {
|
||||
|
||||
|
@ -52,6 +57,8 @@ class PlayerCapabilities implements IPlayer {
|
|||
|
||||
private final PlayerView view = new PlayerView(this);
|
||||
|
||||
private final PlayerFood food = new PlayerFood(this);
|
||||
|
||||
private final EffectSync<EntityPlayer> effectDelegate = new EffectSync<>(this, EFFECT);
|
||||
|
||||
private final IInterpolator interpolator = new BasicEasingInterpolator();
|
||||
|
@ -224,12 +231,31 @@ class PlayerCapabilities implements IPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onEntityEat() {
|
||||
public IFood getFood() {
|
||||
return food;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityEat(ItemStack stack, @Nullable ItemFood food) {
|
||||
if (getPlayerSpecies() == Race.CHANGELING) {
|
||||
EntityPlayer player = getOwner();
|
||||
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 2000, 2));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 2000, 2));
|
||||
if (food != null) {
|
||||
int health = food.getHealAmount(stack);
|
||||
float saturation = food.getSaturationModifier(stack);
|
||||
|
||||
player.getFoodStats().addStats(-health/2, -saturation/2);
|
||||
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 100, 3, true, true));
|
||||
} else {
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 200, 3, true, true));
|
||||
}
|
||||
|
||||
if (player.world.getDifficulty() != EnumDifficulty.PEACEFUL && player.world.rand.nextInt(20) == 0) {
|
||||
player.addPotionEffect(new PotionEffect(UEffects.FOOD_POISONING, 300, 2, true, true));
|
||||
}
|
||||
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 2000, 2, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.minelittlepony.unicopia.player;
|
||||
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
class PlayerFood implements IFood {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
private ItemStack eatingStack = ItemStack.EMPTY;
|
||||
|
||||
public PlayerFood(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(ItemStack stack) {
|
||||
eatingStack = ItemStack.EMPTY;
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
EnumAction action = stack.getItemUseAction();
|
||||
|
||||
if (action == EnumAction.EAT && stack.getItem() instanceof ItemFood) {
|
||||
eatingStack = stack.copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
eatingStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
if (!eatingStack.isEmpty()) {
|
||||
player.onEntityEat(eatingStack, (ItemFood)eatingStack.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue