Skip to content

Commit

Permalink
Add potion entity, items & recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jun 24, 2024
1 parent 49397d6 commit 05fe9de
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package mod.emt.harkenscythe.entities;

import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.HSItemSpectralPotion;
import mod.emt.harkenscythe.potions.HSPotionFlame;
import mod.emt.harkenscythe.potions.HSPotionWater;
import net.minecraft.entity.EntityAreaEffectCloud;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class HSEntitySpectralPotion extends EntityThrowable
{
private PotionEffect potionEffect;
private ItemStack potionStack = new ItemStack(HSItems.spectral_glass_bottle);

public HSEntitySpectralPotion(World world)
{
super(world);
}

public HSEntitySpectralPotion(World world, double x, double y, double z)
{
super(world, x, y, z);
}

public HSEntitySpectralPotion(World world, EntityLivingBase thrower)
{
super(world, thrower);
}

public HSEntitySpectralPotion(World world, EntityLivingBase thrower, ItemStack potionStack)
{
super(world, thrower);
if (potionStack.getItem() instanceof HSItemSpectralPotion)
{
this.potionEffect = ((HSItemSpectralPotion) potionStack.getItem()).getPotionEffect();
this.potionStack = potionStack;
}
}

public ItemStack getPotionStack()
{
return potionStack;
}

public PotionEffect getPotionEffect()
{
return potionEffect;
}

@Override
protected float getGravityVelocity()
{
return 0.07F;
}

@Override
protected void onImpact(RayTraceResult result)
{
if (!this.world.isRemote)
{
if (potionEffect.getPotion() instanceof HSPotionFlame)
{
this.world.playEvent(2002, new BlockPos(this), potionEffect.getPotion().getLiquidColor());
for (int x = -1; x <= 1; x++)
{
for (int y = 0; y <= 2; y++)
{
for (int z = -1; z <= 1; z++)
{
BlockPos pos = this.getPosition().add(x, y, z);
if (world.isAirBlock(pos))
{
world.setBlockState(pos, Blocks.FIRE.getDefaultState());
}
}
}
}
}
else if (potionEffect.getPotion() instanceof HSPotionWater)
{
this.world.playEvent(2002, new BlockPos(this), potionEffect.getPotion().getLiquidColor());
for (int x = -1; x <= 1; x++)
{
for (int y = 0; y <= 2; y++)
{
for (int z = -1; z <= 1; z++)
{
BlockPos pos = this.getPosition().add(x, y, z);
if (world.getBlockState(pos).getBlock() == Blocks.FIRE)
{
world.setBlockToAir(pos);
}
}
}
}
}
else if (potionEffect != null)
{
this.world.playEvent(2002, new BlockPos(this), potionEffect.getPotion().getLiquidColor());
EntityAreaEffectCloud effectCloud = new EntityAreaEffectCloud(this.world, this.posX, this.posY, this.posZ);
effectCloud.setRadius(3.0F);
effectCloud.setRadiusOnUse(-0.5F);
effectCloud.setWaitTime(10);
effectCloud.setDuration(effectCloud.getDuration() / 2);
effectCloud.setRadiusPerTick(-effectCloud.getRadius() / (float) effectCloud.getDuration());
effectCloud.addEffect(potionEffect);
this.world.spawnEntity(effectCloud);
}
this.setDead();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public static void onItemColor(ColorHandlerEvent.Item event)
{
event.getItemColors().registerItemColorHandler(HSItems.bloodweave_hood, HSItems.bloodweave_hood, HSItems.bloodweave_robe, HSItems.bloodweave_pants, HSItems.bloodweave_shoes);
event.getItemColors().registerItemColorHandler(HSItems.soulweave_hood, HSItems.soulweave_hood, HSItems.soulweave_robe, HSItems.soulweave_pants, HSItems.soulweave_shoes);
event.getItemColors().registerItemColorHandler(HSItems.spectral_potion_affliction, HSItems.spectral_potion_affliction);
event.getItemColors().registerItemColorHandler(HSItems.spectral_potion_flame, HSItems.spectral_potion_flame);
event.getItemColors().registerItemColorHandler(HSItems.spectral_potion_purifying, HSItems.spectral_potion_purifying);
event.getItemColors().registerItemColorHandler(HSItems.spectral_potion_water, HSItems.spectral_potion_water);
}
}
18 changes: 16 additions & 2 deletions src/main/java/mod/emt/harkenscythe/init/HSItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import mod.emt.harkenscythe.items.HSFood;
import mod.emt.harkenscythe.items.HSItem;
import mod.emt.harkenscythe.items.HSItemBlockSpecial;
import mod.emt.harkenscythe.items.HSItemSpectralBottle;
import mod.emt.harkenscythe.items.HSItemSpectralPotion;
import mod.emt.harkenscythe.items.HSNecronomicon;
import mod.emt.harkenscythe.items.tools.HSAxe;
import mod.emt.harkenscythe.items.tools.HSGlaive;
Expand Down Expand Up @@ -167,7 +169,15 @@ public class HSItems
public static HSSword harken_athame;

@GameRegistry.ObjectHolder("spectral_glass_bottle")
public static HSItem spectral_glass_bottle;
public static HSItemSpectralBottle spectral_glass_bottle;
@GameRegistry.ObjectHolder("spectral_potion_affliction")
public static HSItemSpectralPotion spectral_potion_affliction;
@GameRegistry.ObjectHolder("spectral_potion_flame")
public static HSItemSpectralPotion spectral_potion_flame;
@GameRegistry.ObjectHolder("spectral_potion_purifying")
public static HSItemSpectralPotion spectral_potion_purifying;
@GameRegistry.ObjectHolder("spectral_potion_water")
public static HSItemSpectralPotion spectral_potion_water;

@GameRegistry.ObjectHolder("bloodweave_hood")
public static HSDyeableArmor bloodweave_hood;
Expand Down Expand Up @@ -259,7 +269,11 @@ public static void onRegisterItemsEvent(@Nonnull final RegistryEvent.Register<It
HSRegistry.setup(new HSFood(3, 0.2F, false, 16, true, EnumRarity.UNCOMMON), "soul_cookie").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItem(EnumRarity.COMMON), "blunt_harken_blade").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSSword(ToolMaterial.IRON, EnumRarity.COMMON), "harken_athame").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItem(EnumRarity.UNCOMMON), "spectral_glass_bottle").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItemSpectralBottle(EnumRarity.UNCOMMON), "spectral_glass_bottle").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItemSpectralPotion(EnumRarity.UNCOMMON, HSPotions.AFFLICTION), "spectral_potion_affliction").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItemSpectralPotion(EnumRarity.UNCOMMON, HSPotions.FLAME), "spectral_potion_flame").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItemSpectralPotion(EnumRarity.UNCOMMON, HSPotions.PURIFYING), "spectral_potion_purifying").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSItemSpectralPotion(EnumRarity.UNCOMMON, HSPotions.WATER), "spectral_potion_water").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSDyeableArmor(ARMOR_BLOODWEAVE, 0, EntityEquipmentSlot.HEAD, EnumRarity.UNCOMMON, 11546150), "bloodweave_hood").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSDyeableArmor(ARMOR_BLOODWEAVE, 0, EntityEquipmentSlot.CHEST, EnumRarity.UNCOMMON, 11546150), "bloodweave_robe").setCreativeTab(HarkenScythe.TAB),
HSRegistry.setup(new HSDyeableArmor(ARMOR_BLOODWEAVE, 0, EntityEquipmentSlot.LEGS, EnumRarity.UNCOMMON, 11546150), "bloodweave_pants").setCreativeTab(HarkenScythe.TAB),
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/mod/emt/harkenscythe/init/HSRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
import mod.emt.harkenscythe.entities.HSEntityHarbinger;
import mod.emt.harkenscythe.entities.HSEntityHemoglobin;
import mod.emt.harkenscythe.entities.HSEntitySoul;
import mod.emt.harkenscythe.entities.HSEntitySpectralPotion;
import mod.emt.harkenscythe.tileentities.HSTileEntityBloodAltar;
import mod.emt.harkenscythe.tileentities.HSTileEntitySoulAltar;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -71,6 +74,8 @@ public static void registerEntities(RegistryEvent.Register<EntityEntry> event)

