2021-05-17 03:02:24 +08:00
|
|
|
package com.gtnewhorizon.structurelib.structure;
|
|
|
|
|
|
2022-09-13 21:22:34 +08:00
|
|
|
import com.google.common.collect.Iterables;
|
2022-08-08 17:40:12 +08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.function.Consumer;
|
2022-09-13 21:22:34 +08:00
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
import javax.annotation.Nullable;
|
2022-08-08 17:40:12 +08:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2021-05-17 03:02:24 +08:00
|
|
|
import net.minecraft.item.ItemStack;
|
2022-08-08 17:40:12 +08:00
|
|
|
import net.minecraft.util.IChatComponent;
|
2021-05-17 03:02:24 +08:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use StructureUtility to instantiate
|
|
|
|
|
*/
|
|
|
|
|
public interface IStructureElementChain<T> extends IStructureElement<T> {
|
2022-07-08 17:14:18 +08:00
|
|
|
IStructureElement<T>[] fallbacks();
|
2021-05-17 03:02:24 +08:00
|
|
|
|
2022-07-08 17:14:18 +08:00
|
|
|
@Override
|
|
|
|
|
default boolean check(T t, World world, int x, int y, int z) {
|
|
|
|
|
for (IStructureElement<T> fallback : fallbacks()) {
|
|
|
|
|
if (fallback.check(t, world, x, y, z)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-05-17 03:02:24 +08:00
|
|
|
|
2022-07-08 17:14:18 +08:00
|
|
|
@Override
|
|
|
|
|
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
|
|
|
|
for (IStructureElement<T> fallback : fallbacks()) {
|
|
|
|
|
if (fallback.spawnHint(t, world, x, y, z, trigger)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-05-17 03:02:24 +08:00
|
|
|
|
2022-07-08 17:14:18 +08:00
|
|
|
@Override
|
|
|
|
|
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
|
|
|
|
for (IStructureElement<T> fallback : fallbacks()) {
|
|
|
|
|
if (fallback.placeBlock(t, world, x, y, z, trigger)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-09-13 21:22:34 +08:00
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
@Override
|
|
|
|
|
default BlocksToPlace getBlocksToPlace(
|
|
|
|
|
T t, World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) {
|
|
|
|
|
Predicate<ItemStack> predicate = null;
|
|
|
|
|
List<Iterable<ItemStack>> is = new ArrayList<>();
|
|
|
|
|
for (IStructureElement<T> fallback : fallbacks()) {
|
|
|
|
|
BlocksToPlace e = fallback.getBlocksToPlace(t, world, x, y, z, trigger, env);
|
|
|
|
|
if (e == null) continue;
|
|
|
|
|
if (predicate == null) predicate = e.getPredicate();
|
|
|
|
|
else predicate = predicate.or(e.getPredicate());
|
|
|
|
|
is.add(e.getStacks());
|
|
|
|
|
}
|
|
|
|
|
if (predicate == null) return null;
|
|
|
|
|
return new BlocksToPlace(predicate, Iterables.concat(is));
|
|
|
|
|
}
|
2022-08-08 17:40:12 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
default PlaceResult survivalPlaceBlock(
|
|
|
|
|
T t,
|
|
|
|
|
World world,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
int z,
|
|
|
|
|
ItemStack trigger,
|
|
|
|
|
IItemSource s,
|
|
|
|
|
EntityPlayerMP actor,
|
|
|
|
|
Consumer<IChatComponent> chatter) {
|
|
|
|
|
boolean haveSkip = false;
|
|
|
|
|
List<IChatComponent> bufferedNoise = new ArrayList<>();
|
|
|
|
|
for (IStructureElement<T> fallback : fallbacks()) {
|
|
|
|
|
PlaceResult result = fallback.survivalPlaceBlock(t, world, x, y, z, trigger, s, actor, bufferedNoise::add);
|
|
|
|
|
switch (result) {
|
|
|
|
|
case REJECT:
|
|
|
|
|
break;
|
|
|
|
|
case SKIP:
|
|
|
|
|
haveSkip = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// dump all that noise back into upstream
|
|
|
|
|
bufferedNoise.forEach(chatter);
|
|
|
|
|
// TODO need reconsider to ensure this is the right course of action
|
|
|
|
|
return haveSkip ? PlaceResult.SKIP : PlaceResult.REJECT;
|
|
|
|
|
}
|
2022-09-11 02:54:11 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
default PlaceResult survivalPlaceBlock(
|
|
|
|
|
T t, World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) {
|
|
|
|
|
boolean haveSkip = false;
|
|
|
|
|
List<IChatComponent> bufferedNoise = new ArrayList<>();
|
|
|
|
|
for (IStructureElement<T> fallback : fallbacks()) {
|
|
|
|
|
PlaceResult result =
|
|
|
|
|
fallback.survivalPlaceBlock(t, world, x, y, z, trigger, env.withChatter(bufferedNoise::add));
|
|
|
|
|
switch (result) {
|
|
|
|
|
case REJECT:
|
|
|
|
|
break;
|
|
|
|
|
case SKIP:
|
|
|
|
|
haveSkip = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// dump all that noise back into upstream
|
|
|
|
|
bufferedNoise.forEach(env.getChatter());
|
|
|
|
|
// TODO need reconsider to ensure this is the right course of action
|
|
|
|
|
return haveSkip ? PlaceResult.SKIP : PlaceResult.REJECT;
|
|
|
|
|
}
|
2021-05-17 03:02:24 +08:00
|
|
|
}
|