Skip to content

Commit

Permalink
Merge pull request #60 from Diet-Cola/plantreinforcements
Browse files Browse the repository at this point in the history
Add Sweet berry bushes
  • Loading branch information
Maxopoly authored Oct 30, 2020
2 parents 091b749 + 215da3b commit a4ee03a
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions src/main/java/vg/civcraft/mc/citadel/ReinforcementLogic.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package vg.civcraft.mc.citadel;

import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Chest;
import org.bukkit.block.data.type.CoralWallFan;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
Expand All @@ -25,7 +27,7 @@ private ReinforcementLogic() {
/**
* Inserts a new reinforcements into the cache, queues it for persistence and
* plays particle effects for creation
*
*
* @param rein Reinforcement just created
*/
public static void createReinforcement(Reinforcement rein) {
Expand All @@ -36,7 +38,7 @@ public static void createReinforcement(Reinforcement rein) {
}

public static Reinforcement callReinforcementCreationEvent(Player player, Block block, ReinforcementType type,
Group group) {
Group group) {
Reinforcement rein = new Reinforcement(block.getLocation(), type, group);
ReinforcementCreationEvent event = new ReinforcementCreationEvent(player, rein);
Bukkit.getPluginManager().callEvent(event);
Expand Down Expand Up @@ -98,38 +100,38 @@ public static Reinforcement getReinforcementProtecting(Block block) {
return reinforcement;
}
switch (block.getType()) {
// Chests are awkward since you can place both sides of a double chest
// independently, which isn't true for
// beds, plants, or doors, so this needs to be accounted for and
// "getResponsibleBlock()" isn't appropriate
// for the following logic: that both sides protect each other; that if either
// block is reinforced, then
// the chest as a whole remains protected.
case CHEST:
case TRAPPED_CHEST: {
Chest chest = (Chest) block.getBlockData();
BlockFace facing = chest.getFacing();
switch (chest.getType()) {
case LEFT: {
BlockFace face = BlockAPI.turnClockwise(facing);
return getReinforcementAt(block.getLocation().add(face.getDirection()));
}
case RIGHT: {
BlockFace face = BlockAPI.turnAntiClockwise(facing);
return getReinforcementAt(block.getLocation().add(face.getDirection()));
// Chests are awkward since you can place both sides of a double chest
// independently, which isn't true for
// beds, plants, or doors, so this needs to be accounted for and
// "getResponsibleBlock()" isn't appropriate
// for the following logic: that both sides protect each other; that if either
// block is reinforced, then
// the chest as a whole remains protected.
case CHEST:
case TRAPPED_CHEST: {
Chest chest = (Chest) block.getBlockData();
BlockFace facing = chest.getFacing();
switch (chest.getType()) {
case LEFT: {
BlockFace face = BlockAPI.turnClockwise(facing);
return getReinforcementAt(block.getLocation().add(face.getDirection()));
}
case RIGHT: {
BlockFace face = BlockAPI.turnAntiClockwise(facing);
return getReinforcementAt(block.getLocation().add(face.getDirection()));
}
default: {
return null;
}
}
}
default: {
return null;
}
}
}
default: {
Block responsible = getResponsibleBlock(block);
if (Objects.equals(block, responsible)) {
return null;
Block responsible = getResponsibleBlock(block);
if (Objects.equals(block, responsible)) {
return null;
}
return getReinforcementAt(responsible.getLocation());
}
return getReinforcementAt(responsible.getLocation());
}
}
}

Expand All @@ -143,7 +145,7 @@ public static Reinforcement getReinforcementProtecting(Block block) {
* @param block Block to get responsible block for
* @return Block which reinforcement would protect the given block
*/

public static Block getResponsibleBlock(Block block) {
// Do not put [double] chests in here.
switch (block.getType()) {
Expand Down Expand Up @@ -171,6 +173,7 @@ public static Block getResponsibleBlock(Block block) {
case CARROTS:
case POTATOES:
case BEETROOTS:
case SWEET_BERRY_BUSH:
case MELON_STEM:
case PUMPKIN_STEM:
case ATTACHED_MELON_STEM:
Expand Down Expand Up @@ -300,7 +303,7 @@ public static Block getResponsibleBlock(Block block) {
* @param player the player attempting to access stuff
* @param block Block to check for
* @return True if the player can not do something like placing an adjacent
* chest or comparator, false otherwise
* chest or comparator, false otherwise
*/
public static boolean isPreventingBlockAccess(Player player, Block block) {
if (block == null) {
Expand Down

0 comments on commit a4ee03a

Please sign in to comment.