registerEntity("hemoglobin", HSEntityHemoglobin.class);
registerEntity("ectoglobin", HSEntityEctoglobin.class);

registerEntity("spectral_potion", HSEntitySpectralPotion.class);
}

public static void registerEntity(String name, Class<? extends Entity> clazz, int eggColor1, int eggColor2)
Expand All @@ -97,6 +102,8 @@ public static void registerRecipes()
HSAltarRecipes.addBloodRecipe(Items.GLASS_BOTTLE, Items.DRAGON_BREATH, 40);
HSAltarRecipes.addBloodRecipe("wool", Item.getItemFromBlock(HSBlocks.bloodweave_cloth), 10);

HSAltarRecipes.addSoulRecipe(HSItems.spectral_potion_flame, HSItems.spectral_potion_affliction, 10);
HSAltarRecipes.addSoulRecipe(HSItems.spectral_potion_water, HSItems.spectral_potion_purifying, 10);
HSAltarRecipes.addSoulRecipe(Items.CAKE, HSItems.soul_cake, 10);
HSAltarRecipes.addSoulRecipe(Items.COOKIE, HSItems.soul_cookie, 10);
//HSAltarRecipes.addSoulRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.AWKWARD).getItem(), Items.EXPERIENCE_BOTTLE, 40); // TODO: Something better for this?
Expand Down Expand Up @@ -137,6 +144,8 @@ public static void registerEntityRenderers(ModelRegistryEvent event)
RenderingRegistry.registerEntityRenderingHandler(HSEntityHarbinger.class, new RenderHSEntityHarbinger.Factory());
RenderingRegistry.registerEntityRenderingHandler(HSEntityHemoglobin.class, new RenderHSHemoglobin.Factory());
RenderingRegistry.registerEntityRenderingHandler(HSEntitySoul.class, new RenderHSEntitySoul.Factory());
// TODO: Render respective potions instead of bottle
RenderingRegistry.registerEntityRenderingHandler(HSEntitySpectralPotion.class, manager -> new RenderSnowball<>(manager, HSItems.spectral_glass_bottle, Minecraft.getMinecraft().getRenderItem()));
}

