From ea0e02b340e2d88c5f0eac133c696a146ff1a344 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:09:40 +0200 Subject: [PATCH] Finish blood system --- .../emt/harkenscythe/blocks/HSBloodAltar.java | 113 +++++++ .../emt/harkenscythe/blocks/HSSoulAltar.java | 18 +- ...lHSSoul.java => ModelHSEntityEssence.java} | 4 +- .../client/renderers/RenderHSBloodAltar.java | 137 +++++++++ .../client/renderers/RenderHSEntityBlood.java | 56 ++++ ...derHSSoul.java => RenderHSEntitySoul.java} | 12 +- .../client/renderers/RenderHSSoulAltar.java | 6 +- .../harkenscythe/entities/HSEntityBlood.java | 44 ++- .../harkenscythe/entities/HSEntitySoul.java | 44 ++- .../events/HSLivingDeathEvent.java | 10 +- .../events/HSLivingHurtEvent.java | 34 +++ .../emt/harkenscythe/init/HSAltarRecipes.java | 56 ++++ .../mod/emt/harkenscythe/init/HSBlocks.java | 8 +- .../mod/emt/harkenscythe/init/HSRegistry.java | 36 ++- .../harkenscythe/init/HSSoulAltarRecipes.java | 33 -- .../tileentities/HSTileEntityBloodAltar.java | 286 ++++++++++++++++++ ...ltarTE.java => HSTileEntitySoulAltar.java} | 6 +- .../harkenscythe/blockstates/blood_altar.json | 20 ++ .../assets/harkenscythe/lang/en_us.lang | 5 + .../harkenscythe/recipes/blood_altar.json | 24 ++ .../textures/blocks/blood_altar_bottom.png | Bin 0 -> 772 bytes .../textures/blocks/blood_altar_side.png | Bin 0 -> 692 bytes .../textures/blocks/blood_altar_top.png | Bin 0 -> 748 bytes 23 files changed, 823 insertions(+), 129 deletions(-) create mode 100644 src/main/java/mod/emt/harkenscythe/blocks/HSBloodAltar.java rename src/main/java/mod/emt/harkenscythe/client/models/{ModelHSSoul.java => ModelHSEntityEssence.java} (97%) create mode 100644 src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSBloodAltar.java create mode 100644 src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntityBlood.java rename src/main/java/mod/emt/harkenscythe/client/renderers/{RenderHSSoul.java => RenderHSEntitySoul.java} (81%) create mode 100644 src/main/java/mod/emt/harkenscythe/events/HSLivingHurtEvent.java create mode 100644 src/main/java/mod/emt/harkenscythe/init/HSAltarRecipes.java delete mode 100644 src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java create mode 100644 src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntityBloodAltar.java rename src/main/java/mod/emt/harkenscythe/tileentities/{HSSoulAltarTE.java => HSTileEntitySoulAltar.java} (96%) create mode 100644 src/main/resources/assets/harkenscythe/blockstates/blood_altar.json create mode 100644 src/main/resources/assets/harkenscythe/recipes/blood_altar.json create mode 100644 src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_bottom.png create mode 100644 src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_side.png create mode 100644 src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_top.png diff --git a/src/main/java/mod/emt/harkenscythe/blocks/HSBloodAltar.java b/src/main/java/mod/emt/harkenscythe/blocks/HSBloodAltar.java new file mode 100644 index 0000000..1a269f1 --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/blocks/HSBloodAltar.java @@ -0,0 +1,113 @@ +package mod.emt.harkenscythe.blocks; + +import mod.emt.harkenscythe.init.HSAltarRecipes; +import mod.emt.harkenscythe.init.HSItems; +import mod.emt.harkenscythe.init.HSSoundEvents; +import mod.emt.harkenscythe.tileentities.HSTileEntityBloodAltar; +import net.minecraft.block.BlockEnchantmentTable; +import net.minecraft.block.state.IBlockState; +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.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class HSBloodAltar extends BlockEnchantmentTable +{ + public HSBloodAltar() + { + super(); + } + + @Override + public boolean hasTileEntity(IBlockState state) + { + return true; + } + + @Override + public void breakBlock(World world, BlockPos pos, IBlockState state) + { + TileEntity te = world.getTileEntity(pos); + if (te instanceof HSTileEntityBloodAltar) + { + HSTileEntityBloodAltar altar = (HSTileEntityBloodAltar) te; + altar.dropItem(); + } + super.breakBlock(world, pos, state); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) + { + return new HSTileEntityBloodAltar(); + } + + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) + { + TileEntity te = world.getTileEntity(pos); + if (te instanceof HSTileEntityBloodAltar) + { + HSTileEntityBloodAltar altar = (HSTileEntityBloodAltar) te; + ItemStack heldItem = player.getHeldItem(hand); + + if (heldItem.getItem() == HSItems.harken_athame) + { + if (altar.isValidRecipe()) + { + Item item = altar.getItemStack().getItem(); + int requiredBloods = HSAltarRecipes.getRequiredBlood(altar.getItemStack().getItem()); + altar.decreaseCrucibleLevel(requiredBloods / 10); + altar.getItemStack().shrink(1); + if (!player.world.isRemote) player.world.spawnEntity(new EntityItem(player.world, altar.getPos().getX() + 0.5D, altar.getPos().getY() + 1.5D, altar.getPos().getZ() + 0.5D, new ItemStack(HSAltarRecipes.getOutputBlood(item)))); + player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), HSSoundEvents.BLOCK_BLOOD_ALTAR_ENCHANT, SoundCategory.BLOCKS, 0.8F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); + player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), SoundEvents.ENTITY_ENDEREYE_DEATH, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); + for (int i = 0; i < requiredBloods; i++) + { + player.world.spawnParticle(EnumParticleTypes.SPELL_WITCH, altar.getPos().getX() + 0.5D, altar.getPos().getY() + 2.0D, altar.getPos().getZ() + 0.5D, 0.0D, 0.0D, 0.0D); + } + altar.updateBloodCount(); + altar.updateRecipe(); + return true; + } + } + else if (!heldItem.isEmpty()) + { + ItemStack altarItem = altar.getItemStack(); + if (altarItem.isEmpty()) + { + altar.setItemStack(heldItem.splitStack(1)); + player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); + return true; + } + else if (altarItem.getMaxStackSize() > altarItem.getCount() && ItemStack.areItemsEqual(altarItem, heldItem) && ItemStack.areItemStackTagsEqual(altarItem, heldItem)) + { + heldItem.shrink(1); + player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); + altarItem.grow(1); + return true; + } + } + else + { + ItemStack itemStack = altar.getItemStack(); + if (!itemStack.isEmpty()) + { + player.addItemStackToInventory(itemStack); + player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), SoundEvents.ENTITY_ENDEREYE_DEATH, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); + altar.setItemStack(ItemStack.EMPTY); + return true; + } + } + } + return false; + } +} diff --git a/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java b/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java index e997c9e..37f88da 100644 --- a/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java +++ b/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java @@ -1,9 +1,9 @@ package mod.emt.harkenscythe.blocks; +import mod.emt.harkenscythe.init.HSAltarRecipes; import mod.emt.harkenscythe.init.HSItems; -import mod.emt.harkenscythe.init.HSSoulAltarRecipes; import mod.emt.harkenscythe.init.HSSoundEvents; -import mod.emt.harkenscythe.tileentities.HSSoulAltarTE; +import mod.emt.harkenscythe.tileentities.HSTileEntitySoulAltar; import net.minecraft.block.BlockEnchantmentTable; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; @@ -36,9 +36,9 @@ public boolean hasTileEntity(IBlockState state) public void breakBlock(World world, BlockPos pos, IBlockState state) { TileEntity te = world.getTileEntity(pos); - if (te instanceof HSSoulAltarTE) + if (te instanceof HSTileEntitySoulAltar) { - HSSoulAltarTE altar = (HSSoulAltarTE) te; + HSTileEntitySoulAltar altar = (HSTileEntitySoulAltar) te; altar.dropItem(); } super.breakBlock(world, pos, state); @@ -47,16 +47,16 @@ public void breakBlock(World world, BlockPos pos, IBlockState state) @Override public TileEntity createNewTileEntity(World worldIn, int meta) { - return new HSSoulAltarTE(); + return new HSTileEntitySoulAltar(); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntity te = world.getTileEntity(pos); - if (te instanceof HSSoulAltarTE) + if (te instanceof HSTileEntitySoulAltar) { - HSSoulAltarTE altar = (HSSoulAltarTE) te; + HSTileEntitySoulAltar altar = (HSTileEntitySoulAltar) te; ItemStack heldItem = player.getHeldItem(hand); if (heldItem.getItem() == HSItems.harken_athame) @@ -64,10 +64,10 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En if (altar.isValidRecipe()) { Item item = altar.getItemStack().getItem(); - int requiredSouls = HSSoulAltarRecipes.getRequiredSouls(altar.getItemStack().getItem()); + int requiredSouls = HSAltarRecipes.getRequiredSouls(altar.getItemStack().getItem()); altar.decreaseCrucibleLevel(requiredSouls / 10); altar.getItemStack().shrink(1); - if (!player.world.isRemote) player.world.spawnEntity(new EntityItem(player.world, altar.getPos().getX() + 0.5D, altar.getPos().getY() + 1.5D, altar.getPos().getZ() + 0.5D, new ItemStack(HSSoulAltarRecipes.getOutput(item)))); + if (!player.world.isRemote) player.world.spawnEntity(new EntityItem(player.world, altar.getPos().getX() + 0.5D, altar.getPos().getY() + 1.5D, altar.getPos().getZ() + 0.5D, new ItemStack(HSAltarRecipes.getOutputSoul(item)))); player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), HSSoundEvents.BLOCK_SOUL_ALTAR_ENCHANT, SoundCategory.BLOCKS, 0.8F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); player.world.playSound(altar.getPos().getX(), altar.getPos().getY(), altar.getPos().getZ(), SoundEvents.ENTITY_ENDEREYE_DEATH, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false); for (int i = 0; i < requiredSouls; i++) diff --git a/src/main/java/mod/emt/harkenscythe/client/models/ModelHSSoul.java b/src/main/java/mod/emt/harkenscythe/client/models/ModelHSEntityEssence.java similarity index 97% rename from src/main/java/mod/emt/harkenscythe/client/models/ModelHSSoul.java rename to src/main/java/mod/emt/harkenscythe/client/models/ModelHSEntityEssence.java index 9e954b9..8fca31d 100644 --- a/src/main/java/mod/emt/harkenscythe/client/models/ModelHSSoul.java +++ b/src/main/java/mod/emt/harkenscythe/client/models/ModelHSEntityEssence.java @@ -10,12 +10,12 @@ import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) -public class ModelHSSoul extends ModelBase +public class ModelHSEntityEssence extends ModelBase { private final ModelRenderer cube; private final ModelRenderer glass = new ModelRenderer(this, "glass"); - public ModelHSSoul() + public ModelHSEntityEssence() { this.glass.setTextureOffset(0, 0).addBox(-4.0F, -4.0F, -4.0F, 8, 8, 8); this.cube = new ModelRenderer(this, "cube"); diff --git a/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSBloodAltar.java b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSBloodAltar.java new file mode 100644 index 0000000..6e15a3e --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSBloodAltar.java @@ -0,0 +1,137 @@ +package mod.emt.harkenscythe.client.renderers; + +import mod.emt.harkenscythe.HarkenScythe; +import mod.emt.harkenscythe.tileentities.HSTileEntityBloodAltar; +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBook; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.RenderItem; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderHSBloodAltar extends TileEntitySpecialRenderer +{ + private static final ResourceLocation TEXTURE_BOOK = new ResourceLocation(HarkenScythe.MOD_ID, "textures/entities/blood_altar_book.png"); + private final ModelBook modelBook = new ModelBook(); + + @Override + public void render(HSTileEntityBloodAltar te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) + { + GlStateManager.pushMatrix(); + RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); + World world = te.getWorld(); + //noinspection ConstantConditions + if (world == null) return; + + GlStateManager.pushAttrib(); + GlStateManager.disableLighting(); + GlStateManager.translate(x, y, z); + + GlStateManager.pushMatrix(); + float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL); + GlStateManager.translate(0.20, 0.25, 0.25); + RenderHelper.enableStandardItemLighting(); + GlStateManager.pushAttrib(); + + ItemStack stack = te.getItemStack(); + if (!stack.isEmpty()) + { + GlStateManager.pushMatrix(); + GlStateManager.translate(0.25, 1.75, 0.25); + GlStateManager.rotate(timeD, 0, 1, 0); + renderItem.renderItem(stack, ItemCameraTransforms.TransformType.FIXED); + GlStateManager.popMatrix(); + } + + RenderHelper.disableStandardItemLighting(); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + + GlStateManager.pushMatrix(); + GlStateManager.translate((float) x + 0.5F, (float) y + 0.75F, (float) z + 0.5F); + float f = (float) te.tickCount + partialTicks; + GlStateManager.translate(0.0F, 0.1F + MathHelper.sin(f * 0.1F) * 0.01F, 0.0F); + float f1; + + for (f1 = te.bookRotation - te.bookRotationPrev; f1 >= (float) Math.PI; f1 -= ((float) Math.PI * 2F)) {} + + while (f1 < -(float) Math.PI) + { + f1 += ((float) Math.PI * 2F); + } + + float f2 = te.bookRotationPrev + f1 * partialTicks; + GlStateManager.rotate(-f2 * (180F / (float) Math.PI), 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(80.0F, 0.0F, 0.0F, 1.0F); + this.bindTexture(TEXTURE_BOOK); + float f3 = te.pageFlipPrev + (te.pageFlip - te.pageFlipPrev) * partialTicks + 0.25F; + float f4 = te.pageFlipPrev + (te.pageFlip - te.pageFlipPrev) * partialTicks + 0.75F; + f3 = (f3 - (float) MathHelper.fastFloor(f3)) * 1.6F - 0.3F; + f4 = (f4 - (float) MathHelper.fastFloor(f4)) * 1.6F - 0.3F; + + if (f3 < 0.0F) + { + f3 = 0.0F; + } + + if (f4 < 0.0F) + { + f4 = 0.0F; + } + + if (f3 > 1.0F) + { + f3 = 1.0F; + } + + if (f4 > 1.0F) + { + f4 = 1.0F; + } + + float f5 = te.bookSpreadPrev + (te.bookSpread - te.bookSpreadPrev) * partialTicks; + GlStateManager.enableCull(); + this.modelBook.render(null, f, f3, f4, f5, 0.0F, 0.0625F); + GlStateManager.popMatrix(); + + if (!stack.isEmpty()) + { + int textColor = te.isValidRecipe() ? 0x00FF00 : 0xFFFFFF; + + // Display blood count + String bloodText = "Blood: " + te.getBloodCount(); + GlStateManager.pushMatrix(); + GlStateManager.translate(x + 0.5, y + 1.5, z + 0.5); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0, 1, 0); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1, 0, 0); + GlStateManager.scale(-0.025f, -0.025f, 0.025f); + GlStateManager.disableLighting(); + Minecraft.getMinecraft().fontRenderer.drawString(bloodText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(bloodText) / 2, 0, textColor); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + // Display input stack count + String stackText = String.valueOf(stack.getCount()); + GlStateManager.pushMatrix(); + GlStateManager.translate(x + 0.5, y + 2.7, z + 0.5); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0, 1, 0); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1, 0, 0); + GlStateManager.scale(-0.025f, -0.025f, 0.025f); + GlStateManager.disableLighting(); + Minecraft.getMinecraft().fontRenderer.drawString(stackText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(stackText) / 2, 0, textColor); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + } + } +} diff --git a/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntityBlood.java b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntityBlood.java new file mode 100644 index 0000000..54a4563 --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntityBlood.java @@ -0,0 +1,56 @@ +package mod.emt.harkenscythe.client.renderers; + +import mod.emt.harkenscythe.HarkenScythe; +import mod.emt.harkenscythe.client.models.ModelHSEntityEssence; +import mod.emt.harkenscythe.entities.HSEntityBlood; +import net.minecraft.client.model.ModelBase; +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.minecraft.util.math.MathHelper; +import net.minecraftforge.fml.client.registry.IRenderFactory; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderHSEntityBlood extends Render +{ + private static final ResourceLocation BLOOD_TEXTURES = new ResourceLocation(HarkenScythe.MOD_ID, "textures/entities/blood_common.png"); + private final ModelBase modelEssence = new ModelHSEntityEssence(); + + public RenderHSEntityBlood(RenderManager renderManagerIn) + { + super(renderManagerIn); + this.shadowSize = 0.0F; + } + + @Override + public void doRender(HSEntityBlood entity, double x, double y, double z, float entityYaw, float partialTicks) + { + float f = (float) entity.getInnerRotation() + partialTicks; + GlStateManager.pushMatrix(); + GlStateManager.translate((float) x, (float) y, (float) z); + this.bindTexture(BLOOD_TEXTURES); + float f1 = MathHelper.sin(f * 0.2F) / 2.0F + 0.5F; + f1 = f1 * f1 + f1; + this.modelEssence.render(entity, 0.0F, f * 3.0F, f1 * 0.2F, 0.0F, 0.0F, 0.0625F); + GlStateManager.popMatrix(); + super.doRender(entity, x, y, z, entityYaw, partialTicks); + } + + @Override + protected ResourceLocation getEntityTexture(HSEntityBlood entity) + { + return BLOOD_TEXTURES; + } + + public static class Factory implements IRenderFactory + { + @Override + public Render createRenderFor(RenderManager manager) + { + return new RenderHSEntityBlood(manager); + } + } +} diff --git a/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoul.java b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntitySoul.java similarity index 81% rename from src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoul.java rename to src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntitySoul.java index 5f58167..656ba3e 100644 --- a/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoul.java +++ b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSEntitySoul.java @@ -1,7 +1,7 @@ package mod.emt.harkenscythe.client.renderers; import mod.emt.harkenscythe.HarkenScythe; -import mod.emt.harkenscythe.client.models.ModelHSSoul; +import mod.emt.harkenscythe.client.models.ModelHSEntityEssence; import mod.emt.harkenscythe.entities.HSEntitySoul; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; @@ -14,12 +14,12 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) -public class RenderHSSoul extends Render +public class RenderHSEntitySoul extends Render { private static final ResourceLocation SOUL_TEXTURES = new ResourceLocation(HarkenScythe.MOD_ID, "textures/entities/soul_common.png"); - private final ModelBase modelSoul = new ModelHSSoul(); + private final ModelBase modelEssence = new ModelHSEntityEssence(); - public RenderHSSoul(RenderManager renderManagerIn) + public RenderHSEntitySoul(RenderManager renderManagerIn) { super(renderManagerIn); this.shadowSize = 0.0F; @@ -34,7 +34,7 @@ public void doRender(HSEntitySoul entity, double x, double y, double z, float en this.bindTexture(SOUL_TEXTURES); float f1 = MathHelper.sin(f * 0.2F) / 2.0F + 0.5F; f1 = f1 * f1 + f1; - this.modelSoul.render(entity, 0.0F, f * 3.0F, f1 * 0.2F, 0.0F, 0.0F, 0.0625F); + this.modelEssence.render(entity, 0.0F, f * 3.0F, f1 * 0.2F, 0.0F, 0.0F, 0.0625F); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); } @@ -50,7 +50,7 @@ public static class Factory implements IRenderFactory @Override public Render createRenderFor(RenderManager manager) { - return new RenderHSSoul(manager); + return new RenderHSEntitySoul(manager); } } } diff --git a/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoulAltar.java b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoulAltar.java index 6e48057..74e9148 100644 --- a/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoulAltar.java +++ b/src/main/java/mod/emt/harkenscythe/client/renderers/RenderHSSoulAltar.java @@ -1,7 +1,7 @@ package mod.emt.harkenscythe.client.renderers; import mod.emt.harkenscythe.HarkenScythe; -import mod.emt.harkenscythe.tileentities.HSSoulAltarTE; +import mod.emt.harkenscythe.tileentities.HSTileEntitySoulAltar; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBook; import net.minecraft.client.renderer.GlStateManager; @@ -17,13 +17,13 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) -public class RenderHSSoulAltar extends TileEntitySpecialRenderer +public class RenderHSSoulAltar extends TileEntitySpecialRenderer { private static final ResourceLocation TEXTURE_BOOK = new ResourceLocation(HarkenScythe.MOD_ID, "textures/entities/soul_altar_book.png"); private final ModelBook modelBook = new ModelBook(); @Override - public void render(HSSoulAltarTE te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) + public void render(HSTileEntitySoulAltar te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { GlStateManager.pushMatrix(); RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); diff --git a/src/main/java/mod/emt/harkenscythe/entities/HSEntityBlood.java b/src/main/java/mod/emt/harkenscythe/entities/HSEntityBlood.java index f6383a8..533eb1a 100644 --- a/src/main/java/mod/emt/harkenscythe/entities/HSEntityBlood.java +++ b/src/main/java/mod/emt/harkenscythe/entities/HSEntityBlood.java @@ -1,7 +1,6 @@ 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; @@ -23,31 +22,28 @@ public boolean processInitialInteract(EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); Item item = stack.getItem(); - if (item instanceof HSEssenceKeeper) + if (item == HSItems.essence_keeper || item == HSItems.essence_vessel) { - if (!player.capabilities.isCreativeMode) + 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); + 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(); + } + 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) { - 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); - } - } + 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); diff --git a/src/main/java/mod/emt/harkenscythe/entities/HSEntitySoul.java b/src/main/java/mod/emt/harkenscythe/entities/HSEntitySoul.java index b570d78..2c7d8eb 100644 --- a/src/main/java/mod/emt/harkenscythe/entities/HSEntitySoul.java +++ b/src/main/java/mod/emt/harkenscythe/entities/HSEntitySoul.java @@ -1,7 +1,6 @@ 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; @@ -23,31 +22,28 @@ public boolean processInitialInteract(EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); Item item = stack.getItem(); - if (item instanceof HSEssenceKeeper) + if (item == HSItems.essence_keeper || item == HSItems.essence_vessel) { - if (!player.capabilities.isCreativeMode) + 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); + 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(); + } + 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) { - 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); - } - } + 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); diff --git a/src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java b/src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java index 01d32e9..6c1de85 100644 --- a/src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java +++ b/src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java @@ -1,9 +1,7 @@ package mod.emt.harkenscythe.events; import mod.emt.harkenscythe.HarkenScythe; -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; @@ -25,13 +23,7 @@ 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 HSGlaive) - { - HSEntityBlood blood = new HSEntityBlood(world); - blood.setPosition(entity.posX, entity.posY, entity.posZ); - world.spawnEntity(blood); - } - else if (player.getHeldItemMainhand().getItem() instanceof HSScythe) + if (player.getHeldItemMainhand().getItem() instanceof HSScythe) { HSEntitySoul soul = new HSEntitySoul(world); soul.setPosition(entity.posX, entity.posY, entity.posZ); diff --git a/src/main/java/mod/emt/harkenscythe/events/HSLivingHurtEvent.java b/src/main/java/mod/emt/harkenscythe/events/HSLivingHurtEvent.java new file mode 100644 index 0000000..a323685 --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/events/HSLivingHurtEvent.java @@ -0,0 +1,34 @@ +package mod.emt.harkenscythe.events; + +import mod.emt.harkenscythe.HarkenScythe; +import mod.emt.harkenscythe.entities.HSEntityBlood; +import mod.emt.harkenscythe.items.tools.HSGlaive; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = HarkenScythe.MOD_ID) +public class HSLivingHurtEvent +{ + @SubscribeEvent + public static void onEntityHurt(LivingHurtEvent event) + { + EntityLivingBase entity = event.getEntityLiving(); + World world = entity.getEntityWorld(); + DamageSource damageSource = event.getSource(); + if (!world.isRemote && damageSource.getTrueSource() instanceof EntityPlayer && damageSource.getDamageType().equals("hs_reap")) + { + EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource(); + if (player.getHeldItemMainhand().getItem() instanceof HSGlaive) + { + HSEntityBlood blood = new HSEntityBlood(world); + blood.setPosition(entity.posX, entity.posY, entity.posZ); + world.spawnEntity(blood); + } + } + } +} diff --git a/src/main/java/mod/emt/harkenscythe/init/HSAltarRecipes.java b/src/main/java/mod/emt/harkenscythe/init/HSAltarRecipes.java new file mode 100644 index 0000000..922b8fd --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/init/HSAltarRecipes.java @@ -0,0 +1,56 @@ +package mod.emt.harkenscythe.init; + +import java.util.Map; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.item.Item; + +public class HSAltarRecipes +{ + private static final Map BLOOD_INPUT_OUTPUT_MAP = new Object2ObjectOpenHashMap<>(); + private static final Map BLOOD_INPUT_BLOODCOUNT_MAP = new Object2IntOpenHashMap<>(); + private static final Map SOUL_INPUT_OUTPUT_MAP = new Object2ObjectOpenHashMap<>(); + private static final Map SOUL_INPUT_SOULCOUNT_MAP = new Object2IntOpenHashMap<>(); + + public static void addBloodRecipe(Item input, Item output, int requiredBlood) + { + BLOOD_INPUT_OUTPUT_MAP.put(input, output); + BLOOD_INPUT_BLOODCOUNT_MAP.put(input, Math.max(requiredBlood, 10)); + } + + public static boolean isValidInputBlood(Item input) + { + return BLOOD_INPUT_OUTPUT_MAP.containsKey(input) && BLOOD_INPUT_BLOODCOUNT_MAP.containsKey(input); + } + + public static Item getOutputBlood(Item input) + { + return BLOOD_INPUT_OUTPUT_MAP.get(input); + } + + public static int getRequiredBlood(Item input) + { + return BLOOD_INPUT_BLOODCOUNT_MAP.get(input); + } + + public static void addSoulRecipe(Item input, Item output, int requiredSouls) + { + SOUL_INPUT_OUTPUT_MAP.put(input, output); + SOUL_INPUT_SOULCOUNT_MAP.put(input, Math.max(requiredSouls, 10)); + } + + public static boolean isValidInputSoul(Item input) + { + return SOUL_INPUT_OUTPUT_MAP.containsKey(input) && SOUL_INPUT_SOULCOUNT_MAP.containsKey(input); + } + + public static Item getOutputSoul(Item input) + { + return SOUL_INPUT_OUTPUT_MAP.get(input); + } + + public static int getRequiredSouls(Item input) + { + return SOUL_INPUT_SOULCOUNT_MAP.get(input); + } +} diff --git a/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java b/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java index 335523f..a24ae55 100644 --- a/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java +++ b/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java @@ -5,6 +5,7 @@ import mod.emt.harkenscythe.blocks.HSBlockCloth; import mod.emt.harkenscythe.blocks.HSBlockCreep; import mod.emt.harkenscythe.blocks.HSBlockMaterial; +import mod.emt.harkenscythe.blocks.HSBloodAltar; import mod.emt.harkenscythe.blocks.HSBloodCrucible; import mod.emt.harkenscythe.blocks.HSSoulAltar; import mod.emt.harkenscythe.blocks.HSSoulCake; @@ -37,12 +38,14 @@ public class HSBlocks @GameRegistry.ObjectHolder("soulweave_cloth") public static HSBlockCloth soulweave_cloth; + @GameRegistry.ObjectHolder("blood_altar") + public static HSBloodAltar blood_altar; + @GameRegistry.ObjectHolder("soul_altar") + public static HSSoulAltar soul_altar; @GameRegistry.ObjectHolder("blood_crucible") public static HSBloodCrucible blood_crucible; @GameRegistry.ObjectHolder("soul_crucible") public static HSSoulCrucible soul_crucible; - @GameRegistry.ObjectHolder("soul_altar") - public static HSSoulAltar soul_altar; @GameRegistry.ObjectHolder("soul_cake") public static HSSoulCake soul_cake; @@ -62,6 +65,7 @@ public static void onRegisterBlocksEvent(@Nonnull final RegistryEvent.Register event) { int id = 1; event.getRegistry().registerAll( - 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() + EntityEntryBuilder.create().entity(HSEntityBlood.class).id(new ResourceLocation(HarkenScythe.MOD_ID, "blood"), id++).name(HarkenScythe.MOD_ID + ".blood").tracker(64, 1, true).build(), + EntityEntryBuilder.create().entity(HSEntitySoul.class).id(new ResourceLocation(HarkenScythe.MOD_ID, "soul"), id++).name(HarkenScythe.MOD_ID + ".soul").tracker(64, 1, true).build() ); } public static void registerTileEntities() { - GameRegistry.registerTileEntity(HSSoulAltarTE.class, new ResourceLocation(HarkenScythe.MOD_ID, "soul_altar")); + GameRegistry.registerTileEntity(HSTileEntityBloodAltar.class, new ResourceLocation(HarkenScythe.MOD_ID, "blood_altar")); + GameRegistry.registerTileEntity(HSTileEntitySoulAltar.class, new ResourceLocation(HarkenScythe.MOD_ID, "soul_altar")); } public static void registerRecipes() { - HSSoulAltarRecipes.addRecipe(Items.CAKE, HSItems.soul_cake, 10); - HSSoulAltarRecipes.addRecipe(Items.COOKIE, HSItems.soul_cookie, 10); - HSSoulAltarRecipes.addRecipe(Items.GLASS_BOTTLE, Items.EXPERIENCE_BOTTLE, 20); - HSSoulAltarRecipes.addRecipe(Items.IRON_INGOT, HSItems.livingmetal_ingot, 10); - HSSoulAltarRecipes.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER).getItem(), Items.DRAGON_BREATH, 30); // TODO: Move this to blood - HSSoulAltarRecipes.addRecipe(new ItemStack(Blocks.SAND).getItem(), new ItemStack(Blocks.SOUL_SAND).getItem(), 10); // TODO: OreDictionary - HSSoulAltarRecipes.addRecipe(new ItemStack(Blocks.WOOL).getItem(), new ItemStack(HSBlocks.soulweave_cloth).getItem(), 10); // TODO: OreDictionary + HSAltarRecipes.addBloodRecipe(new ItemStack(Blocks.WOOL).getItem(), new ItemStack(HSBlocks.bloodweave_cloth).getItem(), 10); // TODO: OreDictionary + + HSAltarRecipes.addSoulRecipe(Items.CAKE, HSItems.soul_cake, 10); + HSAltarRecipes.addSoulRecipe(Items.COOKIE, HSItems.soul_cookie, 10); + HSAltarRecipes.addSoulRecipe(Items.GLASS_BOTTLE, Items.EXPERIENCE_BOTTLE, 20); + HSAltarRecipes.addSoulRecipe(Items.IRON_INGOT, HSItems.livingmetal_ingot, 10); + HSAltarRecipes.addSoulRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER).getItem(), Items.DRAGON_BREATH, 30); // TODO: Move this to blood + HSAltarRecipes.addSoulRecipe(new ItemStack(Blocks.SAND).getItem(), new ItemStack(Blocks.SOUL_SAND).getItem(), 10); // TODO: OreDictionary + HSAltarRecipes.addSoulRecipe(new ItemStack(Blocks.WOOL).getItem(), new ItemStack(HSBlocks.soulweave_cloth).getItem(), 10); // TODO: OreDictionary } @SideOnly(Side.CLIENT) @SubscribeEvent public static void registerEntityRenderers(ModelRegistryEvent event) { - RenderingRegistry.registerEntityRenderingHandler(HSEntitySoul.class, new RenderHSSoul.Factory()); + RenderingRegistry.registerEntityRenderingHandler(HSEntityBlood.class, new RenderHSEntityBlood.Factory()); + RenderingRegistry.registerEntityRenderingHandler(HSEntitySoul.class, new RenderHSEntitySoul.Factory()); } @SideOnly(Side.CLIENT) @SubscribeEvent public static void registerTESRs(RegistryEvent event) { - ClientRegistry.bindTileEntitySpecialRenderer(HSSoulAltarTE.class, new RenderHSSoulAltar()); + ClientRegistry.bindTileEntitySpecialRenderer(HSTileEntityBloodAltar.class, new RenderHSBloodAltar()); + ClientRegistry.bindTileEntitySpecialRenderer(HSTileEntitySoulAltar.class, new RenderHSSoulAltar()); } } diff --git a/src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java b/src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java deleted file mode 100644 index dfe266e..0000000 --- a/src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java +++ /dev/null @@ -1,33 +0,0 @@ -package mod.emt.harkenscythe.init; - -import java.util.Map; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import net.minecraft.item.Item; - -public class HSSoulAltarRecipes -{ - private static final Map SOUL_INPUT_OUTPUT_MAP = new Object2ObjectOpenHashMap<>(); - private static final Map SOUL_INPUT_SOULS_MAP = new Object2IntOpenHashMap<>(); - - public static void addRecipe(Item input, Item output, int requiredSouls) - { - SOUL_INPUT_OUTPUT_MAP.put(input, output); - SOUL_INPUT_SOULS_MAP.put(input, Math.max(requiredSouls, 10)); - } - - public static boolean isValidInput(Item input) - { - return SOUL_INPUT_OUTPUT_MAP.containsKey(input) && SOUL_INPUT_SOULS_MAP.containsKey(input); - } - - public static Item getOutput(Item input) - { - return SOUL_INPUT_OUTPUT_MAP.get(input); - } - - public static int getRequiredSouls(Item input) - { - return SOUL_INPUT_SOULS_MAP.get(input); - } -} diff --git a/src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntityBloodAltar.java b/src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntityBloodAltar.java new file mode 100644 index 0000000..ebf5bf4 --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntityBloodAltar.java @@ -0,0 +1,286 @@ +package mod.emt.harkenscythe.tileentities; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import mod.emt.harkenscythe.blocks.HSBloodCrucible; +import mod.emt.harkenscythe.init.HSAltarRecipes; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +public class HSTileEntityBloodAltar extends TileEntity implements ITickable +{ + private static final Random rand = new Random(); + private static final int RADIUS = 4; + public int tickCount; + public float pageFlip; + public float pageFlipPrev; + public float flipT; + public float flipA; + public float bookSpread; + public float bookSpreadPrev; + public float bookRotation; + public float bookRotationPrev; + public float tRot; + private int bloodCount; + private boolean validRecipe; + private ItemStack itemStack = ItemStack.EMPTY; + + public int getBloodCount() + { + return bloodCount; + } + + public boolean isValidRecipe() + { + return validRecipe; + } + + public ItemStack getItemStack() + { + return itemStack; + } + + public void setItemStack(ItemStack itemStack) + { + this.itemStack = itemStack; + markDirty(); + } + + public void dropItem() + { + if (!world.isRemote && !itemStack.isEmpty()) + { + BlockPos pos = getPos(); + EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), itemStack); + world.spawnEntity(entityItem); + setItemStack(ItemStack.EMPTY); + } + } + + @Override + public void readFromNBT(NBTTagCompound compound) + { + super.readFromNBT(compound); + if (compound.hasKey("Item")) + { + itemStack = new ItemStack(compound.getCompoundTag("Item")); + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) + { + super.writeToNBT(compound); + if (!itemStack.isEmpty()) + { + NBTTagCompound itemTag = new NBTTagCompound(); + itemStack.writeToNBT(itemTag); + compound.setTag("Item", itemTag); + } + return compound; + } + + @Override + public SPacketUpdateTileEntity getUpdatePacket() + { + NBTTagCompound nbtTag = new NBTTagCompound(); + writeToNBT(nbtTag); + return new SPacketUpdateTileEntity(getPos(), 1, nbtTag); + } + + @Override + public NBTTagCompound getUpdateTag() + { + return writeToNBT(new NBTTagCompound()); + } + + @Override + public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) + { + readFromNBT(pkt.getNbtCompound()); + } + + @Override + public void handleUpdateTag(NBTTagCompound tag) + { + readFromNBT(tag); + } + + @Override + public void update() + { + this.bookSpreadPrev = this.bookSpread; + this.bookRotationPrev = this.bookRotation; + EntityPlayer entityplayer = this.world.getClosestPlayer((float) this.pos.getX() + 0.5F, (float) this.pos.getY() + 0.5F, (float) this.pos.getZ() + 0.5F, 3.0D, false); + + if (entityplayer != null) + { + double d0 = entityplayer.posX - (double) ((float) this.pos.getX() + 0.5F); + double d1 = entityplayer.posZ - (double) ((float) this.pos.getZ() + 0.5F); + this.tRot = (float) MathHelper.atan2(d1, d0); + this.bookSpread += 0.1F; + + if (this.bookSpread < 0.5F || rand.nextInt(40) == 0) + { + float f1 = this.flipT; + + do + { + this.flipT += (rand.nextInt(4) - rand.nextInt(4)); + + } while (f1 == this.flipT); + } + } + else + { + this.tRot += 0.02F; + this.bookSpread -= 0.1F; + } + + while (this.bookRotation >= (float) Math.PI) + { + this.bookRotation -= ((float) Math.PI * 2F); + } + + while (this.bookRotation < -(float) Math.PI) + { + this.bookRotation += ((float) Math.PI * 2F); + } + + while (this.tRot >= (float) Math.PI) + { + this.tRot -= ((float) Math.PI * 2F); + } + + while (this.tRot < -(float) Math.PI) + { + this.tRot += ((float) Math.PI * 2F); + } + + float f2; + + for (f2 = this.tRot - this.bookRotation; f2 >= (float) Math.PI; f2 -= ((float) Math.PI * 2F)) + { + } + + while (f2 < -(float) Math.PI) + { + f2 += ((float) Math.PI * 2F); + } + + this.bookRotation += f2 * 0.4F; + this.bookSpread = MathHelper.clamp(this.bookSpread, 0.0F, 1.0F); + ++this.tickCount; + this.pageFlipPrev = this.pageFlip; + float f = (this.flipT - this.pageFlip) * 0.4F; + f = MathHelper.clamp(f, -0.2F, 0.2F); + this.flipA += (f - this.flipA) * 0.9F; + this.pageFlip += this.flipA; + + if (this.world.getWorldTime() % 20 == 19 && !this.getItemStack().isEmpty()) + { + updateBloodCount(); + updateRecipe(); + } + } + + public void updateBloodCount() + { + this.bloodCount = scanCrucibleLevels() * 10; + } + + public void updateRecipe() + { + this.validRecipe = HSAltarRecipes.isValidInputBlood(this.getItemStack().getItem()) && HSAltarRecipes.getRequiredBlood(this.getItemStack().getItem()) <= this.bloodCount; + } + + public int scanCrucibleLevels() + { + int totalLevel = 0; + BlockPos pos = this.getPos(); + World world = this.getWorld(); + + for (int dx = -RADIUS; dx <= RADIUS; dx++) + { + for (int dy = -RADIUS; dy <= RADIUS; dy++) + { + for (int dz = -RADIUS; dz <= RADIUS; dz++) + { + BlockPos checkPos = pos.add(dx, dy, dz); + IBlockState state = world.getBlockState(checkPos); + + if (state.getBlock() instanceof HSBloodCrucible) + { + int level = state.getValue(HSBloodCrucible.LEVEL); + totalLevel += level; + } + } + } + } + + return totalLevel; + } + + public void decreaseCrucibleLevel(int levelToDecrease) + { + World world = this.getWorld(); + if (world.isRemote) return; + + BlockPos pos = this.getPos(); + List cruciblePositions = new ArrayList<>(); + + for (int dx = -RADIUS; dx <= RADIUS; dx++) + { + for (int dy = -RADIUS; dy <= RADIUS; dy++) + { + for (int dz = -RADIUS; dz <= RADIUS; dz++) + { + BlockPos checkPos = pos.add(dx, dy, dz); + IBlockState state = world.getBlockState(checkPos); + + if (state.getBlock() instanceof HSBloodCrucible) + { + cruciblePositions.add(checkPos); + } + } + } + } + + int remainingLevelToDecrease = levelToDecrease; + + while (remainingLevelToDecrease > 0 && !cruciblePositions.isEmpty()) + { + BlockPos selectedPos = cruciblePositions.get(world.rand.nextInt(cruciblePositions.size())); + IBlockState state = world.getBlockState(selectedPos); + + if (state.getBlock() instanceof HSBloodCrucible) + { + int currentLevel = state.getValue(HSBloodCrucible.LEVEL); + + if (currentLevel >= remainingLevelToDecrease) + { + world.setBlockState(selectedPos, state.withProperty(HSBloodCrucible.LEVEL, currentLevel - remainingLevelToDecrease)); + remainingLevelToDecrease = 0; + } + else + { + world.setBlockState(selectedPos, state.withProperty(HSBloodCrucible.LEVEL, 0)); + remainingLevelToDecrease -= currentLevel; + } + } + + cruciblePositions.remove(selectedPos); + } + } +} diff --git a/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java b/src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntitySoulAltar.java similarity index 96% rename from src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java rename to src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntitySoulAltar.java index 33c1f4d..1f51110 100644 --- a/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java +++ b/src/main/java/mod/emt/harkenscythe/tileentities/HSTileEntitySoulAltar.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.Random; import mod.emt.harkenscythe.blocks.HSSoulCrucible; -import mod.emt.harkenscythe.init.HSSoulAltarRecipes; +import mod.emt.harkenscythe.init.HSAltarRecipes; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -18,7 +18,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -public class HSSoulAltarTE extends TileEntity implements ITickable +public class HSTileEntitySoulAltar extends TileEntity implements ITickable { private static final Random rand = new Random(); private static final int RADIUS = 4; @@ -202,7 +202,7 @@ public void updateSoulCount() public void updateRecipe() { - this.validRecipe = HSSoulAltarRecipes.isValidInput(this.getItemStack().getItem()) && HSSoulAltarRecipes.getRequiredSouls(this.getItemStack().getItem()) <= this.soulCount; + this.validRecipe = HSAltarRecipes.isValidInputSoul(this.getItemStack().getItem()) && HSAltarRecipes.getRequiredSouls(this.getItemStack().getItem()) <= this.soulCount; } public int scanCrucibleLevels() diff --git a/src/main/resources/assets/harkenscythe/blockstates/blood_altar.json b/src/main/resources/assets/harkenscythe/blockstates/blood_altar.json new file mode 100644 index 0000000..e3e517f --- /dev/null +++ b/src/main/resources/assets/harkenscythe/blockstates/blood_altar.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "enchanting_table_base", + "textures": { + "particle": "harkenscythe:blocks/blood_altar_bottom", + "bottom": "harkenscythe:blocks/blood_altar_bottom", + "top": "harkenscythe:blocks/blood_altar_top", + "side": "harkenscythe:blocks/blood_altar_side" + } + }, + "variants": { + "normal": [ + {} + ], + "inventory": [ + {} + ] + } +} diff --git a/src/main/resources/assets/harkenscythe/lang/en_us.lang b/src/main/resources/assets/harkenscythe/lang/en_us.lang index 9ba05db..4343853 100644 --- a/src/main/resources/assets/harkenscythe/lang/en_us.lang +++ b/src/main/resources/assets/harkenscythe/lang/en_us.lang @@ -2,6 +2,7 @@ itemGroup.harkenscythe.tab=Harken Scythe # BLOCKS +tile.harkenscythe.blood_altar.name=Altar of Blood tile.harkenscythe.blood_crucible.name=Blood Crucible tile.harkenscythe.biomass_block.name=Biomass Block tile.harkenscythe.bloodweave_cloth.name=Bloodweave Cloth @@ -68,6 +69,10 @@ item.harkenscythe.stone_scythe.name=Stone Scythe item.harkenscythe.wooden_glaive.name=Wooden Glaive item.harkenscythe.wooden_scythe.name=Wooden Scythe +# ENTITIES +entity.harkenscythe.blood.name=Blood Essence +entity.harkenscythe.soul.name=Soul Essence + # MESSAGES message.harkenscythe.hs_reap=%s was reaped diff --git a/src/main/resources/assets/harkenscythe/recipes/blood_altar.json b/src/main/resources/assets/harkenscythe/recipes/blood_altar.json new file mode 100644 index 0000000..42f555c --- /dev/null +++ b/src/main/resources/assets/harkenscythe/recipes/blood_altar.json @@ -0,0 +1,24 @@ +{ + "type": "forge:ore_shaped", + "pattern": [ + " B ", + "ENE", + "NNN" + ], + "key": { + "B": { + "item": "harkenscythe:carnage_book" + }, + "E": { + "type": "forge:ore_dict", + "ore": "enderpearl" + }, + "N": { + "type": "forge:ore_dict", + "ore": "netherrack" + } + }, + "result": { + "item": "harkenscythe:blood_altar" + } +} diff --git a/src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_bottom.png b/src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..dc6432ef1e807cde5693e2619cd8596982e39b05 GIT binary patch literal 772 zcmV+f1N;1mP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0007WNkldBO_)>4OVIsHnKKXxw$qkw6$u=YPK#~7j13a)ooYZ zv~|({(WA%h-MjC5-{*PWAKyo`E0y=zENmy4Y&VM)zds=e(f)o|!)VmA_X7c34-^I0 z6GDWdHexX=%OZgYpg7zh$*q|g_(hs7d(JM1;(@9Xv!V!9paq`4=5*?+d6IN=cJ{LD z+UO_<118hW;bA{bZzd8%H5?vuxq2A}p%02u3Itx~^M}h>(QKY{H~_t9wW8YBa``F8 z<-A_v@4IzKZcbkU0f*^md+9W~LdTcw_IaQ0JWYeFFA9ecMZGkc2sDFQkblN;SP{nEou9;_zm!V% zWH~MfS6nVnPY=to=fC`I4LlAZ`%%P^?3*qgsZ&cTNz|!#ZwlkTH@o`Ug_fbpe2Zka+ zn=NNMWo8)g0ezdv0DaZrc##N6eSLn5MY3AkmCAqZM%okk)Mgt10000|bx literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_side.png b/src/main/resources/assets/harkenscythe/textures/blocks/blood_altar_side.png new file mode 100644 index 0000000000000000000000000000000000000000..03cbb4f6e3f4e70bfd2d2255e01d318498444552 GIT binary patch literal 692 zcmV;l0!#ggP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0006bNklfBJw14u zPGc*TLY6WA`c0hp`WCiM$=|;QCP}kZRoEOHgyD8$Z(#vH%4OV5CXr;Ub)}%Wwob`K z@Zk4PxXcj3Bzc%w#KT=(xMo?%S6AarK994E2}csyIwco@1cD?yA05S~ViBp%PMq=i zFk_lHNdqz58XMCIY!iX9_;8Fci2L>RsMOVAcPWGInTvRt$>4pVfE&HNNVA&rfdGQd z&1fh0JF!owJMp;ACRy*%VA|n;>G5dsInLtO&IT%p1U{B?dZ0rz`nI-)3GxI=#49cr zUKK9u!4)GB9OVqeK)&s_+p(CQ%~iG}nx)!Wl%i26agDIY*SQ=vxT@(;NE2=0b~dZe z;|&ck$osIks0~CTb5T;dWYYvb$SDSS_AMnQ{C>3ZF1%Y#=U?N8L#K61>PxAF%D@0- z4FjK-m$Axrb|xov&^CJ3*ob%Y^V(1pcQD&BRoMFDMZ4g^mt99*)6kX+eZrvfA3% aRuKo@nN&iK%?Wn^0000Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv00078NklC&$4 zvNff@yVi~VG-*S-%~H_{w&=#z&f4jA7^A{;RS?D$<`55pD0uNG9)<{_XHVWedGg}H zzrnkHYhdU_coN<>`8*Hb=leV)R0~`xB42Jy4z3&%jcT>4b93!<8u7^O{yZ98BT63M zo&WN|CJE1JLYxR3AfPyG2*QiCwF1%X!4QB=5>AMxKYzH)`~s0(bsz`{MF}$YpwU1A zexaOA5>5zwDiXcx_lNcRPOWyQRgFwe=7YhEs#bL!h3p&z{UU<&3q+fSf!ck;K)5+B z9SGbkmj}h-$@X?L64@kLBtlW@h~l%=)!UYZg!75S^29_X8g&UmLDx47VY$6}VQ%Nz$fz}SqU%sL#cY_?k}or^}n^aR0lI>$cZlJWTr zU2nwWrEnOPR8iCvMRqulT#Lsojw@=~vM4@RRe~50(9@G7gXeSMU{;%&4+it0P*_p? zjOiXv*zIPFeLFh({`w)oINSSmNm}H%fGmUdIvn+dc+BhV7+FXyY1-GrLx@L=Cw1U* zoeWnX>{2SF@H|=%dprrhKQ}$y&Sbnizh#=h_8Ggsv@~`qL$pQoxZS>y&*L|`1lmZY zkUt~KMW^%A-X2B)EDc++Czw3uf(ynJlB7m5i7p{b<#|ZGC(F%0gR@D(R$<`wunTO<@0^q-923moBU^6A@5eD0>5icCq(1@e!qA2Kii4~O_CrC=$mdAbSsg# e`1iJ^BEJFgi