2021-07-19 17:45:18 +08:00
|
|
|
package com.gtnewhorizon.structurelib.structure;
|
|
|
|
|
|
2022-08-08 17:40:12 +08:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.function.Function;
|
2022-09-13 21:22:34 +08:00
|
|
|
import javax.annotation.Nullable;
|
2022-08-08 17:40:12 +08:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2021-07-19 17:45:18 +08:00
|
|
|
import net.minecraft.item.ItemStack;
|
2022-08-08 17:40:12 +08:00
|
|
|
import net.minecraft.util.IChatComponent;
|
2021-07-19 17:45:18 +08:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
class LazyStructureElement<T> implements IStructureElementDeferred<T> {
|
2022-07-08 17:14:18 +08:00
|
|
|
private Function<T, IStructureElement<T>> to;
|
|
|
|
|
private IStructureElement<T> elem;
|
|
|
|
|
|
|
|
|
|
public LazyStructureElement(Function<T, IStructureElement<T>> to) {
|
|
|
|
|
this.to = to;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IStructureElement<T> get(T t) {
|
|
|
|
|
if (to != null) {
|
|
|
|
|
elem = to.apply(t);
|
|
|
|
|
to = null;
|
|
|
|
|
}
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean check(T t, World world, int x, int y, int z) {
|
|
|
|
|
return get(t).check(t, world, x, y, z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
|
|
|
|
return get(t).placeBlock(t, world, x, y, z, trigger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
|
|
|
|
return get(t).spawnHint(t, world, x, y, z, trigger);
|
|
|
|
|
}
|
2022-08-08 17:40:12 +08:00
|
|
|
|
2022-09-13 21:22:34 +08:00
|
|
|
@Nullable
|
|
|
|
|
@Override
|
|
|
|
|
public BlocksToPlace getBlocksToPlace(
|
|
|
|
|
T t, World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) {
|
|
|
|
|
return get(t).getBlocksToPlace(t, world, x, y, z, trigger, env);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 17:40:12 +08:00
|
|
|
@Override
|
|
|
|
|
public PlaceResult survivalPlaceBlock(
|
|
|
|
|
T t,
|
|
|
|
|
World world,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
int z,
|
|
|
|
|
ItemStack trigger,
|
|
|
|
|
IItemSource s,
|
|
|
|
|
EntityPlayerMP actor,
|
|
|
|
|
Consumer<IChatComponent> chatter) {
|
|
|
|
|
return get(t).survivalPlaceBlock(t, world, x, y, z, trigger, s, actor, chatter);
|
|
|
|
|
}
|
2022-09-11 02:54:11 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PlaceResult survivalPlaceBlock(
|
|
|
|
|
T t, World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) {
|
|
|
|
|
return get(t).survivalPlaceBlock(t, world, x, y, z, trigger, env);
|
|
|
|
|
}
|
2021-07-19 17:45:18 +08:00
|
|
|
}
|