mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Added a potion effect and death message for food poisoning
This commit is contained in:
parent
c286448d11
commit
3129084f71
10 changed files with 167 additions and 23 deletions
|
@ -55,7 +55,7 @@ public class UBlocks {
|
||||||
.setHarvestFruit(w -> UItems.apple.getRandomApple(w.rand, null))
|
.setHarvestFruit(w -> UItems.apple.getRandomApple(w.rand, null))
|
||||||
.setUnharvestFruit(w -> new ItemStack(UItems.rotten_apple));
|
.setUnharvestFruit(w -> new ItemStack(UItems.rotten_apple));
|
||||||
|
|
||||||
static void registerBlocks(IForgeRegistry<Block> registry) {
|
static void init(IForgeRegistry<Block> registry) {
|
||||||
registry.registerAll(cloud, cloud_stairs, cloud_double_slab, cloud_slab, mist_door, anvil, cloud_farmland,
|
registry.registerAll(cloud, cloud_stairs, cloud_double_slab, cloud_slab, mist_door, anvil, cloud_farmland,
|
||||||
sugar_block,
|
sugar_block,
|
||||||
alfalfa,
|
alfalfa,
|
||||||
|
|
37
src/main/java/com/minelittlepony/unicopia/UEffects.java
Normal file
37
src/main/java/com/minelittlepony/unicopia/UEffects.java
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.potion.UPotion;
|
||||||
|
|
||||||
|
import net.minecraft.init.MobEffects;
|
||||||
|
import net.minecraft.potion.Potion;
|
||||||
|
import net.minecraft.potion.PotionEffect;
|
||||||
|
import net.minecraft.util.DamageSource;
|
||||||
|
import net.minecraftforge.registries.IForgeRegistry;
|
||||||
|
|
||||||
|
public class UEffects {
|
||||||
|
|
||||||
|
public static final DamageSource food_poisoning = new DamageSource("food_poisoning").setDamageBypassesArmor();
|
||||||
|
|
||||||
|
public static final Potion FOOD_POISONING = new UPotion(Unicopia.MODID, "food_poisoning", true, 3484199)
|
||||||
|
.setIconIndex(3, 1)
|
||||||
|
.setSilent()
|
||||||
|
.setEffectiveness(0.25)
|
||||||
|
.setApplicator((p, e, i) -> {
|
||||||
|
|
||||||
|
PotionEffect nausea = e.getActivePotionEffect(MobEffects.NAUSEA);
|
||||||
|
if (nausea == null) {
|
||||||
|
PotionEffect foodEffect = e.getActivePotionEffect(p);
|
||||||
|
nausea = new PotionEffect(MobEffects.NAUSEA, foodEffect.getDuration(), foodEffect.getAmplifier(), foodEffect.getIsAmbient(), foodEffect.doesShowParticles());
|
||||||
|
|
||||||
|
e.addPotionEffect(nausea);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.attackEntityFrom(food_poisoning, i);
|
||||||
|
});
|
||||||
|
|
||||||
|
static void init(IForgeRegistry<Potion> registry) {
|
||||||
|
registry.registerAll(
|
||||||
|
FOOD_POISONING
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -170,7 +170,7 @@ public class UItems {
|
||||||
.setUseAction(EnumAction.DRINK)
|
.setUseAction(EnumAction.DRINK)
|
||||||
.setContainerItem(Items.GLASS_BOTTLE);
|
.setContainerItem(Items.GLASS_BOTTLE);
|
||||||
|
|
||||||
static void registerItems(IForgeRegistry<Item> registry) {
|
static void init(IForgeRegistry<Item> registry) {
|
||||||
RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r
|
RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r
|
||||||
.replace(Items.APPLE, apple)
|
.replace(Items.APPLE, apple)
|
||||||
.replace(Items.STICK, stick)
|
.replace(Items.STICK, stick)
|
||||||
|
@ -237,7 +237,7 @@ public class UItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
@FUF(reason = "There is no way to register custom recipe types that support nbt data. Waiting for mixins...")
|
@FUF(reason = "There is no way to register custom recipe types that support nbt data. Waiting for mixins...")
|
||||||
static void registerRecipes(IForgeRegistry<IRecipe> registry) {
|
static void initRecipes(IForgeRegistry<IRecipe> registry) {
|
||||||
Ingredient dewdrop = Ingredient.fromItem(dew_drop);
|
Ingredient dewdrop = Ingredient.fromItem(dew_drop);
|
||||||
Ingredient cloud = Ingredient.fromStacks(new ItemStack(cloud_block, 1, 0));
|
Ingredient cloud = Ingredient.fromStacks(new ItemStack(cloud_block, 1, 0));
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.item.EnumAction;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraft.potion.Potion;
|
||||||
import net.minecraft.util.SoundEvent;
|
import net.minecraft.util.SoundEvent;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -121,17 +122,22 @@ public class Unicopia implements IGuiHandler {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||||
UItems.registerItems(event.getRegistry());
|
UItems.init(event.getRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
||||||
UBlocks.registerBlocks(event.getRegistry());
|
UBlocks.init(event.getRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
|
public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
|
||||||
UItems.registerRecipes(event.getRegistry());
|
UItems.initRecipes(event.getRegistry());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerPotions(RegistryEvent.Register<Potion> event) {
|
||||||
|
UEffects.init(event.getRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|
|
@ -33,15 +33,15 @@ public class BushToxicityDeterminent implements IEdible {
|
||||||
|
|
||||||
if ((type == ROSE || type == FERN)
|
if ((type == ROSE || type == FERN)
|
||||||
&& player.world.rand.nextInt(30) == 0) {
|
&& player.world.rand.nextInt(30) == 0) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.INSTANT_DAMAGE, 1, 1));
|
player.addPotionEffect(new PotionEffect(MobEffects.INSTANT_DAMAGE, 1, 1, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == GRASS) {
|
if (type == GRASS) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 30, 1));
|
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 30, 1, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == FERN) {
|
if (type == FERN) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 30, 1));
|
player.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 30, 1, false, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ public class FlowerToxicityDeterminent implements IEdible {
|
||||||
BlockFlower.EnumFlowerType type = getType(stack);
|
BlockFlower.EnumFlowerType type = getType(stack);
|
||||||
|
|
||||||
if (type == HOUSTONIA && player.world.rand.nextInt(30) == 0) {
|
if (type == HOUSTONIA && player.world.rand.nextInt(30) == 0) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 10, 1));
|
player.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 10, 1, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == OXEYE_DAISY) {
|
if (type == OXEYE_DAISY) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 30, 1));
|
player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 30, 1, false, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@ import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
|
import com.minelittlepony.unicopia.UEffects;
|
||||||
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
|
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
|
||||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||||
|
|
||||||
import net.minecraft.advancements.CriteriaTriggers;
|
import net.minecraft.advancements.CriteriaTriggers;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -27,7 +27,6 @@ import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.EnumActionResult;
|
import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
||||||
|
@ -78,11 +77,7 @@ public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||||
Toxicity toxicity = getToxicityLevel(stack);
|
tooltip.add(getToxicityLevel(stack).getTooltip());
|
||||||
|
|
||||||
TextFormatting color = toxicity.toxicWhenCooked() ? TextFormatting.RED : toxicity.toxicWhenRaw() ? TextFormatting.DARK_PURPLE : TextFormatting.GRAY;
|
|
||||||
|
|
||||||
tooltip.add(color + I18n.format(toxicity.getTranslationKey()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,8 +98,6 @@ public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
||||||
if (entityplayer instanceof EntityPlayerMP) {
|
if (entityplayer instanceof EntityPlayerMP) {
|
||||||
CriteriaTriggers.CONSUME_ITEM.trigger((EntityPlayerMP)entityplayer, stack);
|
CriteriaTriggers.CONSUME_ITEM.trigger((EntityPlayerMP)entityplayer, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityplayer == null || !entityplayer.capabilities.isCreativeMode) {
|
if (entityplayer == null || !entityplayer.capabilities.isCreativeMode) {
|
||||||
|
@ -143,10 +136,9 @@ public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toxicity.isLethal()) {
|
if (toxicity.isLethal()) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 300, 7));
|
player.addPotionEffect(new PotionEffect(UEffects.FOOD_POISONING, 300, 7, false, false));
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.WITHER, 300, 7));
|
|
||||||
} else if (toxicity.toxicWhenCooked()) {
|
} else if (toxicity.toxicWhenCooked()) {
|
||||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 3, 1));
|
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 3, 1, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
toxicityDeterminant.addSecondaryEffects(player, toxicity, stack);
|
toxicityDeterminant.addSecondaryEffects(player, toxicity, stack);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.minelittlepony.unicopia.edibles;
|
package com.minelittlepony.unicopia.edibles;
|
||||||
|
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.init.MobEffects;
|
import net.minecraft.init.MobEffects;
|
||||||
import net.minecraft.potion.PotionEffect;
|
import net.minecraft.potion.PotionEffect;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
|
||||||
public enum Toxicity {
|
public enum Toxicity {
|
||||||
SAFE(0, 0),
|
SAFE(0, 0),
|
||||||
|
@ -44,6 +46,12 @@ public enum Toxicity {
|
||||||
return String.format("toxicity.%s.name", name().toLowerCase());
|
return String.format("toxicity.%s.name", name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTooltip() {
|
||||||
|
TextFormatting color = toxicWhenCooked() ? TextFormatting.RED : toxicWhenRaw() ? TextFormatting.DARK_PURPLE : TextFormatting.GRAY;
|
||||||
|
|
||||||
|
return color + I18n.format(getTranslationKey());
|
||||||
|
}
|
||||||
|
|
||||||
public static Toxicity byMetadata(int metadata) {
|
public static Toxicity byMetadata(int metadata) {
|
||||||
return values[metadata % values.length];
|
return values[metadata % values.length];
|
||||||
}
|
}
|
||||||
|
|
100
src/main/java/com/minelittlepony/unicopia/potion/UPotion.java
Normal file
100
src/main/java/com/minelittlepony/unicopia/potion/UPotion.java
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
package com.minelittlepony.unicopia.potion;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.potion.Potion;
|
||||||
|
import net.minecraft.potion.PotionEffect;
|
||||||
|
|
||||||
|
public class UPotion extends Potion {
|
||||||
|
|
||||||
|
private boolean isSilent;
|
||||||
|
private int tickDelay = 40;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private IEffectApplicator applicator = IEffectApplicator.NONE;
|
||||||
|
|
||||||
|
public UPotion(String domain, String name, boolean isNegative, int tint) {
|
||||||
|
super(isNegative, tint);
|
||||||
|
|
||||||
|
setRegistryName(domain, name);
|
||||||
|
setPotionName("effect." + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UPotion setSilent() {
|
||||||
|
isSilent = true;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UPotion setApplicator(@Nonnull IEffectApplicator applicator) {
|
||||||
|
this.applicator = applicator;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UPotion setTickDelay(int delay) {
|
||||||
|
tickDelay = delay;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UPotion setIconIndex(int u, int v) {
|
||||||
|
super.setIconIndex(u, v);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UPotion setEffectiveness(double effectiveness) {
|
||||||
|
super.setEffectiveness(effectiveness);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldRender(PotionEffect effect) {
|
||||||
|
return isSilent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldRenderInvText(PotionEffect effect) {
|
||||||
|
return isSilent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldRenderHUD(PotionEffect effect) {
|
||||||
|
return isSilent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performEffect(EntityLivingBase entity, int amplifier) {
|
||||||
|
applicator.performEffect(this, entity, amplifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInstant() {
|
||||||
|
return tickDelay > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReady(int duration, int amplifier) {
|
||||||
|
if (!isInstant()) {
|
||||||
|
int i = tickDelay >> amplifier;
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
return duration % i == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IEffectApplicator {
|
||||||
|
IEffectApplicator NONE = (p, e, i) -> {};
|
||||||
|
|
||||||
|
void performEffect(Potion effect, EntityLivingBase target, int amplifier);
|
||||||
|
}
|
||||||
|
}
|
|
@ -194,6 +194,7 @@ death.attack.fire.player=%1$s was burnt to a crisp by %2$s
|
||||||
death.attack.fire.own=%1$s was burnt to a crisp by their own spell
|
death.attack.fire.own=%1$s was burnt to a crisp by their own spell
|
||||||
death.attack.zap=%1$s ate a Zap Apple
|
death.attack.zap=%1$s ate a Zap Apple
|
||||||
death.attack.paradox=%1$s imploded
|
death.attack.paradox=%1$s imploded
|
||||||
|
death.attack.food_poisoning=%1%s died of food poisoning
|
||||||
|
|
||||||
advancements.adventure.bag_of_holding.title=Read the Manual
|
advancements.adventure.bag_of_holding.title=Read the Manual
|
||||||
advancements.adventure.bag_of_holding.description=Successfuly die using the Bag of Holding
|
advancements.adventure.bag_of_holding.description=Successfuly die using the Bag of Holding
|
||||||
|
|
Loading…
Reference in a new issue