Skip to content

Commit

Permalink
Merge branch 'printing' into printing_1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Dec 17, 2021
2 parents 46ace77 + 62d2080 commit db31de8
Show file tree
Hide file tree
Showing 12 changed files with 475 additions and 349 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.12.10

# Mod Properties
mod_version = 2.0.0
mod_version = 2.0
maven_group = net.fabricmc
archives_base_name = litematica-printer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,120 +18,32 @@ public class LitematicaMixinMod implements ModInitializer {
public static final ConfigInteger PRINT_INTERVAL = new ConfigInteger( "printInterval", 4, 2, 20, "Print interval in game ticks. Lower values mean faster printing speed.\nIf the printer creates \"ghost blocks\", raise this value.");
public static final ConfigInteger PRINTING_RANGE = new ConfigInteger("printingRange", 2, 1, 6, "Printing block place range\nLower values are recommended for servers.");
// public static final ConfigBoolean PRINT_WATER = new ConfigBoolean("printWater", false, "Whether or not the printer should place water\n source blocks or make blocks waterlogged.");
public static final ConfigBoolean PRINT_IN_AIR = new ConfigBoolean("printInAir", false, "Whether or not the printer should place blocks without anything to build on.\nBe aware that some anti-cheat plugins might notice this.");
// public static final ConfigBoolean PRINT_IN_AIR = new ConfigBoolean("printInAir", false, "Whether or not the printer should place blocks without anything to build on.\nBe aware that some anti-cheat plugins might notice this.");
public static final ConfigBoolean PRINT_MODE = new ConfigBoolean("printingMode", false, "Autobuild / print loaded selection.\nBe aware that some servers and anticheat plugins do not allow printing.");
public static final ConfigBoolean REPLACE_FLUIDS = new ConfigBoolean("replaceFluids", false, "Whether or not fluid source blocks should be replaced by the printer.");

public static final ImmutableList<IConfigBase> betterConfigList = ImmutableList.of(
Configs.Generic.AREAS_PER_WORLD,
//BETTER_RENDER_ORDER,
Configs.Generic.CHANGE_SELECTED_CORNER,
Configs.Generic.EASY_PLACE_MODE,
Configs.Generic.EASY_PLACE_HOLD_ENABLED,
Configs.Generic.EXECUTE_REQUIRE_TOOL,
Configs.Generic.FIX_RAIL_ROTATION,
Configs.Generic.LOAD_ENTIRE_SCHEMATICS,
Configs.Generic.PASTE_IGNORE_INVENTORY,
Configs.Generic.PICK_BLOCK_ENABLED,
Configs.Generic.PLACEMENT_RESTRICTION,
Configs.Generic.RENDER_MATERIALS_IN_GUI,
Configs.Generic.RENDER_THREAD_NO_TIMEOUT,
Configs.Generic.TOOL_ITEM_ENABLED,
public static ImmutableList<IConfigBase> getConfigList() {
List<IConfigBase> list = new java.util.ArrayList<>(List.copyOf(Configs.Generic.OPTIONS));
list.add(PRINT_INTERVAL);
list.add(PRINTING_RANGE);
// list.add(PRINT_IN_AIR);
list.add(PRINT_MODE);
list.add(REPLACE_FLUIDS);

Configs.Generic.PASTE_REPLACE_BEHAVIOR,
Configs.Generic.SELECTION_CORNERS_MODE,

Configs.Generic.PASTE_COMMAND_INTERVAL,
Configs.Generic.PASTE_COMMAND_LIMIT,
Configs.Generic.PASTE_COMMAND_SETBLOCK,
Configs.Generic.PICK_BLOCKABLE_SLOTS,
Configs.Generic.TOOL_ITEM,

PRINT_INTERVAL,
PRINTING_RANGE,
// PRINT_WATER,
PRINT_IN_AIR,
PRINT_MODE,
REPLACE_FLUIDS
);
return ImmutableList.copyOf(list);
}

// Hotkeys
public static final ConfigHotkey TOGGLE_PRINTING_MODE = new ConfigHotkey("togglePrintingMode", "M,O", "Allows quickly toggling on/off Printing mode");

public static final List<ConfigHotkey> betterHotkeyList = ImmutableList.of(
Hotkeys.ADD_SELECTION_BOX,
Hotkeys.CLONE_SELECTION,
Hotkeys.DELETE_SELECTION_BOX,
Hotkeys.EASY_PLACE_ACTIVATION,
Hotkeys.EASY_PLACE_TOGGLE,
Hotkeys.EXECUTE_OPERATION,
Hotkeys.INVERT_GHOST_BLOCK_RENDER_STATE,
Hotkeys.INVERT_OVERLAY_RENDER_STATE,
Hotkeys.LAYER_MODE_NEXT,
Hotkeys.LAYER_MODE_PREVIOUS,
Hotkeys.LAYER_NEXT,
Hotkeys.LAYER_PREVIOUS,
Hotkeys.LAYER_SET_HERE,
Hotkeys.NUDGE_SELECTION_NEGATIVE,
Hotkeys.NUDGE_SELECTION_POSITIVE,
Hotkeys.MOVE_ENTIRE_SELECTION,
Hotkeys.OPEN_GUI_AREA_SETTINGS,
Hotkeys.OPEN_GUI_LOADED_SCHEMATICS,
Hotkeys.OPEN_GUI_MAIN_MENU,
Hotkeys.OPEN_GUI_MATERIAL_LIST,
Hotkeys.OPEN_GUI_PLACEMENT_SETTINGS,
Hotkeys.OPEN_GUI_SCHEMATIC_PLACEMENTS,
Hotkeys.OPEN_GUI_SCHEMATIC_PROJECTS,
Hotkeys.OPEN_GUI_SCHEMATIC_VERIFIER,
Hotkeys.OPEN_GUI_SELECTION_MANAGER,
Hotkeys.OPEN_GUI_SETTINGS,
Hotkeys.OPERATION_MODE_CHANGE_MODIFIER,
Hotkeys.PICK_BLOCK_FIRST,
Hotkeys.PICK_BLOCK_LAST,
Hotkeys.PICK_BLOCK_TOGGLE,
Hotkeys.RENDER_INFO_OVERLAY,
Hotkeys.RENDER_OVERLAY_THROUGH_BLOCKS,
Hotkeys.RERENDER_SCHEMATIC,
Hotkeys.SAVE_AREA_AS_IN_MEMORY_SCHEMATIC,
Hotkeys.SAVE_AREA_AS_SCHEMATIC_TO_FILE,
Hotkeys.SCHEMATIC_REBUILD_BREAK_ALL,
Hotkeys.SCHEMATIC_REBUILD_BREAK_ALL_EXCEPT,
Hotkeys.SCHEMATIC_REBUILD_BREAK_DIRECTION,
Hotkeys.SCHEMATIC_REBUILD_REPLACE_ALL,
Hotkeys.SCHEMATIC_REBUILD_REPLACE_DIRECTION,
Hotkeys.SCHEMATIC_VERSION_CYCLE_MODIFIER,
Hotkeys.SCHEMATIC_VERSION_CYCLE_NEXT,
Hotkeys.SCHEMATIC_VERSION_CYCLE_PREVIOUS,
Hotkeys.SELECTION_GRAB_MODIFIER,
Hotkeys.SELECTION_GROW_HOTKEY,
Hotkeys.SELECTION_GROW_MODIFIER,
Hotkeys.SELECTION_NUDGE_MODIFIER,
Hotkeys.SELECTION_MODE_CYCLE,
Hotkeys.SELECTION_SHRINK_HOTKEY,
Hotkeys.SET_AREA_ORIGIN,
Hotkeys.SET_SELECTION_BOX_POSITION_1,
Hotkeys.SET_SELECTION_BOX_POSITION_2,
Hotkeys.TOGGLE_ALL_RENDERING,
Hotkeys.TOGGLE_AREA_SELECTION_RENDERING,
Hotkeys.TOGGLE_INFO_OVERLAY_RENDERING,
Hotkeys.TOGGLE_OVERLAY_RENDERING,
Hotkeys.TOGGLE_OVERLAY_OUTLINE_RENDERING,
Hotkeys.TOGGLE_OVERLAY_SIDE_RENDERING,
Hotkeys.TOGGLE_PLACEMENT_BOXES_RENDERING,
Hotkeys.TOGGLE_PLACEMENT_RESTRICTION,
Hotkeys.TOGGLE_SCHEMATIC_BLOCK_RENDERING,
Hotkeys.TOGGLE_SCHEMATIC_RENDERING,
Hotkeys.TOGGLE_TRANSLUCENT_RENDERING,
Hotkeys.TOGGLE_VERIFIER_OVERLAY_RENDERING,
Hotkeys.TOOL_ENABLED_TOGGLE,
Hotkeys.TOOL_PLACE_CORNER_1,
Hotkeys.TOOL_PLACE_CORNER_2,
Hotkeys.TOOL_SELECT_ELEMENTS,
Hotkeys.TOOL_SELECT_MODIFIER_BLOCK_1,
Hotkeys.TOOL_SELECT_MODIFIER_BLOCK_2,
Hotkeys.UNLOAD_CURRENT_SCHEMATIC,
TOGGLE_PRINTING_MODE
);
public static final ConfigHotkey PRINT = new ConfigHotkey("print", "V", "Prints while pressed");
public static final ConfigHotkey TOGGLE_PRINTING_MODE = new ConfigHotkey("togglePrintingMode", "CAPS_LOCK", "Allows quickly toggling on/off Printing mode");

public static List<ConfigHotkey> getHotkeyList() {
List<ConfigHotkey> list = new java.util.ArrayList<>(List.copyOf(Hotkeys.HOTKEY_LIST));
list.add(PRINT);
list.add(TOGGLE_PRINTING_MODE);

return ImmutableList.copyOf(list);
}

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
Expand All @@ -20,16 +18,16 @@ public class ClientPlayNetworkHandlerMixin {
@Shadow
private MinecraftClient client;

@Inject(method = "sendPacket", at = @At("HEAD"))
public void sendPacket(Packet<?> packet, CallbackInfo ci) {
@Overwrite
public void sendPacket(Packet<?> packet) {
if (Implementation.isLookPacket(packet) && Printer.shouldBlockLookPackets()) {
Packet<?> positionOnlyPacket = Implementation.getMoveOnlyPacket(client.player, packet);

if (positionOnlyPacket != null) {
this.connection.send(positionOnlyPacket);
}

return;
} else {
this.connection.send(packet);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,78 +13,23 @@

@Mixin(value = Configs.class, remap = false)
public class ConfigsMixin {

@Redirect(method = "loadFromFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Configs$Generic;OPTIONS:Lcom/google/common/collect/ImmutableList;"))
private static ImmutableList<IConfigBase> moreOptions() {
return LitematicaMixinMod.betterConfigList;
return LitematicaMixinMod.getConfigList();
}

@Redirect(method = "saveToFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Configs$Generic;OPTIONS:Lcom/google/common/collect/ImmutableList;"))
private static ImmutableList<IConfigBase> moreeOptions() {
return LitematicaMixinMod.betterConfigList;
return LitematicaMixinMod.getConfigList();
}

@Redirect(method = "loadFromFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;"))
private static List<ConfigHotkey> moreHotkeys() {
return LitematicaMixinMod.betterHotkeyList;
return LitematicaMixinMod.getHotkeyList();
}

@Redirect(method = "saveToFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;"))
private static List<ConfigHotkey> moreeHotkeys() {
return LitematicaMixinMod.betterHotkeyList;
return LitematicaMixinMod.getHotkeyList();
}



/*
* I couldn't get the redirect mixin working to redirect two fields in one method.
* If you have any idea...
*/
/*@Shadow
private static String CONFIG_FILE_NAME;
@Overwrite
public static void loadFromFile()
{
File configFile = new File(FileUtils.getConfigDirectory(), CONFIG_FILE_NAME);
if (configFile.exists() && configFile.isFile() && configFile.canRead())
{
JsonElement element = JsonUtils.parseJsonFile(configFile);
if (element != null && element.isJsonObject())
{
JsonObject root = element.getAsJsonObject();
ConfigUtils.readConfigBase(root, "Colors", Colors.OPTIONS);
ConfigUtils.readConfigBase(root, "Generic", LitematicaMixinMod.betterConfigList);
ConfigUtils.readConfigBase(root, "Hotkeys", LitematicaMixinMod.betterHotkeyList);
ConfigUtils.readConfigBase(root, "InfoOverlays", InfoOverlays.OPTIONS);
ConfigUtils.readConfigBase(root, "Visuals", Visuals.OPTIONS);
}
}
DataManager.setToolItem(Generic.TOOL_ITEM.getStringValue());
InventoryUtils.setPickBlockableSlots(Generic.PICK_BLOCKABLE_SLOTS.getStringValue());
}
@Overwrite
public static void saveToFile()
{
File dir = FileUtils.getConfigDirectory();
if ((dir.exists() && dir.isDirectory()) || dir.mkdirs())
{
JsonObject root = new JsonObject();
ConfigUtils.writeConfigBase(root, "Colors", Colors.OPTIONS);
ConfigUtils.writeConfigBase(root, "Generic", LitematicaMixinMod.betterConfigList);
ConfigUtils.writeConfigBase(root, "Hotkeys", LitematicaMixinMod.betterHotkeyList);
ConfigUtils.writeConfigBase(root, "InfoOverlays", InfoOverlays.OPTIONS);
ConfigUtils.writeConfigBase(root, "Visuals", Visuals.OPTIONS);
JsonUtils.writeJsonToFile(root, new File(dir, CONFIG_FILE_NAME));
}
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ else if (tab == ConfigGuiTab.HOTKEYS)

@Redirect(method = "getConfigs", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Configs$Generic;OPTIONS:Lcom/google/common/collect/ImmutableList;"))
private ImmutableList<IConfigBase> moreOptions() {
return LitematicaMixinMod.betterConfigList;
return LitematicaMixinMod.getConfigList();
}

@Redirect(method = "getConfigs", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;"))
private List<ConfigHotkey> moreHotkeys() {
return LitematicaMixinMod.betterHotkeyList;
return LitematicaMixinMod.getHotkeyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class InputHandlerMixin {

@Redirect(method = "addHotkeys", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;"))
private List<ConfigHotkey> moreHotkeys() {
return LitematicaMixinMod.betterHotkeyList;
return LitematicaMixinMod.getHotkeyList();
}

@Redirect(method = "addKeysToMap", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;"))
private List<ConfigHotkey> moreeHotkeys() {
return LitematicaMixinMod.betterHotkeyList;
return LitematicaMixinMod.getHotkeyList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
Expand All @@ -31,13 +30,6 @@ public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {

protected Printer printer;

@Inject(at = @At("RETURN"), method = "isCamera", cancellable = true)
protected void isCamera(CallbackInfoReturnable<Boolean> cir) {
if (printer != null && printer.lockCamera) {
cir.setReturnValue(false); // Fix for placing correctly pistons for example
}
}

@Inject(at = @At("HEAD"), method = "tick")
public void tick(CallbackInfo ci) {
if (!didCheckForUpdates) {
Expand All @@ -54,7 +46,9 @@ public void tick(CallbackInfo ci) {
return;
}

if (SchematicWorldHandler.getSchematicWorld() == null || !LitematicaMixinMod.PRINT_MODE.getBooleanValue()) return;
if (SchematicWorldHandler.getSchematicWorld() == null ||
!(LitematicaMixinMod.PRINT_MODE.getBooleanValue() || LitematicaMixinMod.PRINT.getKeybind().isPressed()))
return;

printer.onTick();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerInteractionManager.class)
public abstract class MixinClientPlayerInteractionManager implements IClientPlayerInteractionManager {
Expand All @@ -27,6 +30,7 @@ public void rightClickBlock(BlockPos pos, Direction side, Vec3d hitVec)
interactBlock(client.player, client.world, Hand.MAIN_HAND,
new BlockHitResult(hitVec, side, pos, false));
interactItem(client.player, client.world, Hand.MAIN_HAND);
System.out.println("Printer interactBlock: pos: (" + pos.toShortString() + "), side: " + side.getName() + ", vector: " + hitVec.toString());
}

@Shadow
Expand All @@ -37,4 +41,9 @@ public abstract ActionResult interactBlock(
@Shadow
public abstract ActionResult interactItem(PlayerEntity playerEntity_1,
World world_1, Hand hand_1);

@Inject(at = @At("HEAD"), method = "interactBlock")
public void interactBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
System.out.println("Player interactBlock: pos: (" + hitResult.getBlockPos().toShortString() + "), side: " + hitResult.getSide().getName() + ", vector: " + hitResult.getPos().toString());
}
}
Loading

0 comments on commit db31de8

Please sign in to comment.