Skip to content

Commit

Permalink
add easyPlaceMode++
Browse files Browse the repository at this point in the history
  • Loading branch information
aria1th committed Oct 6, 2022
1 parent 4154d0e commit c50221e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2G
minecraft_version_out =1.19

# Mod Properties
mod_version = 6.6.0
mod_version = 6.8.0
maven_group = net.fabricmc
archives_base_name = litematica-printer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class LitematicaMixinMod implements ModInitializer {
public static final ConfigBoolean USE_INVENTORY_CACHE = new ConfigBoolean("printerUseInventoryCache", true, "Uses Inventory cache instead of litematica's inventory utils.");
public static final ConfigBoolean VERIFY_INVENTORY = new ConfigBoolean("verifierFindInventoryContents", true, "Schematic verifier will show blocks with inventory as wrong state.");
public static final ConfigBoolean PRINTER_OFF = new ConfigBoolean("printerOff", false, "Disables printer.");
public static final ConfigBoolean PRINTER_ONLY_FAKE_ROTATION_MODE = new ConfigBoolean("easyPlaceMode++", false, "Disables printer and only make fake rotation work.");
public static final ConfigBoolean INVENTORY_OPERATIONS = new ConfigBoolean("printerAllowInventoryOperations", false, "Printer will try to fill filters when screen is open and stop other actions");
public static final ConfigBoolean INVENTORY_OPERATIONS_CLOSE_SCREEN = new ConfigBoolean("inventoryCloseScreenAfterDone", false, "Screen will be closed after inventory filling operations");
public static final ConfigInteger INVENTORY_OPERATIONS_WAIT = new ConfigInteger("printerInventoryScreenWait", 200, 0, 8000, "Time(ms) to wait screen to be opened and synced");
Expand Down Expand Up @@ -60,6 +61,7 @@ public class LitematicaMixinMod implements ModInitializer {
VERIFY_INVENTORY,
USE_INVENTORY_CACHE,
PRINTER_OFF,
PRINTER_ONLY_FAKE_ROTATION_MODE,
DISABLE_SYNC,
DEBUG_MESSAGE,
DEBUG_EXTRA_MESSAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.PRINTER_ONLY_FAKE_ROTATION_MODE;

@Mixin(value = WorldUtils.class, remap = false, priority = 1010)
public class WorldUtilsMixin {
private static boolean hasSent = false;
Expand All @@ -29,26 +31,31 @@ private static void onDoEasyPlaceAction(MinecraftClient mc, CallbackInfoReturnab
if (mc.player == null) {
return;
}
if (LitematicaMixinMod.PRINTER_OFF.getBooleanValue()) {
return;
if (PRINTER_ONLY_FAKE_ROTATION_MODE.getBooleanValue()) {
cir.setReturnValue(Printer.doEasyPlaceFakeRotation(mc));
}
ActionResult defaultResult = ActionResult.SUCCESS;
try {
defaultResult = Printer.doPrinterAction(mc);
} catch (NullPointerException e) {
//in case of NPE, print log instead
MessageHolder.sendMessageUncheckedUnique(mc.player, e.getMessage());
if (!hasSent && mc.player != null) {
mc.player.sendMessage(Text.of("Null pointer exception has occured, please upload log at https://github.com/aria1th/litematica-printer/issues"));
hasSent = true;
else {
if (LitematicaMixinMod.PRINTER_OFF.getBooleanValue()) {
return;
}
} catch (AssertionError e) {
MessageHolder.sendOrderMessage("Order error happened " + e.getMessage());
MessageHolder.sendMessageUncheckedUnique(mc.player, "Order Error Happened " + e.getMessage());
cir.setReturnValue(ActionResult.FAIL);
return;
ActionResult defaultResult = ActionResult.SUCCESS;
try {
defaultResult = Printer.doPrinterAction(mc);
} catch (NullPointerException e) {
//in case of NPE, print log instead
MessageHolder.sendMessageUncheckedUnique(mc.player, e.getMessage());
if (!hasSent && mc.player != null) {
mc.player.sendMessage(Text.of("Null pointer exception has occured, please upload log at https://github.com/aria1th/litematica-printer/issues"));
hasSent = true;
}
} catch (AssertionError e) {
MessageHolder.sendOrderMessage("Order error happened " + e.getMessage());
MessageHolder.sendMessageUncheckedUnique(mc.player, "Order Error Happened " + e.getMessage());
cir.setReturnValue(ActionResult.FAIL);
return;
}
cir.setReturnValue(defaultResult);
//return defaultResult;
}
cir.setReturnValue(defaultResult);
//return defaultResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,29 @@ public static void tick(ClientPlayNetworkHandler clientPlayNetworkHandler, Clien
previousFakePitch = playerEntity.getPitch();
previousFakeYaw = playerEntity.getYaw();
}
if (requestedTicks == 0 && PRINTER_ONLY_FAKE_ROTATION_MODE.getBooleanValue()){
placeFromQueue();
}
requestedTicks = requestedTicks - 1;
blockPlacedInTick = 0;
}

public static void placeFromQueue() {
if (requestedTicks != 0) {
return;
}
PosWithBlock obj = waitingQueue.poll();
if (obj != null) {
MessageHolder.sendOrderMessage("found block to place");
if (canPlace(obj.blockState, obj.pos)) {
placeBlock(obj.pos, obj.blockState);
return;
}
else {
MessageHolder.sendOrderMessage("found block to place but can't place");
}
}
waitingQueue.clear();
}
public static boolean emptyWaitingQueue() {
if (requestedTicks != 0) {
return false;
Expand Down Expand Up @@ -274,6 +293,7 @@ private static Direction[] listClosest(Direction first, Direction second, Direct
synchronized public static boolean request(BlockState blockState, BlockPos blockPos) {
// instant
if (!canPlace(blockState, blockPos) || blockState.isAir() || MaterialCache.getInstance().getRequiredBuildItemForState(blockState, SchematicWorldHandler.getSchematicWorld(), blockPos).getItem() == Items.AIR) {
MessageHolder.sendOrderMessage("Cannot place "+ blockState.toString() + " at " + blockPos.toShortString());
return false;
}
if (blockState.isOf(Blocks.GRINDSTONE)) {
Expand Down Expand Up @@ -368,6 +388,7 @@ synchronized public static boolean request(BlockState blockState, BlockPos block
} else {
//delay
if (isHandling() && (lookRefdir != fakeDirection || fp != fakePitch || fy != fakeYaw || !canPlaceWallMounted(blockState))) {
MessageHolder.sendOrderMessage("Cannot handle "+ blockState + " at " + blockPos.toShortString());
return false;
}
if (requestedTicks == 0 && fakeDirection == lookRefdir && fp == fakePitch && fy == fakeYaw) {
Expand All @@ -377,7 +398,13 @@ synchronized public static boolean request(BlockState blockState, BlockPos block
if (waitingQueue.isEmpty()) {
request(fy, fp, lookRefdir, LitematicaMixinMod.FAKE_ROTATION_TICKS.getIntegerValue(), false);
pickFirst(blockState, blockPos);
waitingQueue.offer(new PosWithBlock(blockPos, blockState));
boolean offered = waitingQueue.offer(new PosWithBlock(blockPos, blockState));
if (offered){
MessageHolder.sendOrderMessage("Offered "+ blockState + " at " + blockPos.toShortString());
}
else {
MessageHolder.sendOrderMessage("Cannot offer "+ blockState + " at " + blockPos.toShortString());
}
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,34 @@ synchronized public static boolean doSchematicWorldPickBlock(MinecraftClient mc,
}
return false;
}

public static ActionResult doEasyPlaceFakeRotation(MinecraftClient mc) { //force normal easyplace action, ignore condition checks
RayTraceWrapper traceWrapper = RayTraceUtils.getGenericTrace(mc.world, mc.player, 6);
FakeAccurateBlockPlacement.requestedTicks = Math.max(-2, FakeAccurateBlockPlacement.requestedTicks);
if (traceWrapper == null) {
return ActionResult.PASS;
}
BlockHitResult trace = traceWrapper.getBlockHitResult();
if (trace == null) {
return ActionResult.PASS;
}
World world = SchematicWorldHandler.getSchematicWorld();
World clientWorld = mc.world;
BlockPos blockPos = trace.getBlockPos();
if (isPositionCached(blockPos, false)){
return ActionResult.PASS;
}
BlockState schematicState = world.getBlockState(blockPos);
BlockState clientState = clientWorld.getBlockState(blockPos);
if (schematicState.getBlock().getName().equals(clientState.getBlock().getName()) || schematicState.isAir()) {
return ActionResult.FAIL;
}
if (FakeAccurateBlockPlacement.canHandleOther(schematicState.getBlock().asItem()) && canPickBlock(mc, schematicState, blockPos)) {
MessageHolder.sendOrderMessage("Requested " + schematicState + " at " +blockPos.toShortString());
FakeAccurateBlockPlacement.request(schematicState, blockPos);
return ActionResult.SUCCESS;
}
return ActionResult.FAIL;
}
public static ActionResult doEasyPlaceNormally(MinecraftClient mc) { //force normal easyplace action, ignore condition checks
RayTraceWrapper traceWrapper = RayTraceUtils.getGenericTrace(mc.world, mc.player, 6);
if (traceWrapper == null) {
Expand Down

0 comments on commit c50221e

Please sign in to comment.