-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package mod.emt.harkenscythe.entities; | ||
|
||
import mod.emt.harkenscythe.init.HSItems; | ||
import mod.emt.harkenscythe.items.HSEssenceKeeper; | ||
import net.minecraft.entity.Entity; | ||
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 HSSoul(World worldIn) | ||
{ | ||
super(worldIn); | ||
this.setSize(0.8F, 2.0F); | ||
} | ||
|
||
@Override | ||
protected void entityInit() {} | ||
|
||
@Override | ||
protected boolean canTriggerWalking() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canBeCollidedWith() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
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, 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); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/mod/emt/harkenscythe/entities/render/HSSoulRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package mod.emt.harkenscythe.entities.render; | ||
|
||
import mod.emt.harkenscythe.entities.HSSoul; | ||
import net.minecraft.client.model.ModelBase; | ||
import net.minecraft.client.model.ModelEnderCrystal; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.client.renderer.entity.Render; | ||
import net.minecraft.client.renderer.entity.RenderManager; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.fml.client.registry.IRenderFactory; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class HSSoulRender extends Render<HSSoul> | ||
{ | ||
private static final ResourceLocation SOUL_TEXTURES = new ResourceLocation("textures/entity/endercrystal/endercrystal.png"); | ||
private final ModelBase modelSoul = new ModelEnderCrystal(0.0F, false); | ||
|
||
public HSSoulRender(RenderManager renderManagerIn) | ||
{ | ||
super(renderManagerIn); | ||
this.shadowSize = 0.0F; | ||
} | ||
|
||
@Override | ||
public void doRender(HSSoul entity, double x, double y, double z, float entityYaw, float partialTicks) | ||
{ | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.enableNormalize(); | ||
GlStateManager.enableBlend(); | ||
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); | ||
GlStateManager.color(0.1F, 0.9F, 1.0F, 0.5F); | ||
GlStateManager.translate((float) x, (float) y, (float) z); | ||
this.bindTexture(SOUL_TEXTURES); | ||
if (this.renderOutlines) | ||
{ | ||
GlStateManager.enableColorMaterial(); | ||
GlStateManager.enableOutlineMode(this.getTeamColor(entity)); | ||
} | ||
float ticks = entity.ticksExisted + partialTicks; | ||
float rotation = (ticks) * 2.0F; | ||
GlStateManager.translate(x, y + Math.sin(ticks / 5.0F) * 0.1F + 0.2F, z); | ||
GlStateManager.rotate(rotation, 0, 1, 0); | ||
this.modelSoul.render(entity, 0.0F, 3.0F, 0.2F, 0.0F, 0.0F, 0.0625F); | ||
if (this.renderOutlines) | ||
{ | ||
GlStateManager.disableOutlineMode(); | ||
GlStateManager.disableColorMaterial(); | ||
} | ||
GlStateManager.disableBlend(); | ||
GlStateManager.disableNormalize(); | ||
GlStateManager.popMatrix(); | ||
super.doRender(entity, x, y, z, entityYaw, partialTicks); | ||
} | ||
|
||
@Override | ||
protected ResourceLocation getEntityTexture(HSSoul entity) | ||
{ | ||
return SOUL_TEXTURES; | ||
} | ||
|
||
public static class Factory implements IRenderFactory<HSSoul> | ||
{ | ||
@Override | ||
public Render<? super HSSoul> createRenderFor(RenderManager manager) | ||
{ | ||
return new HSSoulRender(manager); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package mod.emt.harkenscythe.events; | ||
|
||
import mod.emt.harkenscythe.HarkenScythe; | ||
import mod.emt.harkenscythe.entities.HSSoul; | ||
import mod.emt.harkenscythe.items.HSScythe; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.event.entity.living.LivingDeathEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
|
||
@Mod.EventBusSubscriber(modid = HarkenScythe.MOD_ID) | ||
public class HSLivingDeathEvent | ||
{ | ||
@SubscribeEvent | ||
public static void onEntityDeath(LivingDeathEvent event) | ||
{ | ||
EntityLivingBase entity = event.getEntityLiving(); | ||
World world = entity.getEntityWorld(); | ||
if (!world.isRemote && event.getSource().getTrueSource() instanceof EntityPlayer) | ||
{ | ||
EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource(); | ||
if (player.getHeldItemMainhand().getItem() instanceof HSScythe) | ||
{ | ||
HSSoul soul = new HSSoul(world); | ||
soul.setPosition(entity.posX, entity.posY, entity.posZ); | ||
world.spawnEntity(soul); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters