Skip to content

Commit

Permalink
Cleanup (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple authored Jan 23, 2025
1 parent 7e98a77 commit c19d85a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ItemStack getStack(IPseudoInventory inv, boolean consume) {
var result = inv
.tryConsumeItems(MMUtils.mapToList(items, BigItemStack::new), IPseudoInventory.CONSUME_FUZZY);

if (!result.left()) { return null; }
if (!result.leftBoolean()) { return null; }

for (BigItemStack extracted : result.right()) {
ItemStack extractedStack = extracted.getItemStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.joml.Vector3i;

import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.booleans.BooleanObjectImmutablePair;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;

public class BlockAnalyzer {
Expand Down Expand Up @@ -154,7 +154,7 @@ public boolean tryApplyAction(double complexity) {
}

@Override
public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
public BooleanObjectImmutablePair<List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
return build.tryConsumeItems(items, flags);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public boolean tryApplyAction(double complexity) {
}

@Override
public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
public BooleanObjectImmutablePair<List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
boolean simulate = (flags & CONSUME_SIMULATED) != 0;
boolean fuzzy = (flags & CONSUME_FUZZY) != 0;

Expand Down Expand Up @@ -316,7 +316,7 @@ public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> item
requiredItems.addTo(id, req.getStackSize());
}

return Pair.of(true, items);
return BooleanObjectImmutablePair.of(true, items);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public boolean apply(IBlockApplyContext ctx) {
gte.setFrontFacing(mGTFacing.getDirection());
alignment.toolSetExtendedFacing(mGTFacing);
} else {
ctx.error("could not set direction to '" + mGTFacing.getLocalizedName() + "'");
ctx.error("Could not set direction to '" + mGTFacing.getLocalizedName() + "'");
}
}
} else {
Expand Down Expand Up @@ -451,12 +451,12 @@ private void installCover(IBlockApplyContext context, IGregTechTileEntity gte, F
ItemStack stack = cover.getCover();

if (!gte.canPlaceCoverItemAtSide(side, stack)) {
context.error("was not allowed to put cover on " + side.name().toLowerCase() + "side: " + stack.getDisplayName());
context.error("Was not allowed to put cover on " + side.name().toLowerCase() + "side: " + stack.getDisplayName());
return;
}

if (!context.tryConsumeItems(stack)) {
context.error("could not find cover: " + stack.getDisplayName());
context.error("Could not find cover: " + stack.getDisplayName());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.recursive_pineapple.matter_manipulator.common.utils.BigItemStack;
import com.recursive_pineapple.matter_manipulator.common.utils.MMUtils;

import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.booleans.BooleanObjectImmutablePair;

/**
* Something that can accept and provide items/fluids.
Expand Down Expand Up @@ -40,15 +40,15 @@ public interface IPseudoInventory {
* @return Key = whether the extract was successful. Value = the list of items extracted (only relevant for fuzzy
* mode).
*/
public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags);
public BooleanObjectImmutablePair<List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags);

/**
* Consumes a set of items.
*
* @return True when the items were successfully consumed.
*/
public default boolean tryConsumeItems(ItemStack... items) {
return tryConsumeItems(MMUtils.mapToList(items, BigItemStack::new), 0).first();
return tryConsumeItems(MMUtils.mapToList(items, BigItemStack::new), 0).leftBoolean();
}

public void givePlayerItems(List<BigItemStack> items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public default boolean isEquivalent(ImmutableBlockSpec other) {
return ItemStack.areItemStacksEqual(getStack(), other.getStack());
}

/** Returns true when this contains air. BlockSpecs may be air if an invalid block was analyzed. */
public default boolean isAir() {
return getObjectId() == null || getBlock() == null || getBlock() == Blocks.air;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static IItemProvider getProviderFor(ItemStack stack, boolean fuzzy) {
*/
public boolean apply(IBlockApplyContext context, IInventory inv, boolean consume, boolean simulate) {
if (inv.getSizeInventory() != mItems.length) {
context.warn("inventory was the wrong size (expected " + mItems.length + ", was " + inv.getSizeInventory() + ")");
context.warn("Inventory was the wrong size (expected " + mItems.length + ", was " + inv.getSizeInventory() + ")");
return false;
}

Expand All @@ -100,7 +100,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 + ": " + stack.getDisplayName());
continue;
}

Expand All @@ -114,14 +114,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 + ": " + target.toString());
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: " + target.toString());
success = false;
} else {
if (!simulate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.recursive_pineapple.matter_manipulator.common.utils.Mods;
import com.recursive_pineapple.matter_manipulator.common.utils.Mods.Names;

import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.booleans.BooleanObjectImmutablePair;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;

/**
Expand All @@ -65,9 +65,9 @@ public MMInventory(EntityPlayer player, MMState state, ManipulatorTier tier) {
}

@Override
public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
public BooleanObjectImmutablePair<List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
if ((flags & CONSUME_IGNORE_CREATIVE) == 0 && player.capabilities.isCreativeMode) {
return Pair.of(true, items);
return BooleanObjectImmutablePair.of(true, items);
} else {
List<BigItemStack> simulated = MMUtils.mapToList(items, BigItemStack::copy);
List<BigItemStack> extracted = new ArrayList<>();
Expand All @@ -84,10 +84,10 @@ public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> item

// if we aren't allowed to partially consume items, make sure everything was consumed
if ((flags & CONSUME_PARTIAL) == 0) {
if (simulated.stream().anyMatch(s -> s.getStackSize() > 0)) { return Pair.of(false, null); }
if (simulated.stream().anyMatch(s -> s.getStackSize() > 0)) { return BooleanObjectImmutablePair.of(false, null); }
}

if ((flags & CONSUME_SIMULATED) != 0) { return Pair.of(true, extracted); }
if ((flags & CONSUME_SIMULATED) != 0) { return BooleanObjectImmutablePair.of(true, extracted); }

simulated = MMUtils.mapToList(items, BigItemStack::copy);
extracted.clear();
Expand Down Expand Up @@ -117,7 +117,7 @@ public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> item
merged.incStackSize(ex.getStackSize());
}

return Pair.of(true, new ArrayList<>(out.values()));
return BooleanObjectImmutablePair.of(true, new ArrayList<>(out.values()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class RefCell {
try {
prop.setValueFromText(world, x, y, z, value);
} catch (Exception e) {
context.error("could not apply property " + property + ": " + e.getMessage());
context.error("Could not apply property " + property + ": " + e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.recursive_pineapple.matter_manipulator.common.utils.Mods;
import com.recursive_pineapple.matter_manipulator.common.utils.Mods.Names;

import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.booleans.BooleanObjectImmutablePair;

/**
* Handles all building logic.
Expand Down Expand Up @@ -464,7 +464,7 @@ public boolean tryApplyAction(double complexity) {
}

@Override
public Pair<Boolean, List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
public BooleanObjectImmutablePair<List<BigItemStack>> tryConsumeItems(List<BigItemStack> items, int flags) {
return PendingBuild.this.tryConsumeItems(items, flags);
}

Expand All @@ -486,7 +486,13 @@ public void warn(String message) {
if (GregTech.isModLoaded()) blockName = getGTBlockName(pendingBlock);

if (blockName == null) {
blockName = BlockSpec.fromBlock(null, player.worldObj, pendingBlock.x, pendingBlock.y, pendingBlock.z).getDisplayName();
BlockSpec spec = BlockSpec.fromBlock(null, player.worldObj, pendingBlock.x, pendingBlock.y, pendingBlock.z);

if (MMUtils.AE_BLOCK_CABLE.matches(spec)) {
blockName = MMUtils.AE_BLOCK_CABLE.get().asSpec().getDisplayName();
} else {
blockName = spec.getDisplayName();
}
}
}

Expand All @@ -511,8 +517,12 @@ public void error(String message) {
if (pendingBlock.isInWorld(player.worldObj)) {
if (GregTech.isModLoaded()) blockName = getGTBlockName(pendingBlock);

if (blockName == null) {
blockName = BlockSpec.fromBlock(null, player.worldObj, pendingBlock.x, pendingBlock.y, pendingBlock.z).getDisplayName();
BlockSpec spec = BlockSpec.fromBlock(null, player.worldObj, pendingBlock.x, pendingBlock.y, pendingBlock.z);

if (MMUtils.AE_BLOCK_CABLE.matches(spec)) {
blockName = MMUtils.AE_BLOCK_CABLE.get().asSpec().getDisplayName();
} else {
blockName = spec.getDisplayName();
}
}

Expand Down

0 comments on commit c19d85a

Please sign in to comment.