Skip to content

Commit

Permalink
worked on the block analyzer & applier
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple committed Sep 23, 2024
1 parent ea873ff commit d927d79
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ public interface IRedstoneEmitter extends IHasWorldObjectAndCoords {
void setStrongOutputRedstoneSignal(ForgeDirection side, byte aStrength);

/**
* Works the same as {@link #setStrongOutputRedstoneSignal(ForgeDirection, byte)}, except it sets the output on the
* given side to be a weak signal.
* Sets the strength of the redstone signal on the given side to strong or weak.
* Does not change the actual signal.
*
* @param side Must not be UNKNOWN
* @param isStrong True = strong, false = weak
*/
default void setWeakOutputRedstoneSignal(ForgeDirection side, byte aStrength) {}
default void setRedstoneOutputStrength(ForgeDirection side, boolean isStrong) {}

/**
* Checks if the given side will output a strong redstone signal when emitting a redstone signal.
*
* @param side Must not be UNKNOWN
* @return True = strong signal, false = weak signal
*/
default boolean getRedstoneOutputStrength(ForgeDirection side) {
return false;
}

/**
* Gets the Output for the comparator on the given Side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,14 @@ public void setStrongOutputRedstoneSignal(ForgeDirection side, byte strength) {
}

@Override
public void setWeakOutputRedstoneSignal(ForgeDirection side, byte aStrength) {
public void setRedstoneOutputStrength(ForgeDirection side, boolean isStrong) {
mStrongRedstone &= ~(byte) side.flag;
setOutputRedstoneSignal(side, aStrength);
setOutputRedstoneSignal(side, mSidedRedstone[side.ordinal()]);
}

@Override
public boolean getRedstoneOutputStrength(ForgeDirection side) {
return (mStrongRedstone & side.flag) != 0;
}

@Override
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap;
import com.gtnewhorizon.structurelib.alignment.IAlignment;
import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
import com.mojang.authlib.GameProfile;
Expand Down Expand Up @@ -1776,6 +1777,59 @@ public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2,
aIgnoreNBT);
}

public static ItemStackMap<Long> getItemStackHistogram(ItemStack[] stacks) {
return getItemStackHistogram(stacks, true);
}

public static ItemStackMap<Long> getItemStackHistogram(ItemStack[] stacks, boolean NBTSensitive) {
ItemStackMap<Long> histogram = new ItemStackMap<>(NBTSensitive);

if (stacks == null) return histogram;

for (ItemStack stack : stacks) {
if (stack == null) continue;
histogram.merge(stack, (long) stack.stackSize, (Long a, Long b) -> a + b);
}

return histogram;
}

public static ItemStackMap<Long> getItemStackHistogram(Iterable<ItemStack> stacks) {
return getItemStackHistogram(stacks, true);
}

public static ItemStackMap<Long> getItemStackHistogram(Iterable<ItemStack> stacks, boolean NBTSensitive) {
ItemStackMap<Long> histogram = new ItemStackMap<>(NBTSensitive);

if (stacks == null) return histogram;

for (ItemStack stack : stacks) {
if (stack == null) continue;
histogram.merge(stack, (long) stack.stackSize, (Long a, Long b) -> a + b);
}

return histogram;
}

public static ArrayList<ItemStack> getStacksOfSize(ItemStackMap<Long> map, int maxStackSize) {
ArrayList<ItemStack> list = new ArrayList<>();

map.forEach((item, amount) -> {
while (amount > 0) {
int toRemove = Math
.min(amount > Integer.MAX_VALUE ? Integer.MAX_VALUE : amount.intValue(), maxStackSize);

ItemStack copy = item.copy();
copy.stackSize = toRemove;
list.add(copy);

amount -= toRemove;
}
});

return list;
}

public static String getFluidName(Fluid aFluid, boolean aLocalized) {
if (aFluid == null) return E;
String rName = aLocalized ? aFluid.getLocalizedName(new FluidStack(aFluid, 0)) : aFluid.getUnlocalizedName();
Expand Down Expand Up @@ -4614,6 +4668,11 @@ public static Stream<NBTTagCompound> streamCompounds(NBTTagList list) {
.mapToObj(list::getCompoundTagAt);
}

public static Stream<ItemStack> streamInventory(IInventory inv) {
return IntStream.range(0, inv.getSizeInventory())
.mapToObj(inv::getStackInSlot);
}

public static boolean equals(ItemStack[] a, ItemStack[] b) {
// because stupid mojang didn't override equals for us
if (a == null && b == null) return true;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/gregtech/api/util/Lazy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gregtech.api.util;

import java.util.function.Supplier;

public class Lazy<T> {

private boolean hasValue = false;
private T value;

private Supplier<T> getter;

public Lazy(Supplier<T> getter) {
this.getter = getter;
}

public synchronized T get() {
if (!hasValue) {
value = getter.get();
getter = null;
hasValue = true;
}

return value;
}
}
Loading

0 comments on commit d927d79

Please sign in to comment.