Skip to content

Commit

Permalink
Refactor crucible levels
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jun 27, 2024
1 parent 40c6c32 commit da25ba7
Show file tree
Hide file tree
Showing 36 changed files with 4,277 additions and 606 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
{
Item item = altar.getInputStack().getItem();
int requiredBlood = HSAltarRecipes.getRequiredBlood(altar.getInputStack().getItem());
altar.decreaseCrucibleLevel(requiredBlood / 10);
altar.decreaseCrucibleEssenceCount(requiredBlood);
altar.getInputStack().shrink(1);
if (!player.world.isRemote) player.world.spawnEntity(new EntityItem(player.world, altarX + 0.5D, altarY + 1.5D, altarZ + 0.5D, new ItemStack(HSAltarRecipes.getOutputBlood(item))));
player.world.playSound(altarX, altarY, altarZ, HSSoundEvents.BLOCK_BLOOD_ALTAR_ENCHANT, SoundCategory.BLOCKS, 0.8F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/mod/emt/harkenscythe/blocks/HSBloodCrucible.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.HSEssenceKeeper;
import mod.emt.harkenscythe.tileentities.HSTileEntityCrucible;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
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.math.BlockPos;
Expand All @@ -22,22 +24,22 @@ public HSBloodCrucible()
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isRemote) return false;

ItemStack heldStack = player.getHeldItem(hand);
if (heldStack.isEmpty()) return false;

Item heldItem = heldStack.getItem();
if (!(heldItem instanceof HSEssenceKeeper)) return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);

int crucibleLevel = state.getValue(LEVEL);
if (crucibleLevel < 10 && !player.isSneaking() && (heldItem == HSItems.essence_keeper_blood || heldItem == HSItems.essence_vessel_blood))
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof HSTileEntityCrucible)) return false;
int crucibleBloodCount = ((HSTileEntityCrucible) te).getEssenceCount();
if (crucibleBloodCount < HSTileEntityCrucible.MAX_ESSENCE_COUNT && !player.isSneaking() && (heldItem == HSItems.essence_keeper_blood || heldItem == HSItems.essence_vessel_blood))
{
fillCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleLevel, HSItems.essence_keeper_blood, HSItems.essence_vessel_blood);
fillCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleBloodCount, HSItems.essence_keeper_blood, HSItems.essence_vessel_blood);
}
else if (crucibleLevel > 0 && player.isSneaking())
else if (crucibleBloodCount > 0 && player.isSneaking())
{
emptyCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleLevel, HSItems.essence_keeper_blood, HSItems.essence_vessel_blood);
emptyCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleBloodCount, HSItems.essence_keeper_blood, HSItems.essence_vessel_blood);
}

return true;
Expand Down
131 changes: 83 additions & 48 deletions src/main/java/mod/emt/harkenscythe/blocks/HSCrucible.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.annotation.Nullable;
import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.HSDyeableArmor;
import mod.emt.harkenscythe.tileentities.HSTileEntityCrucible;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
Expand All @@ -30,7 +32,8 @@
@SuppressWarnings("deprecation")
public abstract class HSCrucible extends Block
{
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 10);
public static final int MAX_LEVEL = 11;
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, MAX_LEVEL);
protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D);
protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
Expand All @@ -45,7 +48,7 @@ protected HSCrucible(MapColor color)

public void setLevel(World world, BlockPos pos, IBlockState state, int level)
{
world.setBlockState(pos, state.withProperty(LEVEL, MathHelper.clamp(level, 0, 10)), 2);
world.setBlockState(pos, state.withProperty(LEVEL, MathHelper.clamp(level, 0, MAX_LEVEL)), 2);
world.updateComparatorOutputLevel(pos, this);
}

Expand Down Expand Up @@ -117,19 +120,23 @@ public Item getItemDropped(IBlockState state, Random rand, int fortune)
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack heldStack = player.getHeldItem(hand);
Item heldItem = heldStack.getItem();
int crucibleLevel = state.getValue(LEVEL);
if (crucibleLevel > 0 && heldItem instanceof HSDyeableArmor)
TileEntity te = world.getTileEntity(pos);
if (te instanceof HSTileEntityCrucible)
{
HSDyeableArmor armor = (HSDyeableArmor) heldItem;
if (armor.hasColor(heldStack) && ((armor.getArmorMaterial() == HSItems.ARMOR_BLOODWEAVE && this instanceof HSBloodCrucible) || (armor.getArmorMaterial() == HSItems.ARMOR_SOULWEAVE && this instanceof HSSoulCrucible)))
ItemStack heldStack = player.getHeldItem(hand);
Item heldItem = heldStack.getItem();
int essenceCount = ((HSTileEntityCrucible) te).getEssenceCount();
if (essenceCount > 0 && heldItem instanceof HSDyeableArmor)
{
armor.removeColor(heldStack);
setLevel(world, pos, state, crucibleLevel - 1);
player.world.playSound(null, pos, SoundEvents.ENTITY_BOBBER_SPLASH, SoundCategory.BLOCKS, 0.1F, 2.0F);
player.addStat(StatList.ARMOR_CLEANED);
return true;
HSDyeableArmor armor = (HSDyeableArmor) heldItem;
if (armor.hasColor(heldStack) && ((armor.getArmorMaterial() == HSItems.ARMOR_BLOODWEAVE && this instanceof HSBloodCrucible) || (armor.getArmorMaterial() == HSItems.ARMOR_SOULWEAVE && this instanceof HSSoulCrucible)))
{
armor.removeColor(heldStack);
((HSTileEntityCrucible) te).setEssenceCount(world, pos, state, essenceCount - 10);
player.world.playSound(null, pos, SoundEvents.ENTITY_BOBBER_SPLASH, SoundCategory.BLOCKS, 0.1F, 2.0F);
player.addStat(StatList.ARMOR_CLEANED);
return true;
}
}
}
return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
Expand All @@ -141,6 +148,14 @@ public ItemStack getItem(World world, BlockPos pos, IBlockState state)
return new ItemStack(Item.getItemFromBlock(this));
}

@Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player)
{
super.onBlockHarvested(world, pos, state, player);
TileEntity te = world.getTileEntity(pos);
if (te != null) te.invalidate();
}

@Override
public boolean hasComparatorInputOverride(IBlockState state)
{
Expand All @@ -159,60 +174,80 @@ protected BlockStateContainer createBlockState()
return new BlockStateContainer(this, LEVEL);
}

protected void fillCrucible(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldStack, Item heldItem, int crucibleLevel, Item keeperType, Item vesselType)
@Override
public boolean hasTileEntity(IBlockState state)
{
return true;
}

@Override
public TileEntity createTileEntity(World world, IBlockState state)
{
return new HSTileEntityCrucible();
}

protected void fillCrucible(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldStack, Item heldItem, int essenceCount, Item keeperType, Item vesselType)
{
if (!player.capabilities.isCreativeMode)
TileEntity te = world.getTileEntity(pos);
if (te instanceof HSTileEntityCrucible)
{
if (heldStack.getItemDamage() + 10 < heldStack.getMaxDamage())
if (!player.capabilities.isCreativeMode)
{
heldStack.setItemDamage(heldStack.getItemDamage() + 10);
}
else
{
heldStack.shrink(1);
if (heldItem == keeperType)
if (heldStack.getItemDamage() + 1 < heldStack.getMaxDamage())
{
player.setHeldItem(hand, new ItemStack(HSItems.essence_keeper));
heldStack.setItemDamage(heldStack.getItemDamage() + 1);
}
else if (heldItem == vesselType)
else
{
player.setHeldItem(hand, new ItemStack(HSItems.essence_vessel));
heldStack.shrink(1);
if (heldItem == keeperType)
{
player.setHeldItem(hand, new ItemStack(HSItems.essence_keeper));
}
else if (heldItem == vesselType)
{
player.setHeldItem(hand, new ItemStack(HSItems.essence_vessel));
}
}
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
((HSTileEntityCrucible) te).setEssenceCount(world, pos, state, essenceCount + 1);
player.addStat(StatList.getObjectUseStats(heldItem));
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
setLevel(world, pos, state, crucibleLevel + 1);
player.addStat(StatList.getObjectUseStats(heldItem));
}

protected void emptyCrucible(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldStack, Item heldItem, int crucibleLevel, Item keeperType, Item vesselType)
protected void emptyCrucible(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldStack, Item heldItem, int essenceCount, Item keeperType, Item vesselType)
{
if (!player.capabilities.isCreativeMode)
TileEntity te = world.getTileEntity(pos);
if (te instanceof HSTileEntityCrucible)
{
if (heldItem == HSItems.essence_keeper || heldItem == HSItems.essence_vessel)
if (!player.capabilities.isCreativeMode)
{
heldStack.shrink(1);
ItemStack newStack = heldItem == HSItems.essence_keeper ? new ItemStack(keeperType) : new ItemStack(vesselType);
newStack.setItemDamage(newStack.getMaxDamage() - 10);
player.setHeldItem(hand, newStack);
}
else if (heldItem == keeperType || heldItem == vesselType)
{
if (heldStack.getItemDamage() == 0) return;
if (heldStack.getItemDamage() > 0)
{
heldStack.setItemDamage(heldStack.getItemDamage() - 10);
}
if (heldStack.getItemDamage() <= 0)
if (heldItem == HSItems.essence_keeper || heldItem == HSItems.essence_vessel)
{
heldStack.shrink(1);
ItemStack newStack = heldItem == keeperType ? new ItemStack(keeperType) : new ItemStack(vesselType);
ItemStack newStack = heldItem == HSItems.essence_keeper ? new ItemStack(keeperType) : new ItemStack(vesselType);
newStack.setItemDamage(newStack.getMaxDamage() - 1);
player.setHeldItem(hand, newStack);
}
else if (heldItem == keeperType || heldItem == vesselType)
{
if (heldStack.getItemDamage() == 0) return;
if (heldStack.getItemDamage() > 0)
{
heldStack.setItemDamage(heldStack.getItemDamage() - 1);
}
if (heldStack.getItemDamage() <= 0)
{
heldStack.shrink(1);
ItemStack newStack = heldItem == keeperType ? new ItemStack(keeperType) : new ItemStack(vesselType);
player.setHeldItem(hand, newStack);
}
}
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
((HSTileEntityCrucible) te).setEssenceCount(world, pos, state, essenceCount - 1);
player.addStat(StatList.getObjectUseStats(heldItem));
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
setLevel(world, pos, state, crucibleLevel - 1);
player.addStat(StatList.getObjectUseStats(heldItem));
}
}
2 changes: 1 addition & 1 deletion src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
{
Item item = altar.getInputStack().getItem();
int requiredSouls = HSAltarRecipes.getRequiredSouls(altar.getInputStack().getItem());
altar.decreaseCrucibleLevel(requiredSouls / 10);
altar.decreaseCrucibleEssenceCount(requiredSouls);
altar.getInputStack().shrink(1);
if (!player.world.isRemote) player.world.spawnEntity(new EntityItem(player.world, altarX + 0.5D, altarY + 1.5D, altarZ + 0.5D, new ItemStack(HSAltarRecipes.getOutputSoul(item))));
player.world.playSound(altarX, altarY, altarZ, HSSoundEvents.BLOCK_SOUL_ALTAR_ENCHANT, SoundCategory.BLOCKS, 0.8F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/mod/emt/harkenscythe/blocks/HSSoulCrucible.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.HSEssenceKeeper;
import mod.emt.harkenscythe.tileentities.HSTileEntityCrucible;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
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.math.BlockPos;
Expand All @@ -22,22 +24,22 @@ public HSSoulCrucible()
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isRemote) return false;

ItemStack heldStack = player.getHeldItem(hand);
if (heldStack.isEmpty()) return false;

Item heldItem = heldStack.getItem();
if (!(heldItem instanceof HSEssenceKeeper)) return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);

int crucibleLevel = state.getValue(LEVEL);
if (crucibleLevel < 10 && !player.isSneaking() && (heldItem == HSItems.essence_keeper_soul || heldItem == HSItems.essence_vessel_soul))
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof HSTileEntityCrucible)) return false;
int crucibleSoulCount = ((HSTileEntityCrucible) te).getEssenceCount();
if (crucibleSoulCount < HSTileEntityCrucible.MAX_ESSENCE_COUNT && !player.isSneaking() && (heldItem == HSItems.essence_keeper_soul || heldItem == HSItems.essence_vessel_soul))
{
fillCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleLevel, HSItems.essence_keeper_soul, HSItems.essence_vessel_soul);
fillCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleSoulCount, HSItems.essence_keeper_soul, HSItems.essence_vessel_soul);
}
else if (crucibleLevel > 0 && player.isSneaking())
else if (crucibleSoulCount > 0 && player.isSneaking())
{
emptyCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleLevel, HSItems.essence_keeper_soul, HSItems.essence_vessel_soul);
emptyCrucible(world, pos, state, player, hand, heldStack, heldItem, crucibleSoulCount, HSItems.essence_keeper_soul, HSItems.essence_vessel_soul);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mod/emt/harkenscythe/init/HSAltarRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HSAltarRecipes
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));
BLOOD_INPUT_BLOODCOUNT_MAP.put(input, requiredBlood);
}

public static void addBloodRecipe(String oreDictName, Item output, int requiredBlood)
Expand All @@ -45,7 +45,7 @@ public static int getRequiredBlood(Item 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));
SOUL_INPUT_SOULCOUNT_MAP.put(input, requiredSouls);
}

public static void addSoulRecipe(String oreDictName, Item output, int requiredSouls)
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/mod/emt/harkenscythe/init/HSRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import mod.emt.harkenscythe.entities.HSEntitySoul;
import mod.emt.harkenscythe.entities.HSEntitySpectralPotion;
import mod.emt.harkenscythe.tileentities.HSTileEntityBloodAltar;
import mod.emt.harkenscythe.tileentities.HSTileEntityCrucible;
import mod.emt.harkenscythe.tileentities.HSTileEntitySoulAltar;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -93,6 +94,7 @@ public static void registerEntity(String name, Class<? extends Entity> clazz)
public static void registerTileEntities()
{
GameRegistry.registerTileEntity(HSTileEntityBloodAltar.class, new ResourceLocation(HarkenScythe.MOD_ID, "blood_altar"));
GameRegistry.registerTileEntity(HSTileEntityCrucible.class, new ResourceLocation(HarkenScythe.MOD_ID, "crucible"));
GameRegistry.registerTileEntity(HSTileEntitySoulAltar.class, new ResourceLocation(HarkenScythe.MOD_ID, "soul_altar"));
}

Expand All @@ -105,12 +107,12 @@ public static void registerRecipes()
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(Items.COOKIE, HSItems.soul_cookie, 5);
//HSAltarRecipes.addSoulRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.AWKWARD).getItem(), Items.EXPERIENCE_BOTTLE, 40); // TODO: Something better for this?
HSAltarRecipes.addSoulRecipe("ingotIron", HSItems.livingmetal_ingot, 10);
HSAltarRecipes.addSoulRecipe("sand", Item.getItemFromBlock(Blocks.SOUL_SAND), 10);
HSAltarRecipes.addSoulRecipe("wool", Item.getItemFromBlock(HSBlocks.soulweave_cloth), 10);
HSAltarRecipes.addSoulRecipe("blockGlass", Item.getItemFromBlock(HSBlocks.spectral_glass), 10);
HSAltarRecipes.addSoulRecipe("blockGlass", Item.getItemFromBlock(HSBlocks.spectral_glass), 5);
}

@SubscribeEvent
Expand Down
Loading

0 comments on commit da25ba7

Please sign in to comment.