001/* 002 * This file is part of Baritone. 003 * 004 * Baritone is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Lesser General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * Baritone is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License 015 * along with Baritone. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package baritone.api.schematic.mask.operator; 019 020import baritone.api.schematic.mask.AbstractMask; 021import baritone.api.schematic.mask.Mask; 022import baritone.api.schematic.mask.StaticMask; 023import baritone.api.utils.BooleanBinaryOperator; 024import net.minecraft.world.level.block.state.BlockState; 025 026/** 027 * @author Brady 028 */ 029public final class BinaryOperatorMask extends AbstractMask { 030 031 private final Mask a; 032 private final Mask b; 033 private final BooleanBinaryOperator operator; 034 035 public BinaryOperatorMask(Mask a, Mask b, BooleanBinaryOperator operator) { 036 super(Math.max(a.widthX(), b.widthX()), Math.max(a.heightY(), b.heightY()), Math.max(a.lengthZ(), b.lengthZ())); 037 this.a = a; 038 this.b = b; 039 this.operator = operator; 040 } 041 042 @Override 043 public boolean partOfMask(int x, int y, int z, BlockState currentState) { 044 return this.operator.applyAsBoolean( 045 partOfMask(a, x, y, z, currentState), 046 partOfMask(b, x, y, z, currentState) 047 ); 048 } 049 050 private static boolean partOfMask(Mask mask, int x, int y, int z, BlockState currentState) { 051 return x < mask.widthX() && y < mask.heightY() && z < mask.lengthZ() && mask.partOfMask(x, y, z, currentState); 052 } 053 054 public static final class Static extends AbstractMask implements StaticMask { 055 056 private final StaticMask a; 057 private final StaticMask b; 058 private final BooleanBinaryOperator operator; 059 060 public Static(StaticMask a, StaticMask b, BooleanBinaryOperator operator) { 061 super(Math.max(a.widthX(), b.widthX()), Math.max(a.heightY(), b.heightY()), Math.max(a.lengthZ(), b.lengthZ())); 062 this.a = a; 063 this.b = b; 064 this.operator = operator; 065 } 066 067 @Override 068 public boolean partOfMask(int x, int y, int z) { 069 return this.operator.applyAsBoolean( 070 partOfMask(a, x, y, z), 071 partOfMask(b, x, y, z) 072 ); 073 } 074 075 private static boolean partOfMask(StaticMask mask, int x, int y, int z) { 076 return x < mask.widthX() && y < mask.heightY() && z < mask.lengthZ() && mask.partOfMask(x, y, z); 077 } 078 } 079}