Skip to content

Commit

Permalink
Fix #545 by creating Tags.WATER
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Sep 4, 2022
1 parent 0a1058e commit 120d3e2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public CraftStatus checkCraftStatus(@NotNull Craft craft) {
if (type != Material.FIRE && !type.isAir()) {
totalNonNegligibleBlocks++;
}
if (type != Material.FIRE && !type.isAir() && type != Material.WATER) {
if (type != Material.FIRE && !type.isAir() && !Tags.FLUID.contains(type)) {
totalNonNegligibleWaterBlocks++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,31 +480,31 @@ public int getWaterLine() {
posZ = hitBox.getMinZ() - 1;
for (posX = hitBox.getMinX() - 1; posX <= hitBox.getMaxX() + 1; posX++) {
Material material = w.getBlockAt(posX, posY, posZ).getType();
if (material == Material.WATER)
if (Tags.WATER.contains(material))
numWater++;
if (material.isAir())
numAir++;
}
posZ = hitBox.getMaxZ() + 1;
for (posX = hitBox.getMinX() - 1; posX <= hitBox.getMaxX() + 1; posX++) {
Material material = w.getBlockAt(posX, posY, posZ).getType();
if (material == Material.WATER)
if (Tags.WATER.contains(material))
numWater++;
if (material.isAir())
numAir++;
}
posX = hitBox.getMinX() - 1;
for (posZ = hitBox.getMinZ(); posZ <= hitBox.getMaxZ(); posZ++) {
Material material = w.getBlockAt(posX, posY, posZ).getType();
if (material == Material.WATER)
if (Tags.WATER.contains(material))
numWater++;
if (material.isAir())
numAir++;
}
posX = hitBox.getMaxX() + 1;
for (posZ = hitBox.getMinZ(); posZ <= hitBox.getMaxZ(); posZ++) {
Material material = w.getBlockAt(posX, posY, posZ).getType();
if (material == Material.WATER)
if (Tags.WATER.contains(material))
numWater++;
if (material.isAir())
numAir++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ public void onItemSpawn(final ItemSpawnEvent e) {
// prevent water and lava from spreading on moving crafts
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockFromTo(BlockFromToEvent e) {
if (e.isCancelled()) {
if (e.isCancelled())
return;
}

Block block = e.getToBlock();
if (block.getType() != Material.WATER && block.getType() != Material.LAVA) {
if (!Tags.FLUID.contains(block.getType()))
return;
}

MovecraftLocation location = MathUtils.bukkit2MovecraftLoc(block.getLocation());
for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
if ((!tcraft.isNotProcessing()) && MathUtils.locIsNearCraftFast(tcraft, MathUtils.bukkit2MovecraftLoc(block.getLocation()))) {
if ((!tcraft.isNotProcessing()) && MathUtils.locIsNearCraftFast(tcraft, location)) {
e.setCancelled(true);
return;
}
Expand Down Expand Up @@ -162,7 +163,7 @@ public void onPhysics(BlockPhysicsEvent event) {
if (!MathUtils.locIsNearCraftFast(tcraft, mloc)) {
continue;
}
if(Tags.FRAGILE_MATERIALS.contains(event.getBlock().getType())) {
if (Tags.FRAGILE_MATERIALS.contains(event.getBlock().getType())) {
BlockData m = block.getBlockData();
BlockFace face = BlockFace.DOWN;
boolean faceAlwaysDown = block.getType() == Material.COMPARATOR || block.getType() == Material.REPEATER;
Expand Down Expand Up @@ -191,15 +192,15 @@ public void onBlockDispense(BlockDispenseEvent e) {
}

@EventHandler
public void onFlow(BlockFromToEvent e){
if(Settings.DisableSpillProtection)
public void onFlow(BlockFromToEvent e) {
if (Settings.DisableSpillProtection)
return;
if(!e.getBlock().isLiquid())
if (!e.getBlock().isLiquid())
return;
MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation());
MovecraftLocation toLoc = MathUtils.bukkit2MovecraftLoc(e.getToBlock().getLocation());
for(Craft craft : CraftManager.getInstance().getCraftsInWorld(e.getBlock().getWorld())){
if(craft.getHitBox().contains((loc)) && !craft.getFluidLocations().contains(toLoc)) {
for (Craft craft : CraftManager.getInstance().getCraftsInWorld(e.getBlock().getWorld())) {
if (craft.getHitBox().contains((loc)) && !craft.getFluidLocations().contains(toLoc)) {
e.setCancelled(true);
break;
}
Expand All @@ -210,7 +211,7 @@ public void onFlow(BlockFromToEvent e){
public void onIceForm(BlockFormEvent e) {
if (e.isCancelled() || !Settings.DisableIceForm)
return;
if(e.getBlock().getType() != Material.WATER)
if (Tags.WATER.contains(e.getBlock().getType()))
return;

MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public final void onSignTranslate(SignTranslateEvent event) {
}
int add = materials.get(material);
totalNonNegligibleBlocks += add;
if (!material.equals(Material.WATER)) {
if (!Tags.WATER.contains(material)) {
totalNonNegligibleWaterBlocks += add;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ else if (o instanceof Integer)
return data;

var passthroughBlocks = data.get(PASSTHROUGH_BLOCKS);
passthroughBlocks.add(Material.WATER);
passthroughBlocks.addAll(Tags.WATER);
data.put(PASSTHROUGH_BLOCKS, passthroughBlocks);
return data;
});
Expand All @@ -610,7 +610,7 @@ else if (o instanceof Integer)
return data;

var forbiddenHoverOverBlocks = data.get(FORBIDDEN_HOVER_OVER_BLOCKS);
forbiddenHoverOverBlocks.add(Material.WATER);
forbiddenHoverOverBlocks.addAll(Tags.WATER);
data.put(FORBIDDEN_HOVER_OVER_BLOCKS, forbiddenHoverOverBlocks);
return data;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.util.Set;

public class Tags {

public static final EnumSet<Material> FLUID = EnumSet.of(Material.WATER, Material.LAVA);
public static final EnumSet<Material> WATER = EnumSet.of(Material.WATER, Material.BUBBLE_COLUMN);
public static final EnumSet<Material> FLUID = EnumSet.of(Material.WATER, Material.BUBBLE_COLUMN, Material.LAVA);
public static final EnumSet<Material> CHESTS = EnumSet.of(Material.CHEST, Material.TRAPPED_CHEST, Material.BARREL);
public static final EnumSet<Material> FURNACES = EnumSet.of(Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER);
public static final EnumSet<Material> SINKING_PASSTHROUGH = EnumSet.of(Material.TALL_GRASS, Material.GRASS);
Expand All @@ -34,8 +34,6 @@ public class Tags {
FRAGILE_MATERIALS.addAll(Tag.WOODEN_PRESSURE_PLATES.getValues());

FALL_THROUGH_BLOCKS.add(Material.AIR);
FALL_THROUGH_BLOCKS.add(Material.WATER);
FALL_THROUGH_BLOCKS.add(Material.LAVA);
FALL_THROUGH_BLOCKS.add(Material.DEAD_BUSH);
FALL_THROUGH_BLOCKS.addAll(Tag.CORAL_PLANTS.getValues());
FALL_THROUGH_BLOCKS.add(Material.BROWN_MUSHROOM);
Expand All @@ -51,6 +49,7 @@ public class Tags {
FALL_THROUGH_BLOCKS.add(Material.CARROT);
FALL_THROUGH_BLOCKS.add(Material.POTATO);
FALL_THROUGH_BLOCKS.addAll(Tag.FENCES.getValues());
FALL_THROUGH_BLOCKS.addAll(FLUID);
}

@Nullable
Expand Down

0 comments on commit 120d3e2

Please sign in to comment.