@SideOnly(Side.CLIENT)
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/mod/emt/harkenscythe/items/HSItemSpectralBottle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package mod.emt.harkenscythe.items;

import mod.emt.harkenscythe.init.HSItems;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class HSItemSpectralBottle extends HSItem
{
public HSItemSpectralBottle(EnumRarity rarity)
{
super(rarity);
this.setMaxStackSize(16);
}

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
if (!world.isRemote)
{
ItemStack itemStack = player.getHeldItem(hand);
RayTraceResult rayTraceResult = this.rayTrace(world, player, true);
if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos pos = rayTraceResult.getBlockPos();
IBlockState state = world.getBlockState(pos);
IBlockState stateUp = world.getBlockState(pos.up());
if (state.getMaterial() == Material.WATER || stateUp.getMaterial() == Material.FIRE)
{
if (stateUp.getMaterial() == Material.FIRE) world.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 11);
itemStack.shrink(1);
player.addItemStackToInventory(state.getMaterial() == Material.WATER ? new ItemStack(HSItems.spectral_potion_water) : new ItemStack(HSItems.spectral_potion_flame));
world.playSound(null, player.getPosition(), state.getMaterial() == Material.WATER ? SoundEvents.ITEM_BOTTLE_FILL : SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.PLAYERS, 1.0F, 1.0F);
player.addStat(StatList.getObjectUseStats(this));
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
}
}
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
}
71 changes: 71 additions & 0 deletions src/main/java/mod/emt/harkenscythe/items/HSItemSpectralPotion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package mod.emt.harkenscythe.items;

import mod.emt.harkenscythe.entities.HSEntitySpectralPotion;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class HSItemSpectralPotion extends HSItem implements IItemColor
{
private final PotionEffect potionEffect;

public HSItemSpectralPotion(EnumRarity rarity, Potion potion)
{
super(rarity);
this.setMaxStackSize(1);
this.potionEffect = new PotionEffect(potion, 600);
}

public PotionEffect getPotionEffect()
{
return potionEffect;
}

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack itemStack = player.getHeldItem(hand);

if (!player.isCreative())
{
itemStack.shrink(1);
}

world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_LINGERINGPOTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

if (!world.isRemote)
{
HSEntitySpectralPotion spectralPotion = new HSEntitySpectralPotion(world, player, itemStack);
spectralPotion.shoot(player, player.rotationPitch, player.rotationYaw, -20.0F, 0.7F, 1.0F);
world.spawnEntity(spectralPotion);
}

player.addStat(StatList.getObjectUseStats(this));
return new ActionResult<>(EnumActionResult.SUCCESS, itemStack);
}

@SideOnly(Side.CLIENT)
@Override
public boolean hasEffect(ItemStack stack)
{
return true;
}

@Override
public int colorMultiplier(ItemStack stack, int tintIndex)
{
return tintIndex > 0 ? -1 : getPotionEffect().getPotion().getLiquidColor();
}
}
26 changes: 0 additions & 26 deletions src/main/java/mod/emt/harkenscythe/potions/HSPotionFlame.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package mod.emt.harkenscythe.potions;

import mod.emt.harkenscythe.HarkenScythe;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class HSPotionFlame extends Potion
{
Expand All @@ -18,27 +13,6 @@ public HSPotionFlame(String name)
setRegistryName(HarkenScythe.MOD_ID, name);
}

@Override
public void affectEntity(Entity source, Entity indirectSource, EntityLivingBase entityLivingBase, int amplifier, double health)
{
World world = entityLivingBase.world;
BlockPos pos = entityLivingBase.getPosition();
for (int x = -1; x <= 1; x++)
{
for (int y = 0; y <= 1; y++)
{
for (int z = -1; z <= 1; z++)
{
BlockPos firePos = pos.add(x, y, z);
if (world.isAirBlock(firePos))
{
world.setBlockState(firePos, Blocks.FIRE.getDefaultState());
}
}
}
}
}

@Override
public boolean shouldRender(PotionEffect effect)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import mod.emt.harkenscythe.HarkenScythe;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
Expand All @@ -25,9 +24,10 @@ public void performEffect(EntityLivingBase entityLivingBase, int amplifier)
}
else
{
entityLivingBase.removePotionEffect(MobEffects.POISON);
entityLivingBase.removePotionEffect(MobEffects.WITHER);
entityLivingBase.removePotionEffect(MobEffects.BLINDNESS);
for (PotionEffect effect : entityLivingBase.getActivePotionEffects())
{
if (effect.getPotion().isBadEffect() && !effect.getCurativeItems().isEmpty()) entityLivingBase.removePotionEffect(effect.getPotion());
}
}
}

Expand Down
Loading

0 comments on commit 05fe9de

Please sign in to comment.