mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-20 03:59:34 +00:00
57 lines
1.8 KiB
Java
57 lines
1.8 KiB
Java
package com.gtnewhorizon.structurelib.structure;
|
|
|
|
import com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult;
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.world.World;
|
|
|
|
import java.util.UUID;
|
|
|
|
class SurvivalBuildStructureWalker<T> implements IStructureWalker<T> {
|
|
private final T object;
|
|
private final ItemStack trigger;
|
|
private final IItemSource source;
|
|
private final EntityPlayerMP actor;
|
|
private final int elementBudget;
|
|
private final boolean check;
|
|
private int built;
|
|
|
|
public SurvivalBuildStructureWalker(T object, ItemStack trigger, IItemSource source, EntityPlayerMP actor, int elementBudget, boolean check) {
|
|
this.object = object;
|
|
this.trigger = trigger;
|
|
this.source = source;
|
|
this.actor = actor;
|
|
this.elementBudget = elementBudget;
|
|
this.check = check;
|
|
built = 0;
|
|
}
|
|
|
|
@Override
|
|
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z) {
|
|
PlaceResult placeResult = element.survivalPlaceBlock(object, world, x, y, z, trigger, source, actor);
|
|
switch (placeResult) {
|
|
case SKIP:
|
|
return true;
|
|
case ACCEPT:
|
|
if (check)
|
|
element.check(object, world, x, y, z);
|
|
return ++built < elementBudget;
|
|
case REJECT:
|
|
return false;
|
|
case ACCEPT_STOP:
|
|
if (check)
|
|
element.check(object, world, x, y, z);
|
|
built += 1;
|
|
// intentional fallthrough
|
|
case STOP:
|
|
return false;
|
|
default:
|
|
throw new NullPointerException();
|
|
}
|
|
}
|
|
|
|
public int getBuilt() {
|
|
return built;
|
|
}
|
|
}
|