Skip to content

Commit

Permalink
cleanup (#34)
Browse files Browse the repository at this point in the history
* Cleanup & minor fixes

* spotless
  • Loading branch information
RecursivePineapple authored Jan 24, 2025
1 parent 7da13d1 commit b6c7477
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,11 @@ public boolean apply(IBlockApplyContext ctx) {
if (!isAttunable) {
// change the part into the proper version
if (actualItem != null && (expectedItem == null || !Objects.equals(actualItem, expectedItem))) {
if (expectedStack != null && !partHost.canAddPart(expectedStack, dir)) {
ctx.error("Invalid location (" + MMUtils.getDirectionDisplayName(dir, true) + ") for part (" + expectedStack.getDisplayName() + ")");
continue;
}

if (expectedStack != null) {
var result = ctx.tryConsumeItems(Arrays.asList(new BigItemStack(expectedStack)), IPseudoInventory.CONSUME_SIMULATED);

if (!result.leftBoolean()) {
ctx.error("Could not extract item: " + expectedStack.getDisplayName());
ctx.warn("Could not extract item: " + expectedStack.getDisplayName());
continue;
}
}
Expand All @@ -188,10 +183,12 @@ public boolean apply(IBlockApplyContext ctx) {

if (actualItem == null && expectedItem != null) {
if (expectedStack != null && !partHost.canAddPart(expectedStack, dir)) {
ctx.error("Invalid location (" + MMUtils.getDirectionDisplayName(dir, true) + ") for part (" + expectedStack.getDisplayName() + ")");
ctx.error(
"Invalid location (" + MMUtils.getDirectionDisplayName(dir, true) + ") for part (" + expectedStack.getDisplayName() + ")"
);
continue;
}

if (!installPart(ctx, partHost, dir, expected, false)) { return false; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,77 +108,6 @@ public static interface IBlockApplyContext extends IPseudoInventory {
public void error(String message);
}

public static class BlockApplyContext implements IBlockApplyContext {

public World world;
public int x, y, z;
public EntityPlayer player;
public PendingBuild build;
public ItemStack manipulator;

public static final double EU_PER_ACTION = 8192;

@Override
public World getWorld() {
return world;
}

@Override
public int getX() {
return x;
}

@Override
public int getY() {
return y;
}

@Override
public int getZ() {
return z;
}

@Override
public TileEntity getTileEntity() {
return world.getTileEntity(x, y, z);
}

@Override
public EntityPlayer getRealPlayer() {
return player;
}

@Override
public boolean tryApplyAction(double complexity) {
return build.tryConsumePower(manipulator, x, y, z, EU_PER_ACTION * complexity);
}

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

@Override
public void givePlayerItems(List<BigItemStack> items) {
build.givePlayerItems(items);
}

@Override
public void givePlayerFluids(List<BigFluidStack> fluids) {
build.givePlayerFluids(fluids);
}

@Override
public void warn(String message) {
sendChatToPlayer(player, String.format("§cWarning at block %d, %d, %d: %s§r", 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));
}
}

/**
* A fake apply context that tracks which items were consumed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,27 +365,22 @@ public static BlockSpec fromBlock(BlockSpec pooled, World world, int x, int y, i
spec.objectId = GameRegistry.findUniqueIdentifierFor(block);
spec.block = block;

if (!MMUtils.isFree(block, blockMeta)) {
@Nullable
Item item = MMUtils.getItemFromBlock(block, blockMeta);
@Nullable
Item item = MMUtils.getItemFromBlock(block, blockMeta);

if (!MMUtils.isFree(block, blockMeta)) {
if (item == null) { return new BlockSpec().setObject(Blocks.air, 0); }

if (block != Blocks.wall_sign && block != Blocks.standing_sign) {
block = MMUtils.getBlockFromItem(item, item.getMetadata(blockMeta));
}
}

int itemMeta = block.getDamageValue(world, x, y, z);
int itemMeta = block.getDamageValue(world, x, y, z);

spec.metadata = itemMeta;
spec.item = Optional.ofNullable(item);
spec.itemId = item == null ? Optional.empty() : Optional.of(ItemId.create(item, itemMeta, null));
} else {
spec.metadata = 0;
spec.item = Optional.empty();
spec.itemId = Optional.empty();
spec.stack = Optional.empty();
}
spec.metadata = itemMeta;
spec.item = Optional.ofNullable(item);
spec.itemId = item == null ? Optional.empty() : Optional.of(ItemId.create(item, itemMeta, null));

if (Mods.ArchitectureCraft.isModLoaded()) {
spec.arch = ArchitectureCraftAnalysisResult.analyze(world.getTileEntity(x, y, z));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@EventBusSubscriber
public class MMKeyInputs {

public static final KeyBinding CONTROL = new KeyBinding("key.mm-ctrl", Keyboard.KEY_LCONTROL, "key.mm");
public static final KeyBinding CUT = new KeyBinding("key.mm-cut", Keyboard.KEY_X, "key.mm");
public static final KeyBinding COPY = new KeyBinding("key.mm-copy", Keyboard.KEY_C, "key.mm");
Expand Down Expand Up @@ -48,28 +48,28 @@ public static void onKeyPressed(KeyInputEvent event) {
if (state.config.placeMode != PlaceMode.MOVING) {
Messages.SetPlaceMode.sendToServer(PlaceMode.MOVING);
}

if (InteractionConfig.pasteAutoClear) {
Messages.ClearCoords.sendToServer();

if (InteractionConfig.resetTransform) {
Messages.ClearTransform.sendToServer();
}
}

Messages.MarkCut.sendToServer();

return;
}

if (COPY.isPressed()) {
if (state.config.placeMode != PlaceMode.COPYING) {
Messages.SetPlaceMode.sendToServer(PlaceMode.COPYING);
}

if (InteractionConfig.pasteAutoClear) {
Messages.ClearCoords.sendToServer();

if (InteractionConfig.resetTransform) {
Messages.ClearTransform.sendToServer();
}
Expand All @@ -79,21 +79,21 @@ public static void onKeyPressed(KeyInputEvent event) {

return;
}

if (PASTE.isPressed()) {
// set the mode to copying if we aren't in a mode supports pasting (moving/copying)
if (state.config.placeMode != PlaceMode.COPYING && state.config.placeMode != PlaceMode.MOVING) {
Messages.SetPlaceMode.sendToServer(PlaceMode.COPYING);
}

Messages.MarkPaste.sendToServer();

return;
}

if (RESET.isPressed()) {
Messages.ClearCoords.sendToServer();

if (InteractionConfig.resetTransform) {
Messages.ClearTransform.sendToServer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.entity.fx.WeightlessParticleFX;
import com.recursive_pineapple.matter_manipulator.GlobalMMConfig.RenderingConfig;
import com.recursive_pineapple.matter_manipulator.GlobalMMConfig;
import com.recursive_pineapple.matter_manipulator.GlobalMMConfig.RenderingConfig;
import com.recursive_pineapple.matter_manipulator.MMMod;
import com.recursive_pineapple.matter_manipulator.client.rendering.BoxRenderer;
import com.recursive_pineapple.matter_manipulator.common.building.BlockSpec;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class MMRenderer {
private static List<PendingBlock> analysisCache = null;

private static ItemMatterManipulator lastDrawer = null;

private static boolean wasValid = false;

private static final long ANALYSIS_INTERVAL_MS = 10_000;
Expand All @@ -77,10 +77,10 @@ public class MMRenderer {

private static boolean wasInUse = false;

private MMRenderer() { }
private MMRenderer() {}

/** Just loads the class */
public static void init() { }
public static void init() {}

public static void markNeedsRedraw() {
needsHintDraw = true;
Expand Down Expand Up @@ -168,7 +168,7 @@ private static void clear(EntityPlayer player) {
lastAnalyzedConfig = null;
lastPlayerPosition = null;
analysisCache = null;

needsHintDraw = false;
needsAnalysis = false;

Expand Down Expand Up @@ -565,7 +565,8 @@ private static void drawHints(
pendingBlock.z,
errors,
warnings,
RenderingConfig.hintsOnTop || state.config.placeMode == PlaceMode.EXCHANGING || (RenderingConfig.hintsOnTopAir && pendingBlock.spec.isAir()));
RenderingConfig.hintsOnTop || state.config.placeMode == PlaceMode.EXCHANGING || (RenderingConfig.hintsOnTopAir && pendingBlock.spec.isAir())
);
}

if (warnings != null) {
Expand Down Expand Up @@ -603,11 +604,26 @@ private static void drawHints(
StructureLibAPI.endHinting(player.worldObj);
}

private static final short[] WHITE = { 255, 255, 255, 255 };
private static final short[] WARNING = { 255, 170, 0, 255 };
private static final short[] ERROR = { 255, 85, 85, 255 };

private static void markHintDrawthrough(World world, EntityPlayer player, int x, int y, int z, LongOpenHashSet errors, LongOpenHashSet warnings, boolean drawOnTop) {
private static final short[] WHITE = {
255, 255, 255, 255
};
private static final short[] WARNING = {
255, 170, 0, 255
};
private static final short[] ERROR = {
255, 85, 85, 255
};

private static void markHintDrawthrough(
World world,
EntityPlayer player,
int x,
int y,
int z,
LongOpenHashSet errors,
LongOpenHashSet warnings,
boolean drawOnTop
) {
long packed = CoordinatePacker.pack(x, y, z);

short[] colour = WHITE;
Expand Down Expand Up @@ -680,4 +696,4 @@ private static void drawRulers(EntityPlayer player, Location l, boolean fromSurf
GL11.glDisable(GL11.GL_BLEND);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartItem;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@

public class MTEMMUplinkMEHatch extends MTEHatch implements IGridProxyable, IPowerChannelState, ICraftingProvider, ICraftingRequester {

public static final long REQUEST_TIMEOUT = 20 * 60;

protected BaseActionSource requestSource = null;
protected AENetworkProxy gridProxy = null;
protected boolean additionalConnection = false;
Expand Down

0 comments on commit b6c7477

Please sign in to comment.