use of com.ldtteam.structurize.placement.StructurePlacer in project minecolonies by Minecolonies.
the class AbstractEntityAIStructure method pickUpMaterial.
/**
* State to pick up material before going back to work.
*
* @return the next state to go to.
*/
public IAIState pickUpMaterial() {
if (structurePlacer == null || !structurePlacer.getB().hasBluePrint()) {
return IDLE;
}
if (structurePlacer.getB().getStage() == null || structurePlacer.getB().getStage() == BuildingStructureHandler.Stage.CLEAR) {
pickUpCount = 0;
return START_WORKING;
}
final List<Tuple<Predicate<ItemStack>, Integer>> neededItemsList = new ArrayList<>();
final BuilderBucket neededRessourcesMap = getOwnBuilding().getRequiredResources();
final BuildingResourcesModule module = getOwnBuilding().getFirstModuleOccurance(BuildingResourcesModule.class);
if (neededRessourcesMap != null) {
for (final Map.Entry<String, Integer> entry : neededRessourcesMap.getResourceMap().entrySet()) {
final BuildingBuilderResource res = module.getResourceFromIdentifier(entry.getKey());
if (res != null) {
int amount = entry.getValue();
neededItemsList.add(new Tuple<>(itemstack -> ItemStackUtils.compareItemStacksIgnoreStackSize(res.getItemStack(), itemstack, true, true), amount));
}
}
}
if (neededItemsList.size() <= pickUpCount || InventoryUtils.openSlotCount(worker.getInventoryCitizen()) <= MIN_OPEN_SLOTS) {
getOwnBuilding().checkOrRequestBucket(getOwnBuilding().getRequiredResources(), worker.getCitizenData(), true);
getOwnBuilding().checkOrRequestBucket(getOwnBuilding().getNextBucket(), worker.getCitizenData(), false);
pickUpCount = 0;
return START_WORKING;
}
needsCurrently = neededItemsList.get(pickUpCount);
pickUpCount++;
if (InventoryUtils.hasItemInProvider(getOwnBuilding().getTileEntity(), needsCurrently.getA())) {
return GATHERING_REQUIRED_MATERIALS;
}
return pickUpMaterial();
}
use of com.ldtteam.structurize.placement.StructurePlacer in project minecolonies by ldtteam.
the class AbstractEntityAIStructureWithWorkOrder method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
if (job.getWorkOrder().getIteratorType().isEmpty() && getOwnBuilding().hasModule(ISettingsModule.class) && getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE) != null) {
job.getWorkOrder().setIteratorType(getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE).getValue());
}
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
buildingWorker.resetNeededResources();
requestProgress = NULL_POS;
requestState = RequestStage.SOLID;
}
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.DECO;
}
return false;
case DECO:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
}
return false;
default:
return true;
}
}
use of com.ldtteam.structurize.placement.StructurePlacer in project minecolonies by ldtteam.
the class WindowBuildBuilding method updateResources.
/**
* Clears and resets/updates all resources.
*/
private void updateResources() {
if (stylesDropDownList.getSelectedIndex() == -1) {
return;
}
final World world = Minecraft.getInstance().level;
resources.clear();
final IBuildingView parentBuilding = building.getColony().getBuilding(building.getParent());
int nextLevel = building.getBuildingLevel();
if (building.getBuildingLevel() < building.getBuildingMaxLevel() && (parentBuilding == null || building.getBuildingLevel() < parentBuilding.getBuildingLevel())) {
nextLevel = building.getBuildingLevel() + 1;
}
final TileEntity tile = world.getBlockEntity(building.getID());
String schematicName = building.getSchematicName();
if (tile instanceof IBlueprintDataProvider) {
if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
}
}
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), schematicName + nextLevel);
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, building.getPosition(), sn.toString(), new PlacementSettings(), true);
final String md5 = Structures.getMD5(sn.toString());
if (!structure.hasBluePrint() || !structure.isCorrectMD5(md5)) {
if (!structure.hasBluePrint()) {
Log.getLogger().info("Template structure " + sn + " missing");
} else {
Log.getLogger().info("structure " + sn + " md5 error");
}
Log.getLogger().info("Request To Server for structure " + sn);
if (ServerLifecycleHooks.getCurrentServer() == null) {
com.ldtteam.structurize.Network.getNetwork().sendToServer(new SchematicRequestMessage(sn.toString()));
return;
} else {
Log.getLogger().error("WindowMinecoloniesBuildTool: Need to download schematic on a standalone client/server. This should never happen", new Exception());
}
}
if (!structure.hasBluePrint()) {
findPaneOfTypeByID(BUTTON_BUILD, Button.class).hide();
findPaneOfTypeByID(BUTTON_REPAIR, Button.class).hide();
findPaneOfTypeByID(BUTTON_PICKUP_BUILDING, Button.class).show();
return;
}
structure.getBluePrint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(building.getRotation()), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, world);
StructurePlacer placer = new StructurePlacer(structure);
StructurePhasePlacementResult result;
BlockPos progressPos = NULL_POS;
do {
result = placer.executeStructureStep(world, null, progressPos, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.and((info, pos, handler) -> false)), true);
progressPos = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
addNeededResource(stack, stack.getCount());
}
} while (result != null && result.getBlockResult().getResult() != BlockPlacementResult.Result.FINISHED);
window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
updateResourceList();
}
use of com.ldtteam.structurize.placement.StructurePlacer in project minecolonies by ldtteam.
the class CreativeRaiderStructureHandler method loadAndPlaceStructureWithRotation.
/**
* Load a structure into this world and place it in the right position and rotation.
*
* @param worldObj the world to load it in
* @param name the structures name
* @param pos coordinates
* @param rotation the rotation.
* @param mirror the mirror used.
* @param fancyPlacement if fancy or complete.
* @param colonyId the colony id.
* @param event the raid event.
* @param player the placing player.
* @return the placed blueprint.
*/
public static Blueprint loadAndPlaceStructureWithRotation(final World worldObj, @NotNull final String name, @NotNull final BlockPos pos, final Rotation rotation, @NotNull final Mirror mirror, final boolean fancyPlacement, final int colonyId, final IColonyRaidEvent event, @Nullable final ServerPlayerEntity player) {
try {
@NotNull final IStructureHandler structure = new CreativeRaiderStructureHandler(worldObj, pos, name, new PlacementSettings(mirror, rotation), fancyPlacement, event, colonyId);
if (structure.hasBluePrint()) {
@NotNull final StructurePlacer instantPlacer = new StructurePlacer(structure);
Manager.addToQueue(new TickedWorldOperation(instantPlacer, player));
}
return structure.getBluePrint();
} catch (final IllegalStateException e) {
Log.getLogger().warn("Could not load structure!", e);
}
return null;
}
use of com.ldtteam.structurize.placement.StructurePlacer in project minecolonies by ldtteam.
the class EntityAIQuarrier method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
job.getWorkOrder().setIteratorType("default");
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
buildingWorker.resetNeededResources();
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), structurePlacer.getB().getBluePrint().getSizeY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
requestState = RequestStage.SOLID;
}
final BlockPos worldPos = structure.getProgressPosInWorld(requestProgress);
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() < worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (requestProgress.getY() != -1 && result.getIteratorPos().getY() < requestProgress.getY()) {
requestProgress = new BlockPos(0, requestProgress.getY() + 1, 0);
requestState = RequestStage.DECO;
} else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestProgress = new BlockPos(0, structurePlacer.getB().getBluePrint().getSizeY() - 2, 0);
requestState = RequestStage.DECO;
} else {
requestProgress = result.getIteratorPos();
}
return false;
case DECO:
if (requestProgress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
return false;
}
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() > worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
getOwnBuilding().addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else if (requestProgress.getY() != -1 && result.getIteratorPos().getY() > requestProgress.getY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0 || pos.getY() < worldPos.getY())), true);
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
} else if (requestProgress.getY() != -1 && (result.getIteratorPos().getY() < requestProgress.getY())) {
requestState = RequestStage.SOLID;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
}
return true;
}
Aggregations