use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.
the class WindowBuildBuilding method updateResources.
/**
* Clears and resets/updates all resources.
*/
private void updateResources() {
final World world = Minecraft.getMinecraft().world;
resources.clear();
final int nextLevel = building.getBuildingLevel() == building.getBuildingMaxLevel() ? building.getBuildingMaxLevel() : (building.getBuildingLevel() + 1);
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), building.getSchematicName() + nextLevel);
final StructureWrapper wrapper = new StructureWrapper(world, sn.toString());
wrapper.setPosition(building.getLocation());
wrapper.rotate(building.getRotation(), world, building.getLocation(), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE);
while (wrapper.findNextBlock()) {
@Nullable final Template.BlockInfo blockInfo = wrapper.getBlockInfo();
@Nullable final Template.EntityInfo entityInfo = wrapper.getEntityinfo();
if (entityInfo != null) {
for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, Minecraft.getMinecraft().player)) {
if (!ItemStackUtils.isEmpty(stack)) {
addNeededResource(stack, 1);
}
}
}
if (blockInfo == null) {
continue;
}
@Nullable final IBlockState blockState = blockInfo.blockState;
@Nullable final Block block = blockState.getBlock();
if (wrapper.isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
continue;
}
if (block != null && block != Blocks.AIR && !AbstractEntityAIStructure.isBlockFree(block, 0) && block != ModBlocks.blockSolidSubstitution && block != ModBlocks.blockSubstitution) {
if (wrapper.getBlockInfo().tileentityData != null) {
final List<ItemStack> itemList = new ArrayList<>();
if (wrapper.getBlockInfo() != null && wrapper.getBlockInfo().tileentityData != null) {
itemList.addAll(ItemStackUtils.getItemStacksOfTileEntity(wrapper.getBlockInfo().tileentityData, world));
}
for (final ItemStack stack : itemList) {
addNeededResource(stack, 1);
}
}
addNeededResource(BlockUtils.getItemStackFromBlockState(blockState), 1);
}
}
window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
updateResourceList();
}
use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.
the class ConstructionTapeHelper method placeConstructionTape.
/**
* Calculates the borders for the workOrderBuildDecoration and sends it to the placement.
*
* @param workOrder the workOrder.
* @param world the world.
*/
public static void placeConstructionTape(@NotNull final WorkOrderBuildDecoration workOrder, @NotNull final World world) {
final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = ColonyUtils.calculateCorners(workOrder.getBuildingLocation(), world, new StructureWrapper(world, workOrder.getStructureName()), workOrder.getRotation(world), workOrder.isMirrored());
placeConstructionTape(workOrder.getBuildingLocation(), corners, world);
}
use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method getWorkingPosition.
/**
* Calculates the working position.
* <p>
* Takes a min distance from width and length.
* <p>
* Then finds the floor level at that distance and then check if it does contain two air levels.
*
* @param targetPosition the position to work at.
* @return BlockPos position to work from.
*/
@Override
public BlockPos getWorkingPosition(final BlockPos targetPosition) {
final StructureWrapper wrapper = job.getStructure();
final int x1 = wrapper.getPosition().getX() - wrapper.getOffset().getX() - STAND_OFFSET;
final int z1 = wrapper.getPosition().getZ() - wrapper.getOffset().getZ() - STAND_OFFSET;
final int x3 = wrapper.getPosition().getX() + (wrapper.getWidth() - wrapper.getOffset().getX()) + STAND_OFFSET;
final int z3 = wrapper.getPosition().getZ() + (wrapper.getLength() - wrapper.getOffset().getZ() + STAND_OFFSET);
final BlockPos[] edges = new BlockPos[] { new BlockPos(x1, BASE_Y_HEIGHT, z1), new BlockPos(x3, 70, z1), new BlockPos(x1, BASE_Y_HEIGHT, z3), new BlockPos(x3, BASE_Y_HEIGHT, z3) };
for (final BlockPos pos : edges) {
final BlockPos basePos = world.getTopSolidOrLiquidBlock(pos);
if (EntityUtils.checkForFreeSpace(world, basePos.down()) && world.getBlockState(basePos).getBlock() != Blocks.SAPLING && world.getBlockState(basePos.down()).getMaterial().isSolid()) {
return basePos;
}
}
return targetPosition;
}
use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.
the class AbstractBuilding method create.
/**
* Create a Building given it's TileEntity.
*
* @param colony The owning colony.
* @param parent The Tile Entity the building belongs to.
* @return {@link AbstractBuilding} instance, without NBTTags applied.
*/
@Nullable
public static AbstractBuilding create(final Colony colony, @NotNull final TileEntityColonyBuilding parent) {
@Nullable AbstractBuilding building = null;
final Class<?> oclass;
try {
oclass = blockClassToBuildingClassMap.get(parent.getBlockType().getClass());
if (oclass == null) {
Log.getLogger().error(String.format("TileEntity %s does not have an associated Building.", parent.getClass().getName()));
return null;
}
final BlockPos loc = parent.getPosition();
final Constructor<?> constructor = oclass.getDeclaredConstructor(Colony.class, BlockPos.class);
building = (AbstractBuilding) constructor.newInstance(colony, loc);
} catch (@NotNull NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException exception) {
Log.getLogger().error(String.format("Unknown Building type '%s' or missing constructor of proper format.", parent.getClass().getName()), exception);
}
if (building != null && parent.getWorld() != null) {
final WorkOrderBuild workOrder = new WorkOrderBuild(building, 1);
final StructureWrapper wrapper = new StructureWrapper(parent.getWorld(), workOrder.getStructureName());
final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = ColonyUtils.calculateCorners(building.getLocation(), parent.getWorld(), wrapper, workOrder.getRotation(parent.getWorld()), workOrder.isMirrored());
building.setCorners(corners.getFirst().getFirst(), corners.getFirst().getSecond(), corners.getSecond().getFirst(), corners.getSecond().getSecond());
building.setHeight(wrapper.getHeight());
ConstructionTapeHelper.placeConstructionTape(building.getLocation(), corners, parent.getWorld());
}
return building;
}
use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.
the class AbstractBuilding method onUpgradeComplete.
/**
* Called upon completion of an upgrade process.
* We suppress this warning since this parameter will be used in child classes which override this method.
*
* @param newLevel The new level.
*/
@SuppressWarnings("squid:S1172")
public void onUpgradeComplete(final int newLevel) {
final WorkOrderBuild workOrder = new WorkOrderBuild(this, newLevel);
final StructureWrapper wrapper = new StructureWrapper(colony.getWorld(), workOrder.getStructureName());
final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = ColonyUtils.calculateCorners(this.getLocation(), colony.getWorld(), wrapper, workOrder.getRotation(colony.getWorld()), workOrder.isMirrored());
this.height = wrapper.getHeight();
this.setCorners(corners.getFirst().getFirst(), corners.getFirst().getSecond(), corners.getSecond().getFirst(), corners.getSecond().getSecond());
}
Aggregations