Skip to content

Commit

Permalink
Implement athame cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Dec 27, 2024
1 parent 846f8fc commit 8235c44
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/mod/emt/harkenscythe/block/HSBlockAltar.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void breakBlock(World world, BlockPos pos, IBlockState state)
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 HSTileEntityAltar)
if (te instanceof HSTileEntityAltar && hand == EnumHand.MAIN_HAND)
{
HSTileEntityAltar altar = (HSTileEntityAltar) te;
int altarX = altar.getPos().getX();
Expand All @@ -64,9 +64,14 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En

if (heldStack.getItem() == HSItems.harken_athame)
{
if (!altarStack.isEmpty() && altar.getValidRecipe())
if (player.getCooldownTracker().hasCooldown(heldStack.getItem()))
{
return false;
}
else if (!altarStack.isEmpty() && altar.getValidRecipe())
{
handleRecipe(world, altar, altarStack, player, altarX, altarY, altarZ);
player.getCooldownTracker().setCooldown(heldStack.getItem(), 20);
return true;
}
else
Expand All @@ -79,13 +84,13 @@ else if (!heldStack.isEmpty())
if (altarStack.isEmpty())
{
altar.setInputStack(heldStack.splitStack(1));
player.world.playSound(altarX, altarY, altarZ, HSSoundEvents.ITEM_ATHAME_CREATE.getSoundEvent(), SoundCategory.BLOCKS, 1.0F, 1.75F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
world.playSound(altarX, altarY, altarZ, HSSoundEvents.ITEM_ATHAME_CREATE.getSoundEvent(), SoundCategory.BLOCKS, 1.0F, 1.75F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
return true;
}
else if (altarStack.getMaxStackSize() > altarStack.getCount() && ItemStack.areItemsEqual(altarStack, heldStack) && ItemStack.areItemStackTagsEqual(altarStack, heldStack))
{
heldStack.shrink(1);
player.world.playSound(altarX, altarY, altarZ, HSSoundEvents.ITEM_ATHAME_CREATE.getSoundEvent(), SoundCategory.BLOCKS, 1.0F, 1.75F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
world.playSound(altarX, altarY, altarZ, HSSoundEvents.ITEM_ATHAME_CREATE.getSoundEvent(), SoundCategory.BLOCKS, 1.0F, 1.75F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
altarStack.grow(1);
return true;
}
Expand All @@ -97,7 +102,7 @@ else if (altarStack.getMaxStackSize() > altarStack.getCount() && ItemStack.areIt
{
altar.setInputStack(ItemStack.EMPTY);
player.addItemStackToInventory(itemStack);
player.world.playSound(altarX, altarY, altarZ, getSoundEventFail(), SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
world.playSound(altarX, altarY, altarZ, getSoundEventFail(), SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
return true;
}
}
Expand All @@ -124,19 +129,19 @@ protected void handleRecipe(World world, HSTileEntityAltar altar, ItemStack alta
}
else
{
if (!player.world.isRemote)
if (!world.isRemote)
{
player.world.spawnEntity(new EntityItem(player.world, altarX + 0.5D, altarY + 1.5D, altarZ + 0.5D, getOutput(altarStack.getItem())));
world.spawnEntity(new EntityItem(world, altarX + 0.5D, altarY + 1.5D, altarZ + 0.5D, getOutput(altarStack.getItem())));
}
altar.getInputStack().shrink(1);
}

player.world.playSound(altarX, altarY, altarZ, getSoundEvent(), SoundCategory.BLOCKS, 0.8F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
player.world.playSound(altarX, altarY, altarZ, SoundEvents.ENTITY_ENDEREYE_DEATH, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
world.playSound(altarX, altarY, altarZ, getSoundEvent(), SoundCategory.BLOCKS, 0.8F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);
world.playSound(altarX, altarY, altarZ, SoundEvents.ENTITY_ENDEREYE_DEATH, SoundCategory.BLOCKS, 1.0F, 1.5F / (altar.getWorld().rand.nextFloat() * 0.4F + 1.2F), false);

for (int i = 0; i < requiredEssence; i++)
{
player.world.spawnParticle(EnumParticleTypes.SPELL_WITCH, altarX + world.rand.nextFloat(), altarY + 1.0D + world.rand.nextFloat(), altarZ + world.rand.nextFloat(), 0.0D, 0.5D, 0.0D);
world.spawnParticle(EnumParticleTypes.SPELL_WITCH, altarX + world.rand.nextFloat(), altarY + 1.0D + world.rand.nextFloat(), altarZ + world.rand.nextFloat(), 0.0D, 0.5D, 0.0D);
}

if (player instanceof EntityPlayerMP)
Expand Down

0 comments on commit 8235c44

Please sign in to comment.