Skip to content

Commit

Permalink
Merge branch 'RecursivePineapple:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple authored Feb 19, 2025
2 parents a3f5050 + 11c9928 commit 69a554b
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class GlobalMMConfig {

@Config(modid = Names.MATTER_MANIPULATOR, category = "Interaction")
@Config(modid = Names.MATTER_MANIPULATOR, category = "interaction")
public static class InteractionConfig {

@Config.Comment("Clear the paste region when the copy or cut regions are marked")
Expand All @@ -21,7 +21,7 @@ public static class InteractionConfig {
public static boolean resetTransform;
}

@Config(modid = Names.MATTER_MANIPULATOR, category = "Rendering")
@Config(modid = Names.MATTER_MANIPULATOR, category = "rendering")
public static class RenderingConfig {

@Config.Comment("Controls how many blocks are shown in the preview. Client only.")
Expand All @@ -45,21 +45,38 @@ public static class RenderingConfig {
public static boolean hintsOnTopAir;
}

@Config(modid = Names.MATTER_MANIPULATOR, category = "Debug")
@Config(modid = Names.MATTER_MANIPULATOR, category = "debug")
public static class DebugConfig {

@Config.DefaultBoolean(false)
@Config.Name("Enable Debug Logging")
public static boolean debug;
}

@Config(modid = Names.MATTER_MANIPULATOR, category = "building")
public static class BuildingConfig {

@Config.Comment("Empty ME Output Hatches/Busses when they're removed. Server only.")
@Config.DefaultBoolean(true)
@Config.Name("Empty ME Outputs")
public static boolean meEmptying;

@Config.Comment("High values may cause world desync and lag. Server only. Requires restart.")
@Config.DefaultInt(256)
@Config.RangeInt(min = 1)
@Config.Name("MK3 Block Place Speed")
@Config.RequiresMcRestart
public static int mk3BlocksPerPlace;
}

public static boolean DEVENV = false;

public static void init() {
try {
ConfigurationManager.registerConfig(InteractionConfig.class);
ConfigurationManager.registerConfig(RenderingConfig.class);
ConfigurationManager.registerConfig(DebugConfig.class);
ConfigurationManager.registerConfig(BuildingConfig.class);
} catch (ConfigException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public boolean apply(IBlockApplyContext ctx) {
customName.setCustomName(mAECustomName);
}

boolean success = true;

// add/remove/update ae parts and cables
if (te instanceof IPartHost partHost && mAEParts != null) {
for (ForgeDirection dir : AEAnalysisResult.ALL_DIRECTIONS) {
Expand Down Expand Up @@ -189,19 +191,25 @@ public boolean apply(IBlockApplyContext ctx) {
continue;
}

if (!installPart(ctx, partHost, dir, expected, false)) { return false; }
if (!installPart(ctx, partHost, dir, expected, false)) {
success = false;
continue;
}
}
}

if (expected != null) {
if (!expected.updatePart(ctx, partHost, dir)) { return false; }
if (!expected.updatePart(ctx, partHost, dir)) {
success = false;
continue;
}
}

Platform.notifyBlocksOfNeighbors(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
}

return true;
return success;
}

private void removePart(IBlockApplyContext context, IPartHost partHost, ForgeDirection side, boolean simulate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;

import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
Expand All @@ -26,7 +25,6 @@
import appeng.parts.p2p.PartP2PTunnel;
import appeng.parts.p2p.PartP2PTunnelNormal;

import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap;
import com.recursive_pineapple.matter_manipulator.common.building.BlockAnalyzer.IBlockApplyContext;
import com.recursive_pineapple.matter_manipulator.common.utils.MMUtils;

Expand Down Expand Up @@ -143,6 +141,8 @@ public boolean isAttunable() {
public boolean updatePart(IBlockApplyContext context, IPartHost partHost, ForgeDirection side) {
IPart part = partHost.getPart(side);

boolean success = true;

if (part instanceof PartP2PTunnelNormal && isAttunable()) {
partHost.removePart(side, true);

Expand All @@ -154,8 +154,8 @@ public boolean updatePart(IBlockApplyContext context, IPartHost partHost, ForgeD
tunnel.output = mP2POutput;

try {
final P2PCache p2p = tunnel.getProxy()
.getP2P();
final P2PCache p2p = tunnel.getProxy().getP2P();

// calls setFrequency
p2p.updateFreq(tunnel, mP2PFreq);
} catch (final GridAccessException e) {
Expand All @@ -172,33 +172,24 @@ public boolean updatePart(IBlockApplyContext context, IPartHost partHost, ForgeD

if (part instanceof IConfigurableObject configurable && configurable.getConfigManager() != null) {
NBTTagCompound settings = mSettings == null ? new NBTTagCompound() : mSettings;
configurable.getConfigManager()
.readFromNBT(settings);
configurable.getConfigManager().readFromNBT(settings);
}

if (part instanceof ISegmentedInventory segmentedInventory) {
if (segmentedInventory.getInventoryByName("upgrades") instanceof UpgradeInventory upgradeInv) {
ItemStackMap<Long> targetMap = MMUtils.getItemStackHistogram(
Arrays.stream(mAEUpgrades)
.map(PortableItemStack::toStack)
.collect(Collectors.toList())
);
ItemStackMap<Long> actualMap = MMUtils
.getItemStackHistogram(Arrays.asList(MMUtils.inventoryToArray(upgradeInv)));

if (!targetMap.equals(actualMap)) {
if (!MMUtils.installUpgrades(context, upgradeInv, mAEUpgrades, true, false)) { return false; }
if (!MMUtils.installUpgrades(context, upgradeInv, mAEUpgrades, true, false)) {
success = false;
}
}

IInventory config = segmentedInventory.getInventoryByName("config");
if (config != null) {
mConfig.apply(context, config, false, false);
if (!mConfig.apply(context, config, false, false)) success = false;
}

IInventory patterns = segmentedInventory.getInventoryByName("patterns");
if (mAEPatterns != null && patterns != null) {
mAEPatterns.apply(context, patterns, true, false);
if (!mAEPatterns.apply(context, patterns, true, false)) success = false;
}
}

Expand All @@ -210,7 +201,7 @@ public boolean updatePart(IBlockApplyContext context, IPartHost partHost, ForgeD
priorityHost.setPriority(priority);
}

return true;
return success;
}

/**
Expand All @@ -226,28 +217,20 @@ public boolean getRequiredItemsForExistingPart(
) {
IPart part = partHost.getPart(side);

boolean success = true;

if (part instanceof ISegmentedInventory segmentedInventory) {
if (segmentedInventory.getInventoryByName("upgrades") instanceof UpgradeInventory upgradeInv) {
ItemStackMap<Long> targetMap = MMUtils.getItemStackHistogram(
Arrays.stream(mAEUpgrades)
.map(PortableItemStack::toStack)
.collect(Collectors.toList())
);
ItemStackMap<Long> actualMap = MMUtils
.getItemStackHistogram(Arrays.asList(MMUtils.inventoryToArray(upgradeInv)));

if (!targetMap.equals(actualMap)) {
if (!MMUtils.installUpgrades(context, upgradeInv, mAEUpgrades, true, true)) { return false; }
}
if (!MMUtils.installUpgrades(context, upgradeInv, mAEUpgrades, true, false)) success = false;
}

IInventory patterns = segmentedInventory.getInventoryByName("patterns");
if (mAEPatterns != null && patterns != null) {
mAEPatterns.apply(context, patterns, true, true);
if (!mAEPatterns.apply(context, patterns, true, true)) success = false;
}
}

return true;
return success;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import appeng.helpers.ICustomNameObject;
import appeng.parts.AEBasePart;

import com.recursive_pineapple.matter_manipulator.GlobalMMConfig.BuildingConfig;
import com.recursive_pineapple.matter_manipulator.asm.Optional;
import com.recursive_pineapple.matter_manipulator.common.items.manipulator.ItemMatterManipulator;
import com.recursive_pineapple.matter_manipulator.common.items.manipulator.ItemMatterManipulator.ManipulatorTier;
Expand Down Expand Up @@ -131,7 +132,7 @@ protected void removeBlock(World world, int x, int y, int z, ImmutableBlockSpec
boolean eio = Mods.EnderIO.isModLoaded();

if (ae && gt) emptySuperchest(te);
if (ae && gt) emptyMEOutput(te);
if (ae && gt && BuildingConfig.meEmptying) emptyMEOutput(te);
emptyTileInventory(te);
emptyTank(te);
if (gt) removeCovers(te);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.gtnewhorizon.structurelib.alignment.IAlignment;
import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import com.gtnewhorizon.structurelib.alignment.enumerable.Flip;
import com.recursive_pineapple.matter_manipulator.MMMod;
import com.recursive_pineapple.matter_manipulator.common.building.BlockAnalyzer.IBlockApplyContext;
import com.recursive_pineapple.matter_manipulator.common.items.manipulator.Transform;
Expand Down Expand Up @@ -301,11 +302,18 @@ public boolean apply(IBlockApplyContext ctx) {

if (mGTFacing != null && alignment != null) {

if (alignment.isNewExtendedFacingValid(mGTFacing)) {
gte.setFrontFacing(mGTFacing.getDirection());
alignment.toolSetExtendedFacing(mGTFacing);
ExtendedFacing facing = mGTFacing;

// maintenance hatches can be rotated but not flipped
if (!alignment.isNewExtendedFacingValid(facing)) {
facing = ExtendedFacing.of(mGTFacing.getDirection(), mGTFacing.getRotation(), Flip.NONE);
}

if (alignment.isNewExtendedFacingValid(facing)) {
gte.setFrontFacing(facing.getDirection());
alignment.toolSetExtendedFacing(facing);
} else {
ctx.error("Could not set direction to '" + mGTFacing.getLocalizedName() + "'");
ctx.error("Could not set direction to '" + facing.getLocalizedName() + "'");
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class MMInventory implements IPseudoInventory {

private boolean printedUplinkWarning = false;

private HashSet<IStorageGrid> visitedGrids = new HashSet<>();
private final HashSet<IStorageGrid> visitedGrids = new HashSet<>();

public MMInventory(EntityPlayer player, MMState state, ManipulatorTier tier) {
this.player = player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,9 @@ public boolean equals(Object obj) {
*/
public static Comparator<PendingBlock> getComparator() {
return Comparator.comparingInt((PendingBlock b) -> b.buildOrder)
.thenComparing(Comparator.comparing(b -> b.spec, ImmutableBlockSpec.getComparator()))
.thenComparingLong(b -> {
int chunkX = b.x >> 4;
int chunkZ = b.z >> 4;

return (long) chunkX | (long) (chunkZ << 32);
})
.thenComparing(b -> b.spec, ImmutableBlockSpec.getComparator())
.thenComparingInt(b -> b.x >> 4)
.thenComparingInt(b -> b.z >> 4)
.thenComparingInt(b -> Objects.hash(b.gt, b.ae, b.arch, b.mp, b.inventory));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import com.gtnewhorizons.modularui.common.widget.TextWidget;
import com.gtnewhorizons.modularui.common.widget.VanillaButtonWidget;
import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget;
import com.recursive_pineapple.matter_manipulator.GlobalMMConfig;
import com.recursive_pineapple.matter_manipulator.MMMod;
import com.recursive_pineapple.matter_manipulator.client.gui.DirectionDrawable;
import com.recursive_pineapple.matter_manipulator.client.gui.RadialMenuBuilder;
Expand Down Expand Up @@ -145,10 +146,30 @@ public ItemMatterManipulator(ManipulatorTier tier) {
public static enum ManipulatorTier {

// spotless:off
Tier0(32, 16, 20, 3, 1_000_000d, ALLOW_GEOMETRY),
Tier1(64, 32, 10, 5, 100_000_000d, ALLOW_GEOMETRY | CONNECTS_TO_AE | ALLOW_REMOVING | ALLOW_EXCHANGING | ALLOW_CONFIGURING | ALLOW_CABLES),
Tier2(128, 64, 5, 6, 1_000_000_000d, ALLOW_GEOMETRY | CONNECTS_TO_AE | ALLOW_REMOVING | ALLOW_EXCHANGING | ALLOW_CONFIGURING | ALLOW_CABLES | ALLOW_COPYING | ALLOW_MOVING),
Tier3(-1, 256, 5, 7, 10_000_000_000d, ALLOW_GEOMETRY | CONNECTS_TO_AE | ALLOW_REMOVING | ALLOW_EXCHANGING | ALLOW_CONFIGURING | ALLOW_CABLES | ALLOW_COPYING | ALLOW_MOVING | CONNECTS_TO_UPLINK);
Tier0(
32,
16, 20,
3,
1_000_000d,
ALLOW_GEOMETRY),
Tier1(
64,
32, 10,
5,
100_000_000d,
ALLOW_GEOMETRY | CONNECTS_TO_AE | ALLOW_REMOVING | ALLOW_EXCHANGING | ALLOW_CONFIGURING | ALLOW_CABLES),
Tier2(
128,
64, 5,
6,
1_000_000_000d,
ALLOW_GEOMETRY | CONNECTS_TO_AE | ALLOW_REMOVING | ALLOW_EXCHANGING | ALLOW_CONFIGURING | ALLOW_CABLES | ALLOW_COPYING | ALLOW_MOVING),
Tier3(
-1,
GlobalMMConfig.BuildingConfig.mk3BlocksPerPlace, 5,
7,
10_000_000_000d,
ALLOW_GEOMETRY | CONNECTS_TO_AE | ALLOW_REMOVING | ALLOW_EXCHANGING | ALLOW_CONFIGURING | ALLOW_CABLES | ALLOW_COPYING | ALLOW_MOVING | CONNECTS_TO_UPLINK);
// spotless:on

public final int tier = ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,42 @@

import net.minecraftforge.common.util.ForgeDirection;

import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.IHasInventory;
import gregtech.common.tileentities.machines.MTEHatchOutputBusME;
import gregtech.common.tileentities.machines.MTEHatchOutputME;

import com.google.common.collect.ImmutableList;
import com.recursive_pineapple.matter_manipulator.MMMod;
import com.recursive_pineapple.matter_manipulator.asm.Optional;
import com.recursive_pineapple.matter_manipulator.common.utils.Mods.Names;

import tectech.thing.metaTileEntity.hatch.MTEHatchRack;

public enum InventoryAdapter {

GTUnrestricted {

@Override
public boolean canHandle(IInventory inv) {
return GregTech.isModLoaded() && canHandleImpl(inv);
}

@Optional(Names.GREG_TECH)
private boolean canHandleImpl(IInventory inv) {
if (inv instanceof IGregTechTileEntity igte) {
IMetaTileEntity imte = igte.getMetaTileEntity();

if (imte instanceof MTEHatchOutputBusME) return true;
if (imte instanceof MTEHatchOutputME) return true;
if (imte instanceof MTEHatchRack) return true;
}

return false;
}
},

GT {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;

import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -168,4 +170,13 @@ public ItemStack getItemStack(int stackSize) {
itemStack.setTagCompound(nbt == null ? null : (NBTTagCompound) nbt.copy());
return itemStack;
}

public boolean isSameAs(ItemStack stack) {
if (stack == null) return false;
if (item() != stack.getItem()) return false;
if (metaData() != Items.feather.getDamage(stack)) return false;
if (!Objects.equals(nbt(), stack.getTagCompound())) return false;

return true;
}
}
Loading

0 comments on commit 69a554b

Please sign in to comment.