Skip to content

Commit

Permalink
Fix many minor issues
Browse files Browse the repository at this point in the history
- Add battery item provider
- Allow inserts into battery buffers
- String formatting from names
- Fix name for pattern item providers
- Fix colouring for planning warnings/errors
- Skip bacvat renderer
- Transform strong redstone sides
  • Loading branch information
RecursivePineapple authored Feb 26, 2025
2 parents b069122 + 919af9b commit d8a7623
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.recursive_pineapple.matter_manipulator.common.building;

import static gregtech.api.util.GTUtility.sendChatToPlayer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -260,12 +258,12 @@ public void givePlayerFluids(List<BigFluidStack> fluids) {

@Override
public void warn(String message) {
sendChatToPlayer(player, String.format("§cWarning at block %d, %d, %d: %s§r", x, y, z, message));
MMUtils.sendWarningToPlayer(player, String.format("Warning at block %d, %d, %d: %s", x, y, z, message));
}

@Override
public void error(String message) {
sendChatToPlayer(player, String.format("§cError at block %d, %d, %d: %s§r", x, y, z, message));
MMUtils.sendErrorToPlayer(player, String.format("Error at block %d, %d, %d: %s", x, y, z, message));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ public GTAnalysisResult(IGregTechTileEntity igte) {
mGTGhostCircuit = 0;
} else if (circuit.getItem() == ItemList.Circuit_Integrated.getItem()) {
mGTGhostCircuit = (byte) Items.feather.getDamage(circuit);

}
}

Expand Down Expand Up @@ -580,14 +579,20 @@ public void transform(Transform transform) {
}

byte transformedConns = 0;
byte transformedStrongOutput = 0;

for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if ((mConnections & dir.flag) != 0) {
transformedConns |= transform.apply(dir).flag;
}

if ((mStrongRedstone & dir.flag) != 0) {
transformedStrongOutput |= transform.apply(dir).flag;
}
}

