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

Fixed interaction with Brewery cauldrons #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,12 @@
<version>2.2.1</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.DieReicheErethons</groupId>
<artifactId>Brewery</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import com.dre.brewery.BCauldron;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -42,29 +45,30 @@ public boolean useVanillaBlockBreaking() {
@Override
public ItemUseHandler getItemHandler() {
return e -> {
Optional<Block> block = e.getClickedBlock();
Optional<Block> optionalBlock = e.getClickedBlock();

if (block.isPresent()) {
Material material = block.get().getType();
if (optionalBlock.isPresent()) {
Block block = optionalBlock.get();

// Cancel the Block placement if the Player sneaks or the Block is not interactable
if (e.getPlayer().isSneaking() || !isInteractable(material)) {
if (e.getPlayer().isSneaking() || !isInteractable(block)) {
e.cancel();
} else {
return;
}
}

if (edible && e.getPlayer().getFoodLevel() < 20) {
restoreHunger(e.getPlayer());
ItemUtils.consumeItem(e.getItem(), false);
} else {
if (edible && e.getPlayer().getFoodLevel() < 20) {
restoreHunger(e.getPlayer());
ItemUtils.consumeItem(e.getItem(), false);
}
}
};
}

private boolean isInteractable(@Nonnull Material material) {
private boolean isInteractable(@Nonnull Block block) {
// We cannot rely on Material#isInteractable() sadly
// as it would allow the placement of this block on strange items like stairs...
Material material = block.getType();
switch (material) {
case ANVIL:
case BREWING_STAND:
Expand All @@ -73,11 +77,21 @@ private boolean isInteractable(@Nonnull Material material) {
case HOPPER:
case TRAPPED_CHEST:
case ENDER_CHEST:
case CAULDRON:
case SHULKER_BOX:
return true;
default:
return material.name().equals("BARREL") || material.name().endsWith("_SHULKER_BOX");
return material.name().equals("BARREL") ||
material.name().endsWith("_SHULKER_BOX") ||
isBreweryCauldron(block);
}
}

private boolean isBreweryCauldron(@Nonnull Block block) {
try {
return LegacyUtil.isWaterCauldron(block.getType()) &&
LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN));
} catch (NoClassDefFoundError e) {
return false;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ api-version: '1.13'
main: io.github.thebusybiscuit.exoticgarden.ExoticGarden

depend:
- Slimefun
- Slimefun

softdepend:
- Brewery