Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combined hoe fixes #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class CombineHoe extends BaseSTBItem {
private Material seedType;
private int seedAmount;
private InventoryGUI gui;
private EquipmentSlot equipmentSlot;

@Nonnull
public static String getInventoryTitle() {
Expand Down Expand Up @@ -83,6 +84,14 @@ public void setSeedAmount(int seedAmount) {
this.seedAmount = seedAmount;
}

public EquipmentSlot getEquipmentSlot() {
return equipmentSlot;
}

public void setEquipmentSlot(EquipmentSlot equipmentSlot) {
this.equipmentSlot = equipmentSlot;
}

@Override
public boolean isEnchantable() {
return false;
Expand All @@ -92,7 +101,7 @@ public boolean isEnchantable() {
public String[] getLore() {
int n = getWorkRadius() * 2 + 1;
String s = n + "x" + n;
return new String[] { "Right-click dirt/grass:" + ChatColor.WHITE + " till 3x3 area", "Right-click soil:" + ChatColor.WHITE + " sow 3x3 area", "Right-click other:" + ChatColor.WHITE + " open seed bag", "Left-click plants:" + ChatColor.WHITE + " harvest " + s + " area", "Left-click leaves:" + ChatColor.WHITE + " break 3x3x3 area", };
return new String[] { "Right-click dirt/grass:" + ChatColor.WHITE + " till 3x3 area", "Right-click soil:" + ChatColor.WHITE + " sow 3x3 area", "Right-click air:" + ChatColor.WHITE + " open seed bag", "Left-click plants:" + ChatColor.WHITE + " harvest " + s + " area", "Left-click leaves:" + ChatColor.WHITE + " break 3x3x3 area", };
}

@Override
Expand All @@ -113,20 +122,21 @@ public boolean hasGlow() {
@Override
public void onInteractItem(PlayerInteractEvent event) {
Block b = event.getClickedBlock();
setEquipmentSlot(event.getHand());

if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (b.getType() == Material.FARMLAND) {
plantSeeds(event.getPlayer(), b);
event.setCancelled(true);
return;
} else if (b.getType() == Material.DIRT || b.getType() == Material.GRASS) {
} else if (b.getType() == Material.DIRT || b.getType() == Material.GRASS_BLOCK) {
tillSoil(event.getPlayer(), event.getItem(), event.getHand(), b);
event.setCancelled(true);
return;
}
}

if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
if (event.getClickedBlock() == null || !event.getClickedBlock().getType().isInteractable()) {
gui = GUIUtil.createGUI(event.getPlayer(), this, 9, getInventoryTitle());

Expand Down Expand Up @@ -241,6 +251,7 @@ public void onGUIClosed(HumanEntity player) {

setSeedAmount(count);
setSeedType(seeds);
updateHeldItemStack((Player) player, getEquipmentSlot());
}

private void populateSeedBag(InventoryGUI gui) {
Expand Down Expand Up @@ -286,6 +297,7 @@ private void plantSeeds(Player player, Block b) {

if (amountLeft < getSeedAmount()) {
setSeedAmount(amountLeft);
updateHeldItemStack(player, getEquipmentSlot());
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1.0F, 1.0F);
}
}
Expand All @@ -297,7 +309,7 @@ private void harvestLayer(Player player, Block b) {

for (Block block : cuboid) {
if (!block.equals(b) && (STBUtil.isPlant(block.getType()) || Tag.LEAVES.isTagged(block.getType()))) {
if (!SensibleToolbox.getProtectionManager().hasPermission(player, b, ProtectableAction.BREAK_BLOCK)) {
if (SensibleToolbox.getProtectionManager().hasPermission(player, b, ProtectableAction.BREAK_BLOCK)) {
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
block.breakNaturally();
}
Expand Down