Skip to content

Commit

Permalink
Improve glaive tilling
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jul 4, 2024
1 parent 7567748 commit 0f44573
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
19 changes: 1 addition & 18 deletions src/main/java/mod/emt/harkenscythe/blocks/HSBlockCreep.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javax.annotation.Nullable;
import mod.emt.harkenscythe.init.HSBlocks;
import mod.emt.harkenscythe.init.HSItems;
import mod.emt.harkenscythe.items.tools.HSGlaive;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
Expand Down Expand Up @@ -111,11 +110,7 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
{
ItemStack heldStack = player.getHeldItem(hand);
Item heldItem = heldStack.getItem();
if (heldItem instanceof HSGlaive && this == HSBlocks.creep_block)
{
return tillGround(world, pos, player, heldStack, heldItem);
}
else if ((heldItem == HSItems.essence_keeper_blood || heldItem == HSItems.essence_vessel_blood) && this == HSBlocks.creep_block_tilled)
if ((heldItem == HSItems.essence_keeper_blood || heldItem == HSItems.essence_vessel_blood) && this == HSBlocks.creep_block_tilled)
{
return bloodyGround(world, pos, player, hand, heldStack, heldItem);
}
Expand All @@ -139,18 +134,6 @@ public boolean isFireSource(World world, BlockPos pos, EnumFacing side)
return true;
}

private boolean tillGround(World world, BlockPos pos, EntityPlayer player, ItemStack heldStack, Item heldItem)
{
world.setBlockState(pos, HSBlocks.creep_block_tilled.getDefaultState());
if (!player.capabilities.isCreativeMode)
{
heldStack.damageItem(1, player);
}
world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
player.addStat(StatList.getObjectUseStats(heldItem));
return true;
}

private boolean bloodyGround(World world, BlockPos pos, EntityPlayer player, EnumHand hand, ItemStack heldStack, Item heldItem)
{
world.setBlockState(pos, HSBlocks.creep_block_tilled_bloodied.getDefaultState());
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/mod/emt/harkenscythe/items/tools/HSGlaive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import mod.emt.harkenscythe.init.HSBlocks;
import mod.emt.harkenscythe.init.HSDamageSource;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
Expand All @@ -18,7 +20,10 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class HSGlaive extends ItemSword
Expand Down Expand Up @@ -56,15 +61,36 @@ public int getMaxItemUseDuration(ItemStack stack)

// TODO: The glaive does not use an AoE attack, it will only be able to attack one entity at a time but does armor piercing damage
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft)
{
if (!world.isRemote && entityLiving instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entityLiving;
RayTraceResult rayTraceResult = rayTrace(world, player, false);
if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos creepPos = rayTraceResult.getBlockPos();
IBlockState creepState = world.getBlockState(creepPos);
if (creepState.getBlock() == HSBlocks.creep_block)
{
world.setBlockState(creepPos, HSBlocks.creep_block_tilled.getDefaultState());
if (!player.capabilities.isCreativeMode)
{
stack.damageItem(1, player);
}
world.playSound(player, creepPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
player.addStat(StatList.getObjectUseStats(stack.getItem()));
}
}
}

float damage = this.getAttackDamage() + 4.0F; // Has to be done like this otherwise it'll calculate wrong
float range = 3.0F;
AxisAlignedBB bb = new AxisAlignedBB(entityLiving.posX - range, entityLiving.posY - range, entityLiving.posZ - range, entityLiving.posX + range, entityLiving.posY + range, entityLiving.posZ + range);

for (int i = 0; i < worldIn.getEntitiesWithinAABB(EntityLiving.class, bb).size(); i++)
for (int i = 0; i < world.getEntitiesWithinAABB(EntityLiving.class, bb).size(); i++)
{
EntityLiving entityInAABB = worldIn.getEntitiesWithinAABB(EntityLiving.class, bb).get(i);
EntityLiving entityInAABB = world.getEntitiesWithinAABB(EntityLiving.class, bb).get(i);

if (Math.min(1.0F, (getMaxItemUseDuration(stack) - timeLeft) / 20.0F) >= 1.0F)
{
Expand Down

0 comments on commit 0f44573

Please sign in to comment.