diff --git a/src/main/java/mod/emt/harkenscythe/HarkenScythe.java b/src/main/java/mod/emt/harkenscythe/HarkenScythe.java index 2090de3..964c37a 100644 --- a/src/main/java/mod/emt/harkenscythe/HarkenScythe.java +++ b/src/main/java/mod/emt/harkenscythe/HarkenScythe.java @@ -24,6 +24,7 @@ public class HarkenScythe public void init(FMLInitializationEvent event) { HSRegistry.registerTileEntities(); + HSRegistry.registerRecipes(); LOGGER.info(NAME + " initialized"); } } diff --git a/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java b/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java index ee2669e..e997c9e 100644 --- a/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java +++ b/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java @@ -1,14 +1,20 @@ package mod.emt.harkenscythe.blocks; +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 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; @@ -53,12 +59,32 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En HSSoulAltarTE altar = (HSSoulAltarTE) te; ItemStack heldItem = player.getHeldItem(hand); - if (!heldItem.isEmpty()) + if (heldItem.getItem() == HSItems.harken_athame) { - ItemStack altarItem = altar.getItem(); + if (altar.isValidRecipe()) + { + Item item = altar.getItemStack().getItem(); + int requiredSouls = HSSoulAltarRecipes.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)))); + 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++) + { + 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.updateSoulCount(); + altar.updateRecipe(); + return true; + } + } + else if (!heldItem.isEmpty()) + { + ItemStack altarItem = altar.getItemStack(); if (altarItem.isEmpty()) { - altar.setItem(heldItem.splitStack(1)); + 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; } @@ -72,16 +98,16 @@ else if (altarItem.getMaxStackSize() > altarItem.getCount() && ItemStack.areItem } else { - ItemStack itemStack = altar.getItem(); + 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.setItem(ItemStack.EMPTY); + altar.setItemStack(ItemStack.EMPTY); return true; } } } - return true; + return false; } } diff --git a/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java b/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java index 78153ec..5c0a81f 100644 --- a/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java +++ b/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java @@ -40,7 +40,7 @@ public void render(HSSoulAltarTE te, double x, double y, double z, float partial RenderHelper.enableStandardItemLighting(); GlStateManager.pushAttrib(); - ItemStack stack = te.getItem(); + ItemStack stack = te.getItemStack(); if (!stack.isEmpty()) { GlStateManager.pushMatrix(); @@ -57,33 +57,6 @@ public void render(HSSoulAltarTE te, double x, double y, double z, float partial GlStateManager.popAttrib(); GlStateManager.popMatrix(); - if (!stack.isEmpty()) - { - // Display soul count - String soulsText = "Souls: " + te.soulCount; - 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(soulsText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(soulsText) / 2, 0, 0xFFFFFF); - 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, 0xFFFFFF); - GlStateManager.enableLighting(); - GlStateManager.popMatrix(); - } - GlStateManager.pushMatrix(); GlStateManager.translate((float) x + 0.5F, (float) y + 0.75F, (float) z + 0.5F); float f = (float) te.tickCount + partialTicks; @@ -130,5 +103,34 @@ public void render(HSSoulAltarTE te, double x, double y, double z, float partial 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 soul count + String soulsText = "Souls: " + te.getSoulCount(); + 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(soulsText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(soulsText) / 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/init/HSRegistry.java b/src/main/java/mod/emt/harkenscythe/init/HSRegistry.java index 78e7f6d..6fd38a9 100644 --- a/src/main/java/mod/emt/harkenscythe/init/HSRegistry.java +++ b/src/main/java/mod/emt/harkenscythe/init/HSRegistry.java @@ -8,6 +8,7 @@ import mod.emt.harkenscythe.entities.render.HSSoulRender; import mod.emt.harkenscythe.tileentities.HSSoulAltarTE; import net.minecraft.block.Block; +import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; @@ -63,6 +64,11 @@ public static void registerTileEntities() GameRegistry.registerTileEntity(HSSoulAltarTE.class, new ResourceLocation(HarkenScythe.MOD_ID, "soul_altar")); } + public static void registerRecipes() + { + HSSoulAltarRecipes.addRecipe(Items.IRON_INGOT, HSItems.livingmetal_ingot, 10); + } + @SideOnly(Side.CLIENT) @SubscribeEvent public static void registerEntityRenderers(ModelRegistryEvent event) diff --git a/src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java b/src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java new file mode 100644 index 0000000..dfe266e --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/init/HSSoulAltarRecipes.java @@ -0,0 +1,33 @@ +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/init/HSSoundEvents.java b/src/main/java/mod/emt/harkenscythe/init/HSSoundEvents.java index c0aedfe..6063112 100644 --- a/src/main/java/mod/emt/harkenscythe/init/HSSoundEvents.java +++ b/src/main/java/mod/emt/harkenscythe/init/HSSoundEvents.java @@ -8,5 +8,7 @@ @GameRegistry.ObjectHolder(HarkenScythe.MOD_ID) public class HSSoundEvents { + public static final SoundEvent BLOCK_BLOOD_ALTAR_ENCHANT = new SoundEvent(new ResourceLocation(HarkenScythe.MOD_ID, "block.soul_altar.enchant")); + public static final SoundEvent BLOCK_SOUL_ALTAR_ENCHANT = new SoundEvent(new ResourceLocation(HarkenScythe.MOD_ID, "block.blood_altar.enchant")); public static final SoundEvent ITEM_ATHAME_CREATE = new SoundEvent(new ResourceLocation(HarkenScythe.MOD_ID, "item.athame.create")); } diff --git a/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java b/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java index 62e9116..33c1f4d 100644 --- a/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java +++ b/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java @@ -1,7 +1,10 @@ package mod.emt.harkenscythe.tileentities; +import java.util.ArrayList; +import java.util.List; import java.util.Random; import mod.emt.harkenscythe.blocks.HSSoulCrucible; +import mod.emt.harkenscythe.init.HSSoulAltarRecipes; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -29,28 +32,39 @@ public class HSSoulAltarTE extends TileEntity implements ITickable public float bookRotation; public float bookRotationPrev; public float tRot; - public int soulCount; - private ItemStack item = ItemStack.EMPTY; + private int soulCount; + private boolean validRecipe; + private ItemStack itemStack = ItemStack.EMPTY; - public ItemStack getItem() + public int getSoulCount() { - return item; + return soulCount; } - public void setItem(ItemStack item) + public boolean isValidRecipe() { - this.item = item; + return validRecipe; + } + + public ItemStack getItemStack() + { + return itemStack; + } + + public void setItemStack(ItemStack itemStack) + { + this.itemStack = itemStack; markDirty(); } public void dropItem() { - if (!world.isRemote && !item.isEmpty()) + if (!world.isRemote && !itemStack.isEmpty()) { BlockPos pos = getPos(); - EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), item); + EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), itemStack); world.spawnEntity(entityItem); - setItem(ItemStack.EMPTY); + setItemStack(ItemStack.EMPTY); } } @@ -60,7 +74,7 @@ public void readFromNBT(NBTTagCompound compound) super.readFromNBT(compound); if (compound.hasKey("Item")) { - item = new ItemStack(compound.getCompoundTag("Item")); + itemStack = new ItemStack(compound.getCompoundTag("Item")); } } @@ -68,10 +82,10 @@ public void readFromNBT(NBTTagCompound compound) public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); - if (!item.isEmpty()) + if (!itemStack.isEmpty()) { NBTTagCompound itemTag = new NBTTagCompound(); - item.writeToNBT(itemTag); + itemStack.writeToNBT(itemTag); compound.setTag("Item", itemTag); } return compound; @@ -174,12 +188,23 @@ public void update() this.flipA += (f - this.flipA) * 0.9F; this.pageFlip += this.flipA; - if (this.world.getWorldTime() % 20 == 19 && !this.getItem().isEmpty()) + if (this.world.getWorldTime() % 20 == 19 && !this.getItemStack().isEmpty()) { - this.soulCount = scanCrucibleLevels() * 10; + updateSoulCount(); + updateRecipe(); } } + public void updateSoulCount() + { + this.soulCount = scanCrucibleLevels() * 10; + } + + public void updateRecipe() + { + this.validRecipe = HSSoulAltarRecipes.isValidInput(this.getItemStack().getItem()) && HSSoulAltarRecipes.getRequiredSouls(this.getItemStack().getItem()) <= this.soulCount; + } + public int scanCrucibleLevels() { int totalLevel = 0; @@ -206,4 +231,56 @@ public int scanCrucibleLevels() 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 HSSoulCrucible) + { + 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 HSSoulCrucible) + { + int currentLevel = state.getValue(HSSoulCrucible.LEVEL); + + if (currentLevel >= remainingLevelToDecrease) + { + world.setBlockState(selectedPos, state.withProperty(HSSoulCrucible.LEVEL, currentLevel - remainingLevelToDecrease)); + remainingLevelToDecrease = 0; + } + else + { + world.setBlockState(selectedPos, state.withProperty(HSSoulCrucible.LEVEL, 0)); + remainingLevelToDecrease -= currentLevel; + } + } + + cruciblePositions.remove(selectedPos); + } + } } diff --git a/src/main/resources/assets/harkenscythe/sounds.json b/src/main/resources/assets/harkenscythe/sounds.json index fe423c9..d8cccc6 100644 --- a/src/main/resources/assets/harkenscythe/sounds.json +++ b/src/main/resources/assets/harkenscythe/sounds.json @@ -1,4 +1,14 @@ { + "block.soul_altar.enchant": { + "sounds": [ + "harkenscythe:enchant_blood" + ] + }, + "block.blood_altar.enchant": { + "sounds": [ + "harkenscythe:enchant_soul" + ] + }, "item.athame.create": { "sounds": [ "harkenscythe:athame" diff --git a/src/main/resources/assets/harkenscythe/sounds/enchant_blood.ogg b/src/main/resources/assets/harkenscythe/sounds/enchant_blood.ogg new file mode 100644 index 0000000..f8c6d36 Binary files /dev/null and b/src/main/resources/assets/harkenscythe/sounds/enchant_blood.ogg differ diff --git a/src/main/resources/assets/harkenscythe/sounds/enchant_soul.ogg b/src/main/resources/assets/harkenscythe/sounds/enchant_soul.ogg new file mode 100644 index 0000000..4115c51 Binary files /dev/null and b/src/main/resources/assets/harkenscythe/sounds/enchant_soul.ogg differ