use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.
the class AbstractBlockHut method use.
@NotNull
@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
/*
If the world is client, open the gui of the building
*/
if (worldIn.isClientSide) {
@Nullable final IBuildingView building = IColonyManager.getInstance().getBuildingView(worldIn.dimension(), pos);
if (building == null) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.gui.nobuilding");
return ActionResultType.FAIL;
}
if (building.getColony() == null) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.gui.nocolony");
return ActionResultType.FAIL;
}
if (!building.getColony().getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.permission.no");
return ActionResultType.FAIL;
}
building.openGui(player.isShiftKeyDown());
}
return ActionResultType.SUCCESS;
}
use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.
the class ItemResourceScroll method appendHoverText.
@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
super.appendHoverText(stack, worldIn, tooltip, flagIn);
if (worldIn == null)
return;
final CompoundNBT compound = checkForCompound(stack);
final int colonyId = compound.getInt(TAG_COLONY_ID);
final BlockPos builderPos = BlockPosUtil.read(compound, TAG_BUILDER);
final IColonyView colonyView = IColonyManager.getInstance().getColonyView(colonyId, worldIn.dimension());
if (colonyView != null) {
final IBuildingView buildingView = colonyView.getBuilding(builderPos);
if (buildingView instanceof BuildingBuilder.View) {
String name = ((BuildingBuilder.View) buildingView).getWorkerName();
tooltip.add(name != null && !name.trim().isEmpty() ? new StringTextComponent(TextFormatting.DARK_PURPLE + name) : new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_SCROLL_NO_BUILDER));
}
}
}
use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.
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.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.
the class ClientEventHandler method handleRenderBuildTool.
/**
* Renders building bounding boxes into the client
*
* @param event The caught event
* @param world The world in which to render
* @param player The player for which to render
*/
private static void handleRenderBuildTool(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
if (Settings.instance.getActiveStructure() == null) {
return;
}
final IColonyView colony = IColonyManager.getInstance().getClosestColonyView(world, new BlockPos(player.position()));
if (colony == null) {
return;
}
final BlockPos activePosition = Settings.instance.getPosition();
final Map<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> newCache = new HashMap<>();
for (final IBuildingView buildingView : colony.getBuildings()) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getClient().neighborbuildingrendering.get()) {
if (buildingView.getBuildingType() == ModBuildings.postBox || buildingView.getBuildingType() == ModBuildings.stash) {
continue;
}
final BlockPos currentPosition = buildingView.getPosition();
if (activePosition.closerThan(currentPosition, PREVIEW_RANGE)) {
if (blueprintCache.containsKey(currentPosition)) {
newCache.put(currentPosition, blueprintCache.get(currentPosition));
continue;
}
final TileEntity tile = world.getBlockEntity(buildingView.getID());
String schematicName = buildingView.getSchematicName();
if (tile instanceof IBlueprintDataProvider) {
if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
}
}
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, buildingView.getStyle(), schematicName + buildingView.getBuildingMaxLevel());
final String structureName = sn.toString();
final String md5 = Structures.getMD5(structureName);
final IStructureHandler wrapper = new LoadOnlyStructureHandler(world, buildingView.getID(), structureName, new PlacementSettings(), true);
if (!wrapper.hasBluePrint() || !wrapper.isCorrectMD5(md5)) {
if (alreadyRequestedStructures.contains(structureName)) {
continue;
}
alreadyRequestedStructures.add(structureName);
Log.getLogger().error("Couldn't find schematic: " + structureName + " requesting to server if possible.");
if (ServerLifecycleHooks.getCurrentServer() == null) {
Network.getNetwork().sendToServer(new SchematicRequestMessage(structureName));
}
continue;
}
final Blueprint blueprint = wrapper.getBluePrint();
final Mirror mirror = buildingView.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE;
blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(buildingView.getRotation()), mirror, world);
final BlockPos primaryOffset = blueprint.getPrimaryBlockOffset();
final BlockPos boxStartPos = currentPosition.subtract(primaryOffset);
final BlockPos size = new BlockPos(blueprint.getSizeX(), blueprint.getSizeY(), blueprint.getSizeZ());
final BlockPos boxEndPos = boxStartPos.offset(size).subtract(new BlockPos(1, 1, 1));
blueprint.setRenderSource(buildingView.getID());
if (buildingView.getBuildingLevel() < buildingView.getBuildingMaxLevel()) {
newCache.put(currentPosition, new Triple(blueprint, boxStartPos, boxEndPos));
} else {
newCache.put(currentPosition, new Triple<>(null, boxStartPos, boxEndPos));
}
}
}
}
blueprintCache = newCache;
for (final Map.Entry<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> nearbyBuilding : blueprintCache.entrySet()) {
final Triple<Blueprint, BlockPos, BlockPos> buildingData = nearbyBuilding.getValue();
final BlockPos position = nearbyBuilding.getKey();
if (buildingData.a != null) {
StructureClientHandler.renderStructureAtPos(buildingData.a, event.getPartialTicks(), position, event.getMatrixStack());
}
RenderUtils.renderBox(buildingData.b, buildingData.c, 0, 0, 1, 1.0F, 0.002D, event.getMatrixStack(), linesWithCullAndDepth.get());
}
}
use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.
the class WindowResourceList method pullResourcesFromHut.
/**
* Retrieve resources from the building to display in GUI.
*/
private void pullResourcesFromHut() {
final IBuildingView newView = builder.getColony().getBuilding(builder.getID());
if (newView instanceof BuildingBuilder.View) {
final BuildingResourcesModuleView moduleView = newView.getModuleView(BuildingResourcesModuleView.class);
final PlayerInventory inventory = this.mc.player.inventory;
final boolean isCreative = this.mc.player.isCreative();
final List<Delivery> deliveries = new ArrayList<>();
for (Map.Entry<Integer, Collection<IToken<?>>> entry : builder.getOpenRequestsByCitizen().entrySet()) {
addDeliveryRequestsToList(deliveries, ImmutableList.copyOf(entry.getValue()));
}
resources.clear();
resources.addAll(moduleView.getResources().values());
double supplied = 0;
double total = 0;
for (final BuildingBuilderResource resource : resources) {
final int amountToSet;
if (isCreative) {
amountToSet = resource.getAmount();
} else {
amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), stack -> !ItemStackUtils.isEmpty(stack) && ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack()));
}
resource.setPlayerAmount(amountToSet);
resource.setAmountInDelivery(0);
for (final Delivery delivery : deliveries) {
if (ItemStackUtils.compareItemStacksIgnoreStackSize(resource.getItemStack(), delivery.getStack(), false, false)) {
resource.setAmountInDelivery(resource.getAmountInDelivery() + delivery.getStack().getCount());
}
}
supplied += Math.min(resource.getAvailable(), resource.getAmount());
total += resource.getAmount();
}
if (total > 0) {
findPaneOfTypeByID(LABEL_PROGRESS, Text.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.progress.res", (int) ((supplied / total) * 100) + "%", moduleView.getProgress() + "%"));
}
resources.sort(new BuildingBuilderResource.ResourceComparator(NOT_NEEDED, HAVE_ENOUGH, IN_DELIVERY, NEED_MORE, DONT_HAVE));
}
}
Aggregations