mConnections = transformedConns;
mStrongRedstone = transformedStrongOutput;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.item.ItemStack;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -17,7 +18,13 @@ public interface IItemProvider {
* @param consume When false, no items will be extracted and the item will be provided as normal.
* @return The item, or null if the pseudo inventory didn't have the required items.
*/
public @Nullable ItemStack getStack(IPseudoInventory inv, boolean consume);
@Contract("_,false->!null")
@Nullable
ItemStack getStack(IPseudoInventory inv, boolean consume);

public IItemProvider clone();
default String describe() {
return getStack(null, false).getDisplayName();
}

IItemProvider clone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.recursive_pineapple.matter_manipulator.common.utils.Mods;
import com.recursive_pineapple.matter_manipulator.common.utils.Mods.Names;

import bartworks.common.loaders.FluidLoader;
import tectech.thing.casing.TTCasingsContainer;

/**
Expand All @@ -29,6 +30,7 @@ private static boolean shouldBeSkippedGT(Block block, int meta) {
if (block == GregTechAPI.sBlackholeRender) return true;
if (block == TTCasingsContainer.eyeOfHarmonyRenderBlock) return true;
if (block == TTCasingsContainer.forgeOfGodsRenderBlock) return true;
if (block == FluidLoader.bioFluidBlock) return true;

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.item.ItemStack;

import com.recursive_pineapple.matter_manipulator.common.building.BlockAnalyzer.IBlockApplyContext;
import com.recursive_pineapple.matter_manipulator.common.building.providers.BatteryItemProvider;
import com.recursive_pineapple.matter_manipulator.common.utils.InventoryAdapter;
import com.recursive_pineapple.matter_manipulator.common.utils.MMUtils;
import com.recursive_pineapple.matter_manipulator.common.utils.Mods;
Expand Down Expand Up @@ -61,6 +62,10 @@ private static IItemProvider getProviderFor(ItemStack stack, boolean fuzzy) {
if (pattern != null) return pattern;
}

IItemProvider battery = BatteryItemProvider.fromStack(stack);

if (battery != null) return battery;

return fuzzy ? new PortableItemStack(stack) : PortableItemStack.withNBT(stack);
}

Expand Down Expand Up @@ -100,7 +105,7 @@ public boolean apply(IBlockApplyContext context, IInventory inv, InventoryAdapte
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null) {
if (!adapter.canExtract(inv, slot)) {
context.warn("Could not extract item in slot " + slot + ": " + stack.getDisplayName());
context.warn("Could not extract item in slot " + slot + ": " + MMUtils.stripFormat(stack.getDisplayName()));
continue;
}

Expand All @@ -114,14 +119,14 @@ public boolean apply(IBlockApplyContext context, IInventory inv, InventoryAdapte

if (target != null) {
if (!adapter.canInsert(inv, slot, target.getStack(null, false))) {
context.warn("Invalid item for slot " + slot + ": " + target.toString());
context.warn("Invalid item for slot " + slot + ": " + MMUtils.stripFormat(target.describe()));
continue;
}

ItemStack toInsert = target.getStack(context, consume);

if (toInsert == null) {
context.warn("Could not gather item for inventory: " + target.toString());
context.warn("Could not gather item for inventory: " + MMUtils.stripFormat(target.describe()));
success = false;
} else {
if (!simulate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public static PatternItemProvider fromPattern(ItemStack stack) {

@Override
public @Nullable ItemStack getStack(IPseudoInventory inv, boolean consume) {
ItemStack stack = PATTERN.maybeStack(1)
.get();
ItemStack stack = PATTERN.maybeStack(1).get();

stack.stackSize = amount == null ? 1 : amount;
stack.setTagCompound(pattern != null ? (NBTTagCompound) pattern.copy() : null);
Expand All @@ -60,6 +59,11 @@ public static PatternItemProvider fromPattern(ItemStack stack) {
return stack;
}

@Override
public String describe() {
return BLANK_PATTERN.maybeStack(1).get().getDisplayName();
}

@Override
public PatternItemProvider clone() {
PatternItemProvider dup = new PatternItemProvider();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.recursive_pineapple.matter_manipulator.common.building.providers;

import java.util.Arrays;

import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

import net.minecraftforge.oredict.OreDictionary;

import com.recursive_pineapple.matter_manipulator.common.building.IItemProvider;
import com.recursive_pineapple.matter_manipulator.common.building.IPseudoInventory;
import com.recursive_pineapple.matter_manipulator.common.utils.BigItemStack;
import com.recursive_pineapple.matter_manipulator.common.utils.ImmutableItemMeta;
import com.recursive_pineapple.matter_manipulator.common.utils.ItemMeta;

import org.jetbrains.annotations.Nullable;

public class BatteryItemProvider implements IItemProvider {

public ImmutableItemMeta battery;

public BatteryItemProvider() {}

public static BatteryItemProvider fromStack(ItemStack stack) {
if (stack == null) return null;

boolean isBattery = false;

for (int oreId : OreDictionary.getOreIDs(stack)) {
if (OreDictionary.getOreName(oreId).startsWith("battery")) {
isBattery = true;
break;
}
}

if (!isBattery) return null;

BatteryItemProvider provider = new BatteryItemProvider();

provider.battery = new ItemMeta(stack.getItem(), Items.feather.getDamage(stack));

return provider;
}

@Override
public @Nullable ItemStack getStack(IPseudoInventory inv, boolean consume) {
ItemStack stack = new ItemStack(battery.getItem(), 1, battery.getMeta());

if (!consume) return stack;

var result = inv.tryConsumeItems(Arrays.asList(new BigItemStack(stack)), IPseudoInventory.CONSUME_FUZZY);

if (!result.leftBoolean()) return null;

return result.right().get(0).getItemStack();
}

@Override
public IItemProvider clone() {
BatteryItemProvider provider = new BatteryItemProvider();

provider.battery = new ItemMeta(battery.getItem(), battery.getMeta());

return provider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.IHasInventory;
import gregtech.api.metatileentity.implementations.MTEBasicBatteryBuffer;
import gregtech.api.metatileentity.implementations.MTEMultiBlockBase;
import gregtech.common.tileentities.machines.MTEHatchOutputBusME;
import gregtech.common.tileentities.machines.MTEHatchOutputME;
Expand Down Expand Up @@ -42,6 +43,7 @@ private boolean canHandleImpl(IInventory inv) {
if (imte instanceof MTEHatchOutputME) return true;
if (imte instanceof MTEHatchRack) return true;
if (imte instanceof MTEMultiBlockBase) return true;
if (imte instanceof MTEBasicBatteryBuffer) return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.UUID;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -164,6 +165,8 @@ public class MMUtils {
public static final String ITALIC = EnumChatFormatting.ITALIC.toString();
public static final String RESET = EnumChatFormatting.RESET.toString();

public static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)§[0-9A-FK-OR]");

private MMUtils() {}

public static int clamp(int val, int lo, int hi) {
Expand Down Expand Up @@ -415,6 +418,10 @@ public static void sendChatToPlayer(EntityPlayer aPlayer, String aChatMessage) {
}
}

public static String stripFormat(String text) {
return FORMATTING_CODE_PATTERN.matcher(text).replaceAll("");
}

private static DecimalFormat getDecimalFormat() {
return decimalFormatters.computeIfAbsent(Locale.getDefault(Locale.Category.FORMAT), locale -> {
DecimalFormat numberFormat = new DecimalFormat(); // uses the necessary locale inside anyway
Expand Down

0 comments on commit d8a7623

Please sign in to comment.