Skip to content

Commit

Permalink
Add blood essence entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jun 10, 2024
1 parent 65210ef commit b722ca6
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.client.models.ModelHSSoul;
import mod.emt.harkenscythe.entities.HSSoul;
import mod.emt.harkenscythe.entities.HSEntitySoul;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
Expand All @@ -14,7 +14,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderHSSoul extends Render<HSSoul>
public class RenderHSSoul extends Render<HSEntitySoul>
{
private static final ResourceLocation SOUL_TEXTURES = new ResourceLocation(HarkenScythe.MOD_ID, "textures/entities/soul_common.png");
private final ModelBase modelSoul = new ModelHSSoul();
Expand All @@ -26,7 +26,7 @@ public RenderHSSoul(RenderManager renderManagerIn)
}

@Override
public void doRender(HSSoul entity, double x, double y, double z, float entityYaw, float partialTicks)
public void doRender(HSEntitySoul entity, double x, double y, double z, float entityYaw, float partialTicks)
{
float f = (float) entity.getInnerRotation() + partialTicks;
GlStateManager.pushMatrix();
Expand All @@ -40,15 +40,15 @@ public void doRender(HSSoul entity, double x, double y, double z, float entityYa
}

@Override
protected ResourceLocation getEntityTexture(HSSoul entity)
protected ResourceLocation getEntityTexture(HSEntitySoul entity)
{
return SOUL_TEXTURES;
}

public static class Factory implements IRenderFactory<HSSoul>
public static class Factory implements IRenderFactory<HSEntitySoul>
{
@Override
public Render<? super HSSoul> createRenderFor(RenderManager manager)
public Render<? super HSEntitySoul> createRenderFor(RenderManager manager)
{
return new RenderHSSoul(manager);
}
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/mod/emt/harkenscythe/entities/HSEntityBlood.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mod.emt.harkenscythe.entities;

import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.HSEssenceKeeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;

public class HSEntityBlood extends HSEntityEssence
{
public HSEntityBlood(World worldIn)
{
super(worldIn);
}

@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if (item instanceof HSEssenceKeeper)
{
if (!player.capabilities.isCreativeMode)
{
if (item == HSItems.essence_keeper || item == HSItems.essence_vessel)
{
stack.shrink(1);
ItemStack newStack = item == HSItems.essence_keeper ? new ItemStack(HSItems.essence_keeper_blood) : new ItemStack(HSItems.essence_vessel_blood);
newStack.setItemDamage(newStack.getMaxDamage() - 1);
player.setHeldItem(hand, newStack);
}
else if (item == HSItems.essence_keeper_blood || item == HSItems.essence_vessel_blood)
{
if (stack.getItemDamage() == 0) return false;
if (stack.getItemDamage() > 0)
{
stack.setItemDamage(stack.getItemDamage() - 1);
}
if (stack.getItemDamage() <= 0)
{
stack.shrink(1);
ItemStack newStack = item == HSItems.essence_keeper_blood ? new ItemStack(HSItems.essence_keeper_blood) : new ItemStack(HSItems.essence_vessel_blood);
player.setHeldItem(hand, newStack);
}
}
}
this.world.playSound(null, player.getPosition(), SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.PLAYERS, 1.0F, 1.0F);
this.world.spawnParticle(EnumParticleTypes.CLOUD, this.posX, this.posY + 1.5D, this.posZ, 0.0D, 0.1D, 0.0D);
this.setDead();
}
return super.processInitialInteract(player, hand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
import java.util.List;
import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.init.HSSoundEvents;
import mod.emt.harkenscythe.items.HSEssenceKeeper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;

public class HSSoul extends Entity
public abstract class HSEntityEssence extends Entity
{
private static final int DESPAWN_TIME = 6000;
private int innerRotation;

public HSSoul(World worldIn)
protected HSEntityEssence(World worldIn)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
Expand Down Expand Up @@ -89,42 +85,4 @@ protected void readEntityFromNBT(NBTTagCompound compound) {}

@Override
protected void writeEntityToNBT(NBTTagCompound compound) {}

@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if (item instanceof HSEssenceKeeper)
{
if (!player.capabilities.isCreativeMode)
{
if (item == HSItems.essence_keeper || item == HSItems.essence_vessel)
{
stack.shrink(1);
ItemStack newStack = item == HSItems.essence_keeper ? new ItemStack(HSItems.essence_keeper_soul) : new ItemStack(HSItems.essence_vessel_soul);
newStack.setItemDamage(newStack.getMaxDamage() - 1);
player.setHeldItem(hand, newStack);
}
else if (item == HSItems.essence_keeper_soul || item == HSItems.essence_vessel_soul)
{
if (stack.getItemDamage() == 0) return false;
if (stack.getItemDamage() > 0)
{
stack.setItemDamage(stack.getItemDamage() - 1);
}
if (stack.getItemDamage() <= 0)
{
stack.shrink(1);
ItemStack newStack = item == HSItems.essence_keeper_soul ? new ItemStack(HSItems.essence_keeper_soul) : new ItemStack(HSItems.essence_vessel_soul);
player.setHeldItem(hand, newStack);
}
}
}
this.world.playSound(null, player.getPosition(), SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.PLAYERS, 1.0F, 1.0F);
this.world.spawnParticle(EnumParticleTypes.CLOUD, this.posX, this.posY + 1.5D, this.posZ, 0.0D, 0.1D, 0.0D);
this.setDead();
}
return super.processInitialInteract(player, hand);
}
}
58 changes: 58 additions & 0 deletions src/main/java/mod/emt/harkenscythe/entities/HSEntitySoul.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mod.emt.harkenscythe.entities;

import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.HSEssenceKeeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;

public class HSEntitySoul extends HSEntityEssence
{
public HSEntitySoul(World worldIn)
{
super(worldIn);
}

@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if (item instanceof HSEssenceKeeper)
{
if (!player.capabilities.isCreativeMode)
{
if (item == HSItems.essence_keeper || item == HSItems.essence_vessel)
{
stack.shrink(1);
ItemStack newStack = item == HSItems.essence_keeper ? new ItemStack(HSItems.essence_keeper_soul) : new ItemStack(HSItems.essence_vessel_soul);
newStack.setItemDamage(newStack.getMaxDamage() - 1);
player.setHeldItem(hand, newStack);
}
else if (item == HSItems.essence_keeper_soul || item == HSItems.essence_vessel_soul)
{
if (stack.getItemDamage() == 0) return false;
if (stack.getItemDamage() > 0)
{
stack.setItemDamage(stack.getItemDamage() - 1);
}
if (stack.getItemDamage() <= 0)
{
stack.shrink(1);
ItemStack newStack = item == HSItems.essence_keeper_soul ? new ItemStack(HSItems.essence_keeper_soul) : new ItemStack(HSItems.essence_vessel_soul);
player.setHeldItem(hand, newStack);
}
}
}
this.world.playSound(null, player.getPosition(), SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.PLAYERS, 1.0F, 1.0F);
this.world.spawnParticle(EnumParticleTypes.CLOUD, this.posX, this.posY + 1.5D, this.posZ, 0.0D, 0.1D, 0.0D);
this.setDead();
}
return super.processInitialInteract(player, hand);
}
}
14 changes: 11 additions & 3 deletions src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mod.emt.harkenscythe.events;

import mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.entities.HSSoul;
import mod.emt.harkenscythe.entities.HSEntityBlood;
import mod.emt.harkenscythe.entities.HSEntitySoul;
import mod.emt.harkenscythe.items.tools.HSGlaive;
import mod.emt.harkenscythe.items.tools.HSScythe;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -23,9 +25,15 @@ public static void onEntityDeath(LivingDeathEvent event)
if (!world.isRemote && damageSource.getTrueSource() instanceof EntityPlayer && damageSource.getDamageType().equals("hs_reap"))
{
EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
if (player.getHeldItemMainhand().getItem() instanceof HSScythe)
if (player.getHeldItemMainhand().getItem() instanceof HSGlaive)
{
HSSoul soul = new HSSoul(world);
HSEntityBlood blood = new HSEntityBlood(world);
blood.setPosition(entity.posX, entity.posY, entity.posZ);
world.spawnEntity(blood);
}
else if (player.getHeldItemMainhand().getItem() instanceof HSScythe)
{
HSEntitySoul soul = new HSEntitySoul(world);
soul.setPosition(entity.posX, entity.posY, entity.posZ);
world.spawnEntity(soul);
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/mod/emt/harkenscythe/init/HSRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.client.renderers.RenderHSSoul;
import mod.emt.harkenscythe.client.renderers.RenderHSSoulAltar;
import mod.emt.harkenscythe.entities.HSSoul;
import mod.emt.harkenscythe.entities.HSEntityBlood;
import mod.emt.harkenscythe.entities.HSEntitySoul;
import mod.emt.harkenscythe.tileentities.HSSoulAltarTE;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -54,12 +55,8 @@ public static void registerEntities(RegistryEvent.Register<EntityEntry> event)
{
int id = 1;
event.getRegistry().registerAll(
EntityEntryBuilder.create()
.entity(HSSoul.class)
.id(new ResourceLocation(HarkenScythe.MOD_ID, "soul"), id++)
.name("soul")
.tracker(64, 1, true)
.build()
EntityEntryBuilder.create().entity(HSEntityBlood.class).id(new ResourceLocation(HarkenScythe.MOD_ID, "blood"), id++).name("blood").tracker(64, 1, true).build(),
EntityEntryBuilder.create().entity(HSEntitySoul.class).id(new ResourceLocation(HarkenScythe.MOD_ID, "soul"), id++).name("soul").tracker(64, 1, true).build()
);
}

Expand All @@ -83,7 +80,7 @@ public static void registerRecipes()
@SubscribeEvent
public static void registerEntityRenderers(ModelRegistryEvent event)
{
RenderingRegistry.registerEntityRenderingHandler(HSSoul.class, new RenderHSSoul.Factory());
RenderingRegistry.registerEntityRenderingHandler(HSEntitySoul.class, new RenderHSSoul.Factory());
}

@SideOnly(Side.CLIENT)
Expand Down

0 comments on commit b722ca6

Please sign in to comment.