Skip to content

Commit

Permalink
fix forest staff
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Mar 10, 2024
1 parent 39cc443 commit c511ea4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/artifality/item/ForestStaffItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public ActionResult useOnBlock(ItemUsageContext context) {
if(hasSapling(player) && world.isAir(pos.up())) {
BlockSoundGroup blockSoundGroup = Blocks.AZALEA.getSoundGroup(Blocks.AZALEA.getDefaultState());
world.playSound(null, pos, blockSoundGroup.getPlaceSound(), SoundCategory.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
world.setBlockState(pos.up(), SAPLINGS.get(consumeSapling(player)).getDefaultState());
world.setBlockState(pos.up(), SAPLINGS.get(getSapling(player)).getDefaultState());
consumeSapling(player);
return ActionResult.SUCCESS;
}
}
Expand All @@ -71,15 +72,24 @@ private static boolean hasSapling(PlayerEntity playerEntity) {
return false;
}

private static Item consumeSapling(PlayerEntity playerEntity) {
private static Item getSapling(PlayerEntity playerEntity) {
Inventory inventory = playerEntity.getInventory();
for (int i = 0; i <= inventory.size(); i++) {
ItemStack itemStack = inventory.getStack(i);
if(SAPLINGS.containsKey(itemStack.getItem())) {
inventory.removeStack(i, 1);
return inventory.getStack(i).getItem();
}
}
return Items.AIR;
}

private static void consumeSapling(PlayerEntity playerEntity) {
Inventory inventory = playerEntity.getInventory();
for (int i = 0; i <= inventory.size(); i++) {
ItemStack itemStack = inventory.getStack(i);
if(SAPLINGS.containsKey(itemStack.getItem())) {
inventory.removeStack(i, 1);
}
}
}
}

0 comments on commit c511ea4

Please sign in to comment.