-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b432f7e
commit 40b9e14
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/gregtech/common/items/behaviors/ShovelBehavior.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package gregtech.common.items.behaviors; | ||
|
||
import gregtech.api.items.metaitem.stats.IItemBehaviour; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.Blocks; | ||
import net.minecraft.init.SoundEvents; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.*; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public class ShovelBehavior implements IItemBehaviour { | ||
|
||
private final int cost; | ||
|
||
public ShovelBehavior(int cost) { | ||
this.cost = cost; | ||
} | ||
|
||
@Override | ||
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { | ||
ItemStack itemstack = player.getHeldItem(hand); | ||
if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { | ||
return ActionResult.newResult(EnumActionResult.FAIL, itemstack); | ||
} else { | ||
IBlockState iblockstate = world.getBlockState(pos); | ||
Block block = iblockstate.getBlock(); | ||
if (facing != EnumFacing.DOWN && world.getBlockState(pos.up()).getMaterial() == Material.AIR && block == Blocks.GRASS) { | ||
IBlockState state = Blocks.GRASS_PATH.getDefaultState(); | ||
world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F); | ||
if (!world.isRemote) { | ||
world.setBlockState(pos, state, 11); | ||
itemstack.damageItem(cost, player); | ||
} | ||
return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); | ||
} else { | ||
return ActionResult.newResult(EnumActionResult.PASS, itemstack); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters