aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_HatchElementBuilder.java')
-rw-r--r--src/main/java/gregtech/api/util/GT_HatchElementBuilder.java258
1 files changed, 120 insertions, 138 deletions
diff --git a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
index c3057f3caa..ba9e3b9773 100644
--- a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
+++ b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
@@ -58,21 +58,21 @@ public class GT_HatchElementBuilder<T> {
public final GT_HatchElementBuilder<T> anyOf(IHatchElement<? super T>... elements) {
if (elements == null || elements.length == 0) throw new IllegalArgumentException();
return adder(
- Arrays.stream(elements)
- .map(
- e -> e.adder()
- .rebrand())
- .reduce(IGT_HatchAdder::orElse)
- .get()).hatchClasses(
- Arrays.stream(elements)
- .map(IHatchElement::mteClasses)
- .flatMap(Collection::stream)
- .collect(Collectors.toList()))
- .cacheHint(
- () -> Arrays.stream(elements)
- .map(IHatchElement::name)
- .sorted()
- .collect(Collectors.joining(" or ", "of type ", "")));
+ Arrays.stream(elements)
+ .map(
+ e -> e.adder()
+ .rebrand())
+ .reduce(IGT_HatchAdder::orElse)
+ .get()).hatchClasses(
+ Arrays.stream(elements)
+ .map(IHatchElement::mteClasses)
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList()))
+ .cacheHint(
+ () -> Arrays.stream(elements)
+ .map(IHatchElement::name)
+ .sorted()
+ .collect(Collectors.joining(" or ", "of type ", "")));
}
/**
@@ -84,8 +84,8 @@ public class GT_HatchElementBuilder<T> {
public final GT_HatchElementBuilder<T> atLeast(IHatchElement<? super T>... elements) {
if (elements == null || elements.length == 0) throw new IllegalArgumentException();
return atLeast(
- Arrays.stream(elements)
- .collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting())));
+ Arrays.stream(elements)
+ .collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting())));
}
/**
@@ -96,9 +96,8 @@ public class GT_HatchElementBuilder<T> {
public final GT_HatchElementBuilder<T> atLeastList(List<IHatchElement<? super T>> elements) {
if (elements == null || elements.isEmpty()) throw new IllegalArgumentException();
return atLeast(
- elements.stream()
- .collect(
- Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting())));
+ elements.stream()
+ .collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting())));
}
/**
@@ -108,57 +107,51 @@ public class GT_HatchElementBuilder<T> {
if (elements == null || elements.isEmpty() || elements.containsKey(null) || elements.containsValue(null))
throw new IllegalArgumentException();
List<Class<? extends IMetaTileEntity>> list = elements.keySet()
- .stream()
- .map(IHatchElement::mteClasses)
- .flatMap(Collection::stream)
- .collect(Collectors.toList());
+ .stream()
+ .map(IHatchElement::mteClasses)
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
// map cannot be null or empty, so assert Optional isPresent
return adder(
- elements.keySet()
- .stream()
- .map(
- e -> e.adder()
- .rebrand())
- .reduce(IGT_HatchAdder::orElse)
- .orElseThrow(AssertionError::new))
- .hatchItemFilter(
- obj -> GT_StructureUtility.filterByMTEClass(
- elements.entrySet()
- .stream()
- .filter(
- entry -> entry.getKey()
- .count(obj)
- < entry.getValue()
- .longValue())
- .flatMap(
- entry -> entry.getKey()
- .mteClasses()
- .stream())
- .collect(Collectors.toList())))
- .shouldReject(
- obj -> elements.entrySet()
- .stream()
- .allMatch(
- e -> e.getKey()
- .count(obj)
- >= e.getValue()
- .longValue()))
- .shouldSkip(
- (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (
- c, t) -> t != null && list.stream()
- .anyMatch(
- clazz -> clazz.isInstance(
- t.getMetaTileEntity())))
- .cacheHint(
- () -> elements.keySet()
- .stream()
- .map(IHatchElement::name)
- .sorted()
- .collect(
- Collectors.joining(
- " or ",
- "of type ",
- "")));
+ elements.keySet()
+ .stream()
+ .map(
+ e -> e.adder()
+ .rebrand())
+ .reduce(IGT_HatchAdder::orElse)
+ .orElseThrow(AssertionError::new))
+ .hatchItemFilter(
+ obj -> GT_StructureUtility.filterByMTEClass(
+ elements.entrySet()
+ .stream()
+ .filter(
+ entry -> entry.getKey()
+ .count(obj)
+ < entry.getValue()
+ .longValue())
+ .flatMap(
+ entry -> entry.getKey()
+ .mteClasses()
+ .stream())
+ .collect(Collectors.toList())))
+ .shouldReject(
+ obj -> elements.entrySet()
+ .stream()
+ .allMatch(
+ e -> e.getKey()
+ .count(obj)
+ >= e.getValue()
+ .longValue()))
+ .shouldSkip(
+ (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c,
+ t) -> t != null && list.stream()
+ .anyMatch(clazz -> clazz.isInstance(t.getMetaTileEntity())))
+ .cacheHint(
+ () -> elements.keySet()
+ .stream()
+ .map(IHatchElement::name)
+ .sorted()
+ .collect(Collectors.joining(" or ", "of type ", "")));
}
// endregion
@@ -198,34 +191,34 @@ public class GT_HatchElementBuilder<T> {
}
public GT_HatchElementBuilder<T> hatchItemFilter(
- Function<? super T, ? extends Predicate<ItemStack>> aHatchItemFilter) {
+ Function<? super T, ? extends Predicate<ItemStack>> aHatchItemFilter) {
if (aHatchItemFilter == null) throw new IllegalArgumentException();
mHatchItemFilter = (t, s) -> aHatchItemFilter.apply(t);
return this;
}
public GT_HatchElementBuilder<T> hatchItemFilterAnd(
- Function<? super T, ? extends Predicate<ItemStack>> aHatchItemFilter) {
+ Function<? super T, ? extends Predicate<ItemStack>> aHatchItemFilter) {
if (aHatchItemFilter == null) throw new IllegalArgumentException();
BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> tOldFilter = mHatchItemFilter;
mHatchItemFilter = (t, s) -> tOldFilter.apply(t, s)
- .and(aHatchItemFilter.apply(t));
+ .and(aHatchItemFilter.apply(t));
return this;
}
public GT_HatchElementBuilder<T> hatchItemFilter(
- BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> aHatchItemFilter) {
+ BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> aHatchItemFilter) {
if (aHatchItemFilter == null) throw new IllegalArgumentException();
mHatchItemFilter = aHatchItemFilter;
return this;
}
public GT_HatchElementBuilder<T> hatchItemFilterAnd(
- BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> aHatchItemFilter) {
+ BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> aHatchItemFilter) {
if (aHatchItemFilter == null) throw new IllegalArgumentException();
BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> tOldFilter = mHatchItemFilter;
mHatchItemFilter = (t, s) -> tOldFilter.apply(t, s)
- .and(aHatchItemFilter.apply(t, s));
+ .and(aHatchItemFilter.apply(t, s));
return this;
}
@@ -297,14 +290,11 @@ public class GT_HatchElementBuilder<T> {
// region intermediate
public GT_HatchElementBuilder<T> hatchClass(Class<? extends IMetaTileEntity> clazz) {
- return hatchItemFilter(
- c -> is -> clazz.isInstance(GT_Item_Machines.getMetaTileEntity(is))).cacheHint(
- () -> "of class " + clazz.getSimpleName())
- .shouldSkip(
- (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (
- c,
- t) -> clazz.isInstance(
- t.getMetaTileEntity()));
+ return hatchItemFilter(c -> is -> clazz.isInstance(GT_Item_Machines.getMetaTileEntity(is)))
+ .cacheHint(() -> "of class " + clazz.getSimpleName())
+ .shouldSkip(
+ (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> clazz
+ .isInstance(t.getMetaTileEntity()));
}
@SafeVarargs
@@ -315,26 +305,22 @@ public class GT_HatchElementBuilder<T> {
public final GT_HatchElementBuilder<T> hatchClasses(List<? extends Class<? extends IMetaTileEntity>> classes) {
List<? extends Class<? extends IMetaTileEntity>> list = new ArrayList<>(classes);
return hatchItemFilter(obj -> GT_StructureUtility.filterByMTEClass(list)).cacheHint(
- () -> list.stream()
- .map(Class::getSimpleName)
- .sorted()
- .collect(Collectors.joining(" or ", "of class ", "")))
- .shouldSkip(
- (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (
- c, t) -> t != null
- && list.stream()
- .anyMatch(
- clazz -> clazz.isInstance(
- t.getMetaTileEntity())));
+ () -> list.stream()
+ .map(Class::getSimpleName)
+ .sorted()
+ .collect(Collectors.joining(" or ", "of class ", "")))
+ .shouldSkip(
+ (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null && list.stream()
+ .anyMatch(clazz -> clazz.isInstance(t.getMetaTileEntity())));
}
public GT_HatchElementBuilder<T> hatchId(int aId) {
return hatchItemFilter(
- c -> is -> GT_Utility.isStackValid(is) && is.getItem() instanceof GT_Item_Machines
- && is.getItemDamage() == aId).cacheHint(() -> "of id " + aId)
- .shouldSkip(
- (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (
- c, t) -> t != null && t.getMetaTileID() == aId);
+ c -> is -> GT_Utility.isStackValid(is) && is.getItem() instanceof GT_Item_Machines
+ && is.getItemDamage() == aId).cacheHint(() -> "of id " + aId)
+ .shouldSkip(
+ (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null
+ && t.getMetaTileID() == aId);
}
public GT_HatchElementBuilder<T> hatchIds(int... aIds) {
@@ -342,16 +328,15 @@ public class GT_HatchElementBuilder<T> {
if (aIds.length == 1) return hatchId(aIds[0]);
TIntCollection coll = aIds.length < 16 ? new TIntArrayList(aIds) : new TIntHashSet(aIds);
return hatchItemFilter(
- c -> is -> GT_Utility.isStackValid(is) && is.getItem() instanceof GT_Item_Machines
- && coll.contains(is.getItemDamage())).cacheHint(
- () -> Arrays.stream(coll.toArray())
- .sorted()
- .mapToObj(String::valueOf)
- .collect(Collectors.joining(" or ", "of id ", "")))
- .shouldSkip(
- (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (
- c, t) -> t != null && coll.contains(
- t.getMetaTileID()));
+ c -> is -> GT_Utility.isStackValid(is) && is.getItem() instanceof GT_Item_Machines
+ && coll.contains(is.getItemDamage())).cacheHint(
+ () -> Arrays.stream(coll.toArray())
+ .sorted()
+ .mapToObj(String::valueOf)
+ .collect(Collectors.joining(" or ", "of id ", "")))
+ .shouldSkip(
+ (BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null
+ && coll.contains(t.getMetaTileID()));
}
// endregion
@@ -382,7 +367,7 @@ public class GT_HatchElementBuilder<T> {
public boolean check(T t, World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
return tileEntity instanceof IGregTechTileEntity
- && mAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) mCasingIndex);
+ && mAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) mCasingIndex);
}
@Override
@@ -400,7 +385,7 @@ public class GT_HatchElementBuilder<T> {
public boolean check(T t, World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
return tileEntity instanceof IGregTechTileEntity
- && mAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) mCasingIndex);
+ && mAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) mCasingIndex);
}
@Override
@@ -432,55 +417,54 @@ public class GT_HatchElementBuilder<T> {
@Override
public BlocksToPlace getBlocksToPlace(T t, World world, int x, int y, int z, ItemStack trigger,
- AutoPlaceEnvironment env) {
+ AutoPlaceEnvironment env) {
return BlocksToPlace.create(mHatchItemFilter.apply(t, trigger));
}
@Deprecated
@Override
public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
- IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
+ IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
return survivalPlaceBlock(
- t,
- world,
- x,
- y,
- z,
- trigger,
- AutoPlaceEnvironment.fromLegacy(s, actor, chatter));
+ t,
+ world,
+ x,
+ y,
+ z,
+ trigger,
+ AutoPlaceEnvironment.fromLegacy(s, actor, chatter));
}
@Override
public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
- AutoPlaceEnvironment env) {
+ AutoPlaceEnvironment env) {
if (mShouldSkip != null) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof IGregTechTileEntity
- && mShouldSkip.test(t, (IGregTechTileEntity) tileEntity))
- return PlaceResult.SKIP;
+ && mShouldSkip.test(t, (IGregTechTileEntity) tileEntity)) return PlaceResult.SKIP;
}
if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, env.getActor()))
return PlaceResult.REJECT;
if (mReject != null && mReject.test(t)) return PlaceResult.REJECT;
ItemStack taken = env.getSource()
- .takeOne(mHatchItemFilter.apply(t, trigger), true);
+ .takeOne(mHatchItemFilter.apply(t, trigger), true);
if (GT_Utility.isStackInvalid(taken)) {
String type = getHint();
env.getChatter()
- .accept(new ChatComponentTranslation("GT5U.autoplace.error.no_hatch", type));
+ .accept(new ChatComponentTranslation("GT5U.autoplace.error.no_hatch", type));
return PlaceResult.REJECT;
}
if (StructureUtility.survivalPlaceBlock(
- taken,
- ItemStackPredicate.NBTMode.IGNORE,
- null,
- true,
- world,
- x,
- y,
- z,
- env.getSource(),
- env.getActor()) != PlaceResult.ACCEPT) {
+ taken,
+ ItemStackPredicate.NBTMode.IGNORE,
+ null,
+ true,
+ world,
+ x,
+ y,
+ z,
+ env.getSource(),
+ env.getActor()) != PlaceResult.ACCEPT) {
return PlaceResult.REJECT;
}
// try to infer facing
@@ -497,9 +481,7 @@ public class GT_HatchElementBuilder<T> {
// explicitly rejected, probably obstructed by another slice
if (mDisallowedDirection.contains(direction)) continue;
ForgeDirection rotated = env.getFacing()
- .getWorldDirection(
- direction.offsetY != 0 ? direction.getOpposite()
- : direction);
+ .getWorldDirection(direction.offsetY != 0 ? direction.getOpposite() : direction);
allowed.add(rotated);
}
}