forked from McJtyMods/TheOneProbe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package mcjty.theoneprobe; | ||
|
||
|
||
import mcjty.theoneprobe.Tools; | ||
import mcjty.theoneprobe.api.ElementAlignment; | ||
import mcjty.theoneprobe.api.IProbeInfo; | ||
import mcjty.theoneprobe.api.ProbeMode; | ||
import mcjty.theoneprobe.api.TextStyleClass; | ||
import mcjty.theoneprobe.apiimpl.styles.ItemStyle; | ||
import mcjty.theoneprobe.apiimpl.styles.LayoutStyle; | ||
import mcjty.theoneprobe.config.Config; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.items.ItemHandlerHelper; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.text.DecimalFormat; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class Utilities { | ||
|
||
public static final String MODID_DYNAMIC_TREES = "dynamictrees"; | ||
public static final String MODID_APOTHEOSIS = "apotheosis"; | ||
public static final String MODID_PROJECTE = "projecte"; | ||
public static final String MODID_THAUMCRAFT = "thaumcraft"; | ||
|
||
public static final DecimalFormat FORMAT = new DecimalFormat("#,###.#"); | ||
|
||
@Nonnull | ||
public static String getProviderId(@Nonnull String name) { | ||
return String.format("%s:%s_provider", TopExtras.MODID, name); | ||
} | ||
|
||
public static void addItemStack(@Nonnull List<ItemStack> stacks, @Nonnull Set<Item> foundItems, @Nonnull ItemStack stack) { | ||
if (stack.isEmpty()) return; | ||
if (foundItems.contains(stack.getItem())) { | ||
for (ItemStack s : stacks) { | ||
if (ItemHandlerHelper.canItemStacksStack(s, stack)) { | ||
s.grow(stack.getCount()); | ||
return; | ||
} | ||
} | ||
} | ||
// If we come here we need to append a new stack | ||
stacks.add(stack.copy()); | ||
foundItems.add(stack.getItem()); | ||
} | ||
|
||
public static void showChestContents(@Nonnull IProbeInfo probeInfo, @Nonnull List<ItemStack> stacks, @Nonnull ProbeMode mode) { | ||
IProbeInfo vertical = probeInfo.vertical(probeInfo.defaultLayoutStyle().borderColor(Config.chestContentsBorderColor).spacing(0)); | ||
int rows = 0; | ||
int idx = 0; | ||
|
||
if (Tools.show(mode, Config.getRealConfig().getShowChestContentsDetailed()) && stacks.size() <= Config.showItemDetailThresshold) { | ||
for (ItemStack stackInSlot : stacks) { | ||
vertical.horizontal(new LayoutStyle().spacing(10).alignment(ElementAlignment.ALIGN_CENTER)) | ||
.item(stackInSlot, new ItemStyle().width(16).height(16)) | ||
.text(TextStyleClass.INFO + stackInSlot.getDisplayName()); | ||
} | ||
} else { | ||
IProbeInfo horizontal = null; | ||
for (ItemStack stackInSlot : stacks) { | ||
if (idx % 10 == 0) { | ||
horizontal = vertical.horizontal(new LayoutStyle().spacing(0)); | ||
rows++; | ||
if (rows > 4) break; | ||
} | ||
horizontal.item(stackInSlot); | ||
idx++; | ||
} | ||
} | ||
} | ||
} |