├── printer_demo.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ ├── resources │ ├── assets │ │ └── litematica-printer │ │ │ ├── icon.png │ │ │ └── lang │ │ │ ├── zh_cn.json │ │ │ ├── zh_tw.json │ │ │ ├── ko_kr.json │ │ │ ├── uk_ua.json │ │ │ ├── en_us.json │ │ │ └── es_es.json │ ├── litematica-printer-implementation.mixins.json │ ├── litematica-printer.mixins.json │ └── fabric.mod.json │ └── java │ └── me │ └── aleksilassila │ └── litematica │ └── printer │ ├── actions │ ├── Action.java │ ├── ReleaseShiftAction.java │ ├── InteractAction.java │ └── PrepareAction.java │ ├── implementation │ ├── BlockHelperImpl.java │ ├── actions │ │ └── InteractActionImpl.java │ ├── PrinterPlacementContext.java │ └── mixin │ │ └── MixinClientPlayerEntity.java │ ├── LitematicaMixinMod.java │ ├── event │ └── KeyCallbacks.java │ ├── mixin │ ├── AxeItemAccessor.java │ ├── InputHandlerMixin.java │ ├── GuiConfigsMixin.java │ ├── PlayerMoveC2SPacketMixin.java │ └── ConfigsMixin.java │ ├── guides │ ├── placement │ │ ├── FlowerPotGuide.java │ │ ├── FarmlandGuide.java │ │ ├── TorchGuide.java │ │ ├── FallingBlockGuide.java │ │ ├── LogGuide.java │ │ ├── BlockIndifferentGuesserGuide.java │ │ ├── PropertySpecificGuesserGuide.java │ │ ├── RotatingBlockGuide.java │ │ ├── SlabGuide.java │ │ ├── BlockReplacementGuide.java │ │ ├── ChestGuide.java │ │ ├── RailGuesserGuide.java │ │ ├── GeneralPlacementGuide.java │ │ ├── PlacementGuide.java │ │ └── GuesserGuide.java │ ├── SkipGuide.java │ ├── interaction │ │ ├── CampfireExtinguishGuide.java │ │ ├── EnderEyeGuide.java │ │ ├── LightCandleGuide.java │ │ ├── TillingGuide.java │ │ ├── FlowerPotFillGuide.java │ │ ├── CycleStateGuide.java │ │ ├── LogStrippingGuide.java │ │ └── InteractionGuide.java │ ├── Guides.java │ └── Guide.java │ ├── PrinterReference.java │ ├── config │ ├── Hotkeys.java │ └── Configs.java │ ├── SchematicBlockState.java │ ├── BlockHelper.java │ ├── ActionHandler.java │ ├── UpdateChecker.java │ └── Printer.java ├── .gitignore ├── settings.gradle ├── .gitattributes ├── gradle.properties ├── .github └── workflows │ └── build.yml ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE.md /printer_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sakura-ryoko/litematica-printer/HEAD/printer_demo.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sakura-ryoko/litematica-printer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sakura-ryoko/litematica-printer/HEAD/src/main/resources/assets/litematica-printer/icon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .settings 3 | bin/ 4 | build/ 5 | eclipse/ 6 | logs/ 7 | .classpath 8 | .project 9 | build.number 10 | run/ 11 | .idea/ 12 | .DS_Store 13 | .vscode 14 | libs/ 15 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name = 'Fabric' 5 | url = 'https://maven.fabricmc.net/' 6 | } 7 | mavenCentral() 8 | gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/actions/Action.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.actions; 2 | 3 | import net.minecraft.client.Minecraft; 4 | import net.minecraft.client.player.LocalPlayer; 5 | 6 | public abstract class Action { 7 | abstract public void send(Minecraft client, LocalPlayer player); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/litematica-printer-implementation.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "me.aleksilassila.litematica.printer.implementation.mixin", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "MixinClientPlayerEntity" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/implementation/BlockHelperImpl.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.implementation; 2 | 3 | import me.aleksilassila.litematica.printer.BlockHelper; 4 | import net.minecraft.world.level.block.ButtonBlock; 5 | 6 | public class BlockHelperImpl extends BlockHelper { 7 | static { 8 | interactiveBlocks.add(ButtonBlock.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/resources/litematica-printer.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "me.aleksilassila.litematica.printer.mixin", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "AxeItemAccessor", 8 | "ConfigsMixin", 9 | "GuiConfigsMixin", 10 | "InputHandlerMixin", 11 | "PlayerMoveC2SPacketMixin" 12 | ], 13 | "injectors": { 14 | "defaultRequire": 1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/LitematicaMixinMod.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import me.aleksilassila.litematica.printer.event.KeyCallbacks; 4 | import net.fabricmc.api.ModInitializer; 5 | import net.minecraft.client.Minecraft; 6 | 7 | public class LitematicaMixinMod implements ModInitializer { 8 | public static Printer printer; 9 | 10 | @Override 11 | public void onInitialize() { 12 | KeyCallbacks.init(Minecraft.getInstance()); 13 | Printer.logger.info("{} initialized.", PrinterReference.MOD_STRING); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/event/KeyCallbacks.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.event; 2 | 3 | import fi.dy.masa.malilib.hotkeys.KeyCallbackToggleBooleanConfigWithMessage; 4 | import me.aleksilassila.litematica.printer.config.Configs; 5 | import me.aleksilassila.litematica.printer.config.Hotkeys; 6 | import net.minecraft.client.Minecraft; 7 | 8 | public class KeyCallbacks { 9 | public static void init(Minecraft mc) { 10 | Hotkeys.TOGGLE_PRINTING_MODE.getKeybind().setCallback(new KeyCallbackToggleBooleanConfigWithMessage(Configs.PRINT_MODE)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # text stuff 2 | * text=auto 3 | *.bat text eol=crlf 4 | *.groovy text eol=lf 5 | *.java text eol=crlf 6 | *.md text 7 | *.properties text eol=lf 8 | *.scala text eol=lf 9 | *.sh text eol=lf 10 | .gitattributes text eol=lf 11 | .gitignore text eol=lf 12 | build.gradle text eol=lf 13 | gradlew text eol=lf 14 | gradle/wrapper/gradle-wrapper.properties text eol=crlf 15 | COPYING.txt text eol=lf 16 | COPYING.LESSER.txt text eol=lf 17 | README.md text eol=lf 18 | 19 | #binary 20 | *.dat binary 21 | *.bin binary 22 | *.png binary 23 | *.exe binary 24 | *.dll binary 25 | *.zip binary 26 | *.jar binary 27 | *.7z binary 28 | *.db binary 29 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/mixin/AxeItemAccessor.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.mixin; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.gen.Accessor; 5 | 6 | import java.util.Map; 7 | import net.minecraft.world.item.AxeItem; 8 | import net.minecraft.world.level.block.Block; 9 | 10 | /** 11 | * This class apparently fixes an issue with Quilt. 12 | */ 13 | @Mixin(AxeItem.class) 14 | public interface AxeItemAccessor { 15 | @Accessor("STRIPPABLES") 16 | static Map getStrippedBlocks() { 17 | throw new AssertionError("Untransformed @Accessor"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs = -Xmx2G 3 | org.gradle.parallel = false 4 | 5 | # Mod Properties 6 | mod_version = 3.2.1 7 | 8 | mod_id = litematica-printer 9 | maven_group = me.aleksilassila 10 | archives_base_name = litematica-printer 11 | 12 | # Dependencies (malilib / litematica) 13 | malilib_version = 28fd4dd03a 14 | litematica_version = f735104983 15 | 16 | # Minecraft, Fabric Loader and API and mappings versions 17 | minecraft_version_out = 1.21.11 18 | minecraft_version = 1.21.11 19 | mappings_version = 1.21.11+build.1 20 | 21 | fabric_loader_version = 0.18.2 22 | mod_menu_version = 17.0.0-alpha.1 23 | fabric_api_version = 0.139.4+1.21.11 24 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/FlowerPotGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.world.item.ItemStack; 5 | import net.minecraft.world.item.Items; 6 | import javax.annotation.Nonnull; 7 | import java.util.Collections; 8 | import java.util.List; 9 | 10 | public class FlowerPotGuide extends GeneralPlacementGuide { 11 | public FlowerPotGuide(SchematicBlockState state) { 12 | super(state); 13 | } 14 | 15 | @Override 16 | protected @Nonnull List getRequiredItems() { 17 | return Collections.singletonList(new ItemStack(Items.FLOWER_POT)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/PrinterReference.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import net.minecraft.SharedConstants; 4 | import fi.dy.masa.malilib.util.StringUtils; 5 | 6 | public class PrinterReference { 7 | public static final String MOD_ID = "litematica_printer"; 8 | public static final String MOD_KEY = "litematica-printer"; // For lang files since they shouldn't use a '_' 9 | public static final String MOD_NAME = "Litematica Printer"; 10 | public static final String MOD_VERSION = StringUtils.getModVersionString(MOD_ID); 11 | public static final String MC_VERSION = SharedConstants.getCurrentVersion().id(); 12 | public static final String MOD_STRING = MOD_ID + "-" + MC_VERSION + "-" + MOD_VERSION; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/actions/ReleaseShiftAction.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.actions; 2 | 3 | import net.minecraft.client.Minecraft; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; 6 | import net.minecraft.world.entity.player.Input; 7 | 8 | public class ReleaseShiftAction extends Action { 9 | @Override 10 | public void send(Minecraft client, LocalPlayer player) { 11 | player.input.keyPresses = new Input(player.input.keyPresses.forward(), player.input.keyPresses.backward(), player.input.keyPresses.left(), player.input.keyPresses.right(), player.input.keyPresses.jump(), false, player.input.keyPresses.sprint()); 12 | player.connection.send(new ServerboundPlayerInputPacket(player.input.keyPresses)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/implementation/actions/InteractActionImpl.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.implementation.actions; 2 | 3 | import me.aleksilassila.litematica.printer.actions.InteractAction; 4 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.world.InteractionHand; 8 | import net.minecraft.world.phys.BlockHitResult; 9 | 10 | public class InteractActionImpl extends InteractAction { 11 | public InteractActionImpl(PrinterPlacementContext context) { 12 | super(context); 13 | } 14 | 15 | @Override 16 | protected void interact(Minecraft client, LocalPlayer player, InteractionHand hand, BlockHitResult hitResult) { 17 | if (client.gameMode != null) { 18 | client.gameMode.useItemOn(player, hand, hitResult); 19 | client.gameMode.useItem(player, hand); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/FarmlandGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.world.item.ItemStack; 5 | import net.minecraft.world.level.block.Block; 6 | import net.minecraft.world.level.block.Blocks; 7 | import javax.annotation.Nonnull; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | public class FarmlandGuide extends GeneralPlacementGuide { 12 | public static final Block[] TILLABLE_BLOCKS = new Block[]{ 13 | Blocks.DIRT, 14 | Blocks.GRASS_BLOCK, 15 | Blocks.COARSE_DIRT, 16 | Blocks.ROOTED_DIRT, 17 | Blocks.DIRT_PATH, 18 | }; 19 | 20 | public FarmlandGuide(SchematicBlockState state) { 21 | super(state); 22 | } 23 | 24 | @Override 25 | protected @Nonnull List getRequiredItems() { 26 | return Arrays.stream(TILLABLE_BLOCKS).map(b -> getBlockItem(b.defaultBlockState())).toList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/SkipGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.actions.Action; 5 | import net.minecraft.client.player.LocalPlayer; 6 | import net.minecraft.world.item.ItemStack; 7 | import javax.annotation.Nonnull; 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | public class SkipGuide extends Guide { 13 | public SkipGuide(SchematicBlockState state) { 14 | super(state); 15 | } 16 | 17 | @Override 18 | public boolean skipOtherGuides() { 19 | return true; 20 | } 21 | 22 | @Override 23 | public boolean canExecute(LocalPlayer player) { 24 | return false; 25 | } 26 | 27 | @Override 28 | public @Nonnull List execute(LocalPlayer player) { 29 | return new ArrayList<>(); 30 | } 31 | 32 | @Override 33 | protected @Nonnull List getRequiredItems() { 34 | return Collections.singletonList(ItemStack.EMPTY); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/config/Hotkeys.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.config; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import fi.dy.masa.malilib.config.options.ConfigHotkey; 5 | import fi.dy.masa.malilib.hotkeys.KeybindSettings; 6 | import me.aleksilassila.litematica.printer.PrinterReference; 7 | 8 | import java.util.List; 9 | 10 | public class Hotkeys { 11 | private static final String HOTKEY_KEY = PrinterReference.MOD_KEY + ".config.hotkeys"; 12 | 13 | // Hotkeys 14 | public static final ConfigHotkey PRINT = new ConfigHotkey("print", "V", KeybindSettings.PRESS_ALLOWEXTRA_EMPTY).apply(HOTKEY_KEY); 15 | public static final ConfigHotkey TOGGLE_PRINTING_MODE = new ConfigHotkey("togglePrintingMode", "CAPS_LOCK", KeybindSettings.PRESS_ALLOWEXTRA_EMPTY).apply(HOTKEY_KEY); 16 | 17 | public static List getHotkeyList() { 18 | List list = new java.util.ArrayList<>(fi.dy.masa.litematica.config.Hotkeys.HOTKEY_LIST); 19 | list.add(PRINT); 20 | list.add(TOGGLE_PRINTING_MODE); 21 | 22 | return ImmutableList.copyOf(list); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "litematica_printer", 4 | "version": "${version}", 5 | "name": "Litematica Printer", 6 | "description": "A fork of Litematica that adds the missing printer functionality", 7 | "authors": [ 8 | "aleksilassila" 9 | ], 10 | "contact": { 11 | "homepage": "https://github.com/aleksilassila/litematica-printer", 12 | "sources": "https://github.com/aleksilassila/litematica-printer" 13 | }, 14 | "license": "CC0-1.0", 15 | "icon": "assets/litematica-printer/icon.png", 16 | "environment": "*", 17 | "entrypoints": { 18 | "main": [ 19 | "me.aleksilassila.litematica.printer.LitematicaMixinMod" 20 | ] 21 | }, 22 | "mixins": [ 23 | "litematica-printer.mixins.json", 24 | "litematica-printer-implementation.mixins.json" 25 | ], 26 | "depends": { 27 | "fabric": "*", 28 | "java": ">=21", 29 | "minecraft": "1.21.11", 30 | "malilib": ">=0.27.0- <0.28.0-", 31 | "litematica": ">=0.25.0- <0.26.0-" 32 | }, 33 | "breaks": { 34 | "malilib": "<0.27.0-", 35 | "litematica": "<0.25.0-" 36 | }, 37 | "custom": { 38 | "modmenu": { 39 | "parent": "litematica" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/mixin/InputHandlerMixin.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.mixin; 2 | 3 | import fi.dy.masa.litematica.event.InputHandler; 4 | import fi.dy.masa.malilib.config.options.ConfigHotkey; 5 | import me.aleksilassila.litematica.printer.config.Hotkeys; 6 | import org.objectweb.asm.Opcodes; 7 | 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Redirect; 11 | 12 | import java.util.List; 13 | 14 | @Mixin(value = InputHandler.class, remap = false) 15 | public class InputHandlerMixin { 16 | @Redirect(method = "addHotkeys", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;", opcode = Opcodes.GETSTATIC)) 17 | private List moreHotkeys() { 18 | return Hotkeys.getHotkeyList(); 19 | } 20 | 21 | @Redirect(method = "addKeysToMap", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;", opcode = Opcodes.GETSTATIC)) 22 | private List moreeHotkeys() { 23 | return Hotkeys.getHotkeyList(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/TorchGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.core.Direction; 6 | import net.minecraft.world.level.block.Block; 7 | import net.minecraft.world.level.block.HorizontalDirectionalBlock; 8 | import java.util.Collections; 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | public class TorchGuide extends GeneralPlacementGuide { 13 | public TorchGuide(SchematicBlockState state) { 14 | super(state); 15 | } 16 | 17 | @Override 18 | protected List getPossibleSides() { 19 | Optional facing = getProperty(targetState, HorizontalDirectionalBlock.FACING); 20 | 21 | return facing 22 | .map(direction -> Collections.singletonList(direction.getOpposite())) 23 | .orElseGet(() -> Collections.singletonList(Direction.DOWN)); 24 | } 25 | 26 | @Override 27 | protected Optional getRequiredItemAsBlock(LocalPlayer player) { 28 | return Optional.of(state.targetState.getBlock()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/FallingBlockGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.core.Direction; 6 | import net.minecraft.world.level.block.FallingBlock; 7 | import net.minecraft.world.level.block.state.BlockState; 8 | 9 | public class FallingBlockGuide extends GuesserGuide { 10 | 11 | public FallingBlockGuide(SchematicBlockState state) { 12 | super(state); 13 | } 14 | 15 | boolean blockPlacement() { 16 | if (targetState.getBlock() instanceof FallingBlock) { 17 | BlockState below = state.world.getBlockState(state.blockPos.relative(Direction.DOWN)); 18 | return FallingBlock.isFree(below); 19 | } 20 | 21 | return false; 22 | } 23 | 24 | @Override 25 | public boolean canExecute(LocalPlayer player) { 26 | if (blockPlacement()) 27 | return false; 28 | 29 | return super.canExecute(player); 30 | } 31 | 32 | @Override 33 | public boolean skipOtherGuides() { 34 | if (blockPlacement()) 35 | return true; 36 | 37 | return super.skipOtherGuides(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/CampfireExtinguishGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.world.item.ItemStack; 6 | import net.minecraft.world.level.block.CampfireBlock; 7 | import javax.annotation.Nonnull; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | public class CampfireExtinguishGuide extends InteractionGuide { 12 | boolean shouldBeLit; 13 | boolean isLit; 14 | 15 | public CampfireExtinguishGuide(SchematicBlockState state) { 16 | super(state); 17 | 18 | shouldBeLit = getProperty(targetState, CampfireBlock.LIT).orElse(false); 19 | isLit = getProperty(currentState, CampfireBlock.LIT).orElse(false); 20 | } 21 | 22 | @Override 23 | public boolean canExecute(LocalPlayer player) { 24 | if (!super.canExecute(player)) 25 | return false; 26 | 27 | return (currentState.getBlock() instanceof CampfireBlock) && !shouldBeLit && isLit; 28 | } 29 | 30 | @Override 31 | protected @Nonnull List getRequiredItems() { 32 | return Arrays.stream(SHOVEL_ITEMS).map(ItemStack::new).toList(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/EnderEyeGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.world.item.ItemStack; 6 | import net.minecraft.world.item.Items; 7 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 8 | import javax.annotation.Nonnull; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | public class EnderEyeGuide extends InteractionGuide { 13 | public EnderEyeGuide(SchematicBlockState state) { 14 | super(state); 15 | } 16 | 17 | @Override 18 | public boolean canExecute(LocalPlayer player) { 19 | if (!super.canExecute(player)) 20 | return false; 21 | 22 | if (currentState.hasProperty(BlockStateProperties.EYE) && targetState.hasProperty(BlockStateProperties.EYE)) { 23 | return !currentState.getValue(BlockStateProperties.EYE) && targetState.getValue(BlockStateProperties.EYE); 24 | } 25 | 26 | return false; 27 | } 28 | 29 | @Override 30 | protected @Nonnull List getRequiredItems() { 31 | return Collections.singletonList(new ItemStack(Items.ENDER_EYE)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/actions/InteractAction.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.actions; 2 | 3 | import me.aleksilassila.litematica.printer.Printer; 4 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.world.InteractionHand; 8 | import net.minecraft.world.phys.BlockHitResult; 9 | 10 | abstract public class InteractAction extends Action { 11 | public final PrinterPlacementContext context; 12 | 13 | public InteractAction(PrinterPlacementContext context) { 14 | this.context = context; 15 | } 16 | 17 | protected abstract void interact(Minecraft client, LocalPlayer player, InteractionHand hand, BlockHitResult hitResult); 18 | 19 | @Override 20 | public void send(Minecraft client, LocalPlayer player) { 21 | interact(client, player, InteractionHand.MAIN_HAND, context.hitResult); 22 | Printer.printDebug("InteractAction.send: Blockpos: {} Side: {} HitPos: {}", context.getClickedPos(), context.getClickedFace(), context.getClickLocation()); 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "InteractAction{" + 28 | "context=" + context + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # Automatically build the project and run any configured tests for every push 2 | # and submitted pull request. This can help catch issues that only occur on 3 | # certain platforms or Java versions, and provides a first line of defence 4 | # against bad commits. 5 | 6 | name: build 7 | on: [ pull_request, push ] 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | matrix: 13 | # Use these Java versions 14 | java: [ 21 ] 15 | distro: [ temurin ] 16 | # and run on both Linux and Windows 17 | os: [ ubuntu-latest ] 18 | runs-on: ${{ matrix.os }} 19 | steps: 20 | - name: checkout repository 21 | uses: actions/checkout@v4 22 | - name: validate gradle wrapper 23 | uses: gradle/actions/wrapper-validation@v4 24 | - name: setup jdk ${{ matrix.java }} 25 | uses: actions/setup-java@v4 26 | with: 27 | distribution: ${{ matrix.distro }} 28 | java-version: ${{ matrix.java }} 29 | - name: make gradle wrapper executable 30 | if: ${{ runner.os != 'Windows' }} 31 | run: chmod +x ./gradlew 32 | - name: build 33 | run: ./gradlew build 34 | - name: capture build artifacts 35 | if: ${{ runner.os == 'Linux' }} 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: Artifacts 39 | path: build/libs/ 40 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/mixin/GuiConfigsMixin.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.mixin; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import fi.dy.masa.litematica.gui.GuiConfigs; 5 | import fi.dy.masa.malilib.config.IConfigBase; 6 | import fi.dy.masa.malilib.config.options.ConfigHotkey; 7 | import me.aleksilassila.litematica.printer.config.Configs; 8 | import me.aleksilassila.litematica.printer.config.Hotkeys; 9 | import org.objectweb.asm.Opcodes; 10 | 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.injection.At; 13 | import org.spongepowered.asm.mixin.injection.Redirect; 14 | 15 | import java.util.List; 16 | 17 | @Mixin(value = GuiConfigs.class, remap = false) 18 | public class GuiConfigsMixin { 19 | @Redirect(method = "getConfigs", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Configs$Generic;OPTIONS:Lcom/google/common/collect/ImmutableList;", opcode = Opcodes.GETSTATIC)) 20 | private ImmutableList moreOptions() { 21 | return Configs.getConfigList(); 22 | } 23 | 24 | @Redirect(method = "getConfigs", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;", opcode = Opcodes.GETSTATIC)) 25 | private List moreHotkeys() { 26 | return Hotkeys.getHotkeyList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/LightCandleGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.world.item.ItemStack; 6 | import net.minecraft.world.item.Items; 7 | import net.minecraft.world.level.block.AbstractCandleBlock; 8 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 9 | import javax.annotation.Nonnull; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | public class LightCandleGuide extends InteractionGuide { 14 | boolean shouldBeLit; 15 | boolean isLit; 16 | 17 | public LightCandleGuide(SchematicBlockState state) { 18 | super(state); 19 | 20 | shouldBeLit = getProperty(targetState, BlockStateProperties.LIT).orElse(false); 21 | isLit = getProperty(currentState, BlockStateProperties.LIT).orElse(false); 22 | } 23 | 24 | @Override 25 | protected @Nonnull List getRequiredItems() { 26 | return Collections.singletonList(new ItemStack(Items.FLINT_AND_STEEL)); 27 | } 28 | 29 | @Override 30 | public boolean canExecute(LocalPlayer player) { 31 | if (!super.canExecute(player)) 32 | return false; 33 | 34 | return (currentState.getBlock() instanceof AbstractCandleBlock) && shouldBeLit && !isLit; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/TillingGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.guides.placement.FarmlandGuide; 5 | import net.minecraft.client.player.LocalPlayer; 6 | import net.minecraft.world.item.Item; 7 | import net.minecraft.world.item.ItemStack; 8 | import net.minecraft.world.item.Items; 9 | import javax.annotation.Nonnull; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class TillingGuide extends InteractionGuide { 14 | public static final Item[] HOE_ITEMS = new Item[]{ 15 | Items.NETHERITE_HOE, 16 | Items.DIAMOND_HOE, 17 | Items.GOLDEN_HOE, 18 | Items.IRON_HOE, 19 | Items.STONE_HOE, 20 | Items.WOODEN_HOE 21 | }; 22 | 23 | public TillingGuide(SchematicBlockState state) { 24 | super(state); 25 | } 26 | 27 | @Override 28 | public boolean canExecute(LocalPlayer player) { 29 | if (!super.canExecute(player)) 30 | return false; 31 | 32 | return Arrays.stream(FarmlandGuide.TILLABLE_BLOCKS).anyMatch(b -> b == currentState.getBlock()); 33 | } 34 | 35 | @Override 36 | protected @Nonnull List getRequiredItems() { 37 | return Arrays.stream(HOE_ITEMS).map(ItemStack::new).toList(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/SchematicBlockState.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import fi.dy.masa.litematica.world.WorldSchematic; 4 | import net.minecraft.core.BlockPos; 5 | import net.minecraft.core.Direction; 6 | import net.minecraft.world.level.Level; 7 | import net.minecraft.world.level.block.state.BlockState; 8 | 9 | public class SchematicBlockState { 10 | public final Level world; 11 | public final WorldSchematic schematic; 12 | public final BlockPos blockPos; 13 | public final BlockState targetState; 14 | public final BlockState currentState; 15 | 16 | public SchematicBlockState(Level world, WorldSchematic schematic, BlockPos blockPos) { 17 | this.world = world; 18 | this.schematic = schematic; 19 | this.blockPos = blockPos; 20 | this.targetState = schematic.getBlockState(blockPos); 21 | this.currentState = world.getBlockState(blockPos); 22 | } 23 | 24 | public SchematicBlockState offset(Direction direction) { 25 | return new SchematicBlockState(world, schematic, blockPos.relative(direction)); 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "SchematicBlockState{" + 31 | "world=" + world + 32 | ", schematic=" + schematic + 33 | ", blockPos=" + blockPos + 34 | ", targetState=" + targetState + 35 | ", currentState=" + currentState + 36 | '}'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/FlowerPotFillGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.world.item.ItemStack; 6 | import net.minecraft.world.level.block.Block; 7 | import net.minecraft.world.level.block.FlowerPotBlock; 8 | import javax.annotation.Nonnull; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | public class FlowerPotFillGuide extends InteractionGuide { 13 | private final Block content; 14 | 15 | public FlowerPotFillGuide(SchematicBlockState state) { 16 | super(state); 17 | 18 | Block targetBlock = state.targetState.getBlock(); 19 | if (targetBlock instanceof FlowerPotBlock) { 20 | this.content = ((FlowerPotBlock) targetBlock).getPotted(); 21 | } else { 22 | this.content = null; 23 | } 24 | } 25 | 26 | @Override 27 | public boolean canExecute(LocalPlayer player) { 28 | if (content == null) 29 | return false; 30 | if (!(currentState.getBlock() instanceof FlowerPotBlock)) 31 | return false; 32 | 33 | return super.canExecute(player); 34 | } 35 | 36 | @Override 37 | protected @Nonnull List getRequiredItems() { 38 | if (content == null) 39 | return Collections.emptyList(); 40 | else 41 | return Collections.singletonList(new ItemStack(content)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/BlockHelper.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import net.minecraft.world.item.Item; 8 | import net.minecraft.world.item.Items; 9 | import net.minecraft.world.level.block.*; 10 | 11 | abstract public class BlockHelper { 12 | public static List> interactiveBlocks = new ArrayList<>(Arrays.asList( 13 | AbstractChestBlock.class, AbstractFurnaceBlock.class, CraftingTableBlock.class, 14 | LeverBlock.class, 15 | DoorBlock.class, TrapDoorBlock.class, BedBlock.class, RedStoneWireBlock.class, 16 | ScaffoldingBlock.class, 17 | HopperBlock.class, EnchantingTableBlock.class, NoteBlock.class, JukeboxBlock.class, 18 | CakeBlock.class, 19 | FenceGateBlock.class, BrewingStandBlock.class, DragonEggBlock.class, CommandBlock.class, 20 | BeaconBlock.class, AnvilBlock.class, ComparatorBlock.class, RepeaterBlock.class, 21 | DropperBlock.class, DispenserBlock.class, ShulkerBoxBlock.class, LecternBlock.class, 22 | FlowerPotBlock.class, BarrelBlock.class, BellBlock.class, SmithingTableBlock.class, 23 | LoomBlock.class, CartographyTableBlock.class, GrindstoneBlock.class, 24 | StonecutterBlock.class, SignBlock.class, AbstractCandleBlock.class)); 25 | 26 | public static final Item[] SHOVEL_ITEMS = new Item[]{ 27 | Items.NETHERITE_SHOVEL, 28 | Items.DIAMOND_SHOVEL, 29 | Items.GOLDEN_SHOVEL, 30 | Items.IRON_SHOVEL, 31 | Items.STONE_SHOVEL, 32 | Items.WOODEN_SHOVEL 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/CycleStateGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.client.player.LocalPlayer; 5 | import net.minecraft.world.item.ItemStack; 6 | import net.minecraft.world.level.block.LeverBlock; 7 | import net.minecraft.world.level.block.state.BlockState; 8 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 9 | import net.minecraft.world.level.block.state.properties.Property; 10 | import javax.annotation.Nonnull; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class CycleStateGuide extends InteractionGuide { 15 | private static final Property[] propertiesToIgnore = new Property[]{ 16 | BlockStateProperties.POWERED, 17 | BlockStateProperties.LIT 18 | }; 19 | 20 | public CycleStateGuide(SchematicBlockState state) { 21 | super(state); 22 | } 23 | 24 | @Override 25 | public boolean canExecute(LocalPlayer player) { 26 | if (!super.canExecute(player)) 27 | return false; 28 | 29 | return targetState.getBlock() == currentState.getBlock(); 30 | } 31 | 32 | @Override 33 | protected @Nonnull List getRequiredItems() { 34 | return Collections.singletonList(ItemStack.EMPTY); 35 | } 36 | 37 | @Override 38 | protected boolean statesEqual(BlockState state1, BlockState state2) { 39 | if (state2.getBlock() instanceof LeverBlock) { 40 | return super.statesEqual(state1, state2); 41 | } 42 | 43 | return statesEqualIgnoreProperties(state1, state2, propertiesToIgnore); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/LogStrippingGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.config.Configs; 5 | import me.aleksilassila.litematica.printer.mixin.AxeItemAccessor; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.world.item.Item; 8 | import net.minecraft.world.item.ItemStack; 9 | import net.minecraft.world.item.Items; 10 | import net.minecraft.world.level.block.Block; 11 | import javax.annotation.Nonnull; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | public class LogStrippingGuide extends InteractionGuide { 17 | static final Item[] AXE_ITEMS = new Item[]{ 18 | Items.NETHERITE_AXE, 19 | Items.DIAMOND_AXE, 20 | Items.GOLDEN_AXE, 21 | Items.IRON_AXE, 22 | Items.STONE_AXE, 23 | Items.WOODEN_AXE 24 | }; 25 | 26 | public static final Map STRIPPED_BLOCKS = AxeItemAccessor.getStrippedBlocks(); 27 | 28 | public LogStrippingGuide(SchematicBlockState state) { 29 | super(state); 30 | } 31 | 32 | @Override 33 | public boolean canExecute(LocalPlayer player) { 34 | if (!Configs.STRIP_LOGS.getBooleanValue()) 35 | return false; 36 | 37 | if (!super.canExecute(player)) 38 | return false; 39 | 40 | Block strippingResult = STRIPPED_BLOCKS.get(currentState.getBlock()); 41 | return strippingResult == targetState.getBlock(); 42 | } 43 | 44 | @Override 45 | protected @Nonnull List getRequiredItems() { 46 | return Arrays.stream(AXE_ITEMS).map(ItemStack::new).toList(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/mixin/PlayerMoveC2SPacketMixin.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.mixin; 2 | 3 | import me.aleksilassila.litematica.printer.LitematicaMixinMod; 4 | import me.aleksilassila.litematica.printer.Printer; 5 | import me.aleksilassila.litematica.printer.actions.PrepareAction; 6 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.ModifyVariable; 10 | 11 | @Mixin(ServerboundMovePlayerPacket.class) 12 | public class PlayerMoveC2SPacketMixin { 13 | @ModifyVariable(method = "(DDDFFZZZZ)V", at = @At("HEAD"), ordinal = 0, argsOnly = true) 14 | private static float modifyLookYaw(float yaw) { 15 | Printer printer = LitematicaMixinMod.printer; 16 | if (printer == null) { 17 | return yaw; 18 | } 19 | 20 | PrepareAction action = printer.actionHandler.lookAction; 21 | if (action != null && action.modifyYaw) { 22 | Printer.printDebug("YAW: {}", action.yaw); 23 | return action.yaw; 24 | } else { 25 | return yaw; 26 | } 27 | } 28 | 29 | @ModifyVariable(method = "(DDDFFZZZZ)V", at = @At("HEAD"), ordinal = 1, argsOnly = true) 30 | private static float modifyLookPitch(float pitch) { 31 | Printer printer = LitematicaMixinMod.printer; 32 | if (printer == null) { 33 | return pitch; 34 | } 35 | 36 | PrepareAction action = printer.actionHandler.lookAction; 37 | if (action != null && action.modifyPitch) { 38 | Printer.printDebug("PITCH: {}", action.pitch); 39 | return action.pitch; 40 | } else { 41 | return pitch; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/ActionHandler.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import me.aleksilassila.litematica.printer.actions.Action; 4 | import me.aleksilassila.litematica.printer.actions.PrepareAction; 5 | import me.aleksilassila.litematica.printer.config.Configs; 6 | import net.minecraft.client.Minecraft; 7 | import net.minecraft.client.player.LocalPlayer; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | import java.util.Queue; 11 | 12 | public class ActionHandler { 13 | private final Minecraft client; 14 | private final LocalPlayer player; 15 | private final Queue actionQueue = new LinkedList<>(); 16 | public PrepareAction lookAction = null; 17 | 18 | public ActionHandler(Minecraft client, LocalPlayer player) { 19 | this.client = client; 20 | this.player = player; 21 | } 22 | 23 | private int tick = 0; 24 | 25 | public void onGameTick() { 26 | int tickRate = Configs.PRINTING_INTERVAL.getIntegerValue(); 27 | tick = tick % tickRate == tickRate - 1 ? 0 : tick + 1; 28 | 29 | if (tick % tickRate != 0) { 30 | return; 31 | } 32 | 33 | Action nextAction = actionQueue.poll(); 34 | 35 | if (nextAction != null) { 36 | Printer.printDebug("Sending action {}", nextAction); 37 | nextAction.send(client, player); 38 | } else { 39 | lookAction = null; 40 | } 41 | } 42 | 43 | public boolean acceptsActions() { 44 | return actionQueue.isEmpty(); 45 | } 46 | 47 | public void addActions(Action... actions) { 48 | if (!acceptsActions()) { 49 | return; 50 | } 51 | 52 | for (Action action : actions) { 53 | if (action instanceof PrepareAction) { 54 | lookAction = (PrepareAction) action; 55 | } 56 | } 57 | 58 | actionQueue.addAll(List.of(actions)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/mixin/ConfigsMixin.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.mixin; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import fi.dy.masa.litematica.config.Configs; 5 | import fi.dy.masa.malilib.config.IConfigBase; 6 | import fi.dy.masa.malilib.config.options.ConfigHotkey; 7 | import me.aleksilassila.litematica.printer.config.Hotkeys; 8 | import org.objectweb.asm.Opcodes; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Redirect; 13 | 14 | import java.util.List; 15 | 16 | @Mixin(value = Configs.class, remap = false) 17 | public class ConfigsMixin { 18 | @Redirect(method = "loadFromFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Configs$Generic;OPTIONS:Lcom/google/common/collect/ImmutableList;", opcode = Opcodes.GETSTATIC)) 19 | private static ImmutableList moreOptions() { 20 | return me.aleksilassila.litematica.printer.config.Configs.getConfigList(); 21 | } 22 | 23 | @Redirect(method = "saveToFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Configs$Generic;OPTIONS:Lcom/google/common/collect/ImmutableList;", opcode = Opcodes.GETSTATIC)) 24 | private static ImmutableList moreeOptions() { 25 | return me.aleksilassila.litematica.printer.config.Configs.getConfigList(); 26 | } 27 | 28 | @Redirect(method = "loadFromFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;", opcode = Opcodes.GETSTATIC)) 29 | private static List moreHotkeys() { 30 | return Hotkeys.getHotkeyList(); 31 | } 32 | 33 | @Redirect(method = "saveToFile", at = @At(value = "FIELD", target = "Lfi/dy/masa/litematica/config/Hotkeys;HOTKEY_LIST:Ljava/util/List;", opcode = Opcodes.GETSTATIC)) 34 | private static List moreeHotkeys() { 35 | return Hotkeys.getHotkeyList(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/UpdateChecker.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonObject; 5 | import com.google.gson.JsonParser; 6 | 7 | import java.io.InputStream; 8 | import java.net.URL; 9 | import java.util.Scanner; 10 | 11 | public class UpdateChecker { 12 | public static final String version = "v" + PrinterReference.MOD_VERSION; 13 | 14 | // Try to get this to work at some point 15 | // static { 16 | // try (InputStream in = UpdateChecker.class.getResourceAsStream("/fabric.mod.json")) { 17 | // String jsonString = IOUtils.toString(in, StandardCharsets.UTF_8); 18 | // JsonObject json = JsonParser.parseString(jsonString).getAsJsonObject(); 19 | // System.out.println("JSON object: " + json); 20 | // System.out.println("Raw json: " + jsonString); 21 | // System.out.println("File: " + new File(UpdateChecker.class.getResource("/fabric.mod.json").getFile())); 22 | // String version = json.get("version").getAsString(); 23 | // System.out.println("Reading fabric.mod.json"); 24 | // System.out.println("Parsed version: " + version); 25 | // } catch (Exception e) { 26 | // e.printStackTrace(); 27 | // } 28 | // } 29 | 30 | @SuppressWarnings("deprecation") 31 | public static String getPrinterVersion() { 32 | try (InputStream inputStream = new URL("https://api.github.com/repos/aleksilassila/litematica-printer/tags").openStream(); Scanner scanner = new Scanner(inputStream)) { 33 | if (scanner.hasNext()) { 34 | JsonArray tags = new JsonParser().parse(scanner.next()).getAsJsonArray(); 35 | return ((JsonObject) tags.get(0)).get("name").getAsString(); 36 | } 37 | } catch (Exception exception) { 38 | System.out.println("Cannot look for updates: " + exception.getMessage()); 39 | } 40 | 41 | return ""; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/LogGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.config.Configs; 5 | import me.aleksilassila.litematica.printer.guides.interaction.LogStrippingGuide; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.core.Direction; 8 | import net.minecraft.world.item.ItemStack; 9 | import net.minecraft.world.level.block.Block; 10 | import net.minecraft.world.level.block.RotatedPillarBlock; 11 | import javax.annotation.Nonnull; 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | public class LogGuide extends GeneralPlacementGuide { 18 | public LogGuide(SchematicBlockState state) { 19 | super(state); 20 | } 21 | 22 | @Override 23 | protected List getPossibleSides() { 24 | if (targetState.hasProperty(RotatedPillarBlock.AXIS)) { 25 | Direction.Axis axis = targetState.getValue(RotatedPillarBlock.AXIS); 26 | return Arrays.stream(Direction.values()).filter(d -> d.getAxis() == axis).toList(); 27 | } 28 | 29 | return new ArrayList<>(); 30 | } 31 | 32 | @Override 33 | protected @Nonnull List getRequiredItems() { 34 | for (Block log : LogStrippingGuide.STRIPPED_BLOCKS.keySet()) { 35 | if (targetState.getBlock() == LogStrippingGuide.STRIPPED_BLOCKS.get(log)) { 36 | return Collections.singletonList(new ItemStack(log)); 37 | } 38 | } 39 | 40 | return super.getRequiredItems(); 41 | } 42 | 43 | @Override 44 | public boolean canExecute(LocalPlayer player) { 45 | if (!Configs.STRIP_LOGS.getBooleanValue()) 46 | return false; 47 | 48 | if (LogStrippingGuide.STRIPPED_BLOCKS.containsValue(targetState.getBlock())) { 49 | return super.canExecute(player); 50 | } 51 | 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/BlockIndifferentGuesserGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | 5 | import net.minecraft.world.level.block.*; 6 | import net.minecraft.world.level.block.state.BlockState; 7 | 8 | public class BlockIndifferentGuesserGuide extends GuesserGuide { 9 | public BlockIndifferentGuesserGuide(SchematicBlockState state) { 10 | super(state); 11 | } 12 | 13 | @Override 14 | protected boolean statesEqual(BlockState resultState, BlockState targetState) { 15 | Block targetBlock = targetState.getBlock(); 16 | Block resultBlock = resultState.getBlock(); 17 | 18 | if (targetBlock instanceof BambooStalkBlock) { 19 | return resultBlock instanceof BambooStalkBlock || resultBlock instanceof BambooSaplingBlock; 20 | } 21 | 22 | if (targetBlock instanceof BigDripleafStemBlock) { 23 | if (resultBlock instanceof BigDripleafBlock || resultBlock instanceof BigDripleafStemBlock) { 24 | return resultState.getValue(HorizontalDirectionalBlock.FACING) == targetState.getValue(HorizontalDirectionalBlock.FACING); 25 | } 26 | } 27 | 28 | if (targetBlock instanceof TwistingVinesPlantBlock) { 29 | if (resultBlock instanceof TwistingVinesBlock) { 30 | return true; 31 | } else if (resultBlock instanceof TwistingVinesPlantBlock) { 32 | return statesEqualIgnoreProperties(resultState, targetState, TwistingVinesBlock.AGE); 33 | } 34 | } 35 | 36 | if (targetBlock instanceof TripWireBlock && resultBlock instanceof TripWireBlock) { 37 | return statesEqualIgnoreProperties(resultState, targetState, 38 | TripWireBlock.ATTACHED, TripWireBlock.DISARMED, TripWireBlock.POWERED, TripWireBlock.NORTH, 39 | TripWireBlock.EAST, TripWireBlock.SOUTH, TripWireBlock.WEST); 40 | } 41 | 42 | return super.statesEqual(resultState, targetState); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/config/Configs.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.config; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import fi.dy.masa.malilib.config.IConfigBase; 5 | import fi.dy.masa.malilib.config.options.ConfigBoolean; 6 | import fi.dy.masa.malilib.config.options.ConfigDouble; 7 | import fi.dy.masa.malilib.config.options.ConfigInteger; 8 | import me.aleksilassila.litematica.printer.PrinterReference; 9 | 10 | import java.util.List; 11 | 12 | public class Configs { 13 | private static final String GENERIC_KEY = PrinterReference.MOD_KEY + ".config.generic"; 14 | 15 | // Configs settings 16 | public static final ConfigInteger PRINTING_INTERVAL = new ConfigInteger("printingInterval", 12, 1, 40).apply(GENERIC_KEY); 17 | public static final ConfigDouble PRINTING_RANGE = new ConfigDouble("printingRange", 5, 2.5, 5).apply(GENERIC_KEY); 18 | public static final ConfigBoolean PRINT_MODE = new ConfigBoolean("printingMode", false).apply(GENERIC_KEY); 19 | public static final ConfigBoolean PRINT_DEBUG = new ConfigBoolean("printingDebug", false).apply(GENERIC_KEY); 20 | public static final ConfigBoolean REPLACE_FLUIDS_SOURCE_BLOCKS = new ConfigBoolean("replaceFluidSourceBlocks", true).apply(GENERIC_KEY); 21 | public static final ConfigBoolean STRIP_LOGS = new ConfigBoolean("stripLogs", true).apply(GENERIC_KEY); 22 | public static final ConfigBoolean INTERACT_BLOCKS = new ConfigBoolean("interactBlocks", true).apply(GENERIC_KEY); 23 | public static final ConfigBoolean PRINT_IN_AIR = new ConfigBoolean("printInAir", false).apply(GENERIC_KEY); 24 | 25 | public static ImmutableList getConfigList() { 26 | List list = new java.util.ArrayList<>(fi.dy.masa.litematica.config.Configs.Generic.OPTIONS); 27 | list.add(PRINT_MODE); 28 | list.add(PRINT_DEBUG); 29 | list.add(PRINTING_INTERVAL); 30 | list.add(PRINTING_RANGE); 31 | list.add(REPLACE_FLUIDS_SOURCE_BLOCKS); 32 | list.add(STRIP_LOGS); 33 | list.add(INTERACT_BLOCKS); 34 | list.add(PRINT_IN_AIR); 35 | 36 | return ImmutableList.copyOf(list); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/interaction/InteractionGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.interaction; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.actions.Action; 5 | import me.aleksilassila.litematica.printer.actions.PrepareAction; 6 | import me.aleksilassila.litematica.printer.actions.ReleaseShiftAction; 7 | import me.aleksilassila.litematica.printer.guides.Guide; 8 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 9 | import me.aleksilassila.litematica.printer.implementation.actions.InteractActionImpl; 10 | import net.minecraft.client.player.LocalPlayer; 11 | import net.minecraft.core.Direction; 12 | import net.minecraft.world.item.ItemStack; 13 | import net.minecraft.world.phys.BlockHitResult; 14 | import net.minecraft.world.phys.Vec3; 15 | import javax.annotation.Nonnull; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * A guide that clicks the current block to change its state. 21 | */ 22 | public abstract class InteractionGuide extends Guide { 23 | public InteractionGuide(SchematicBlockState state) { 24 | super(state); 25 | } 26 | 27 | @Override 28 | public @Nonnull List execute(LocalPlayer player) { 29 | List actions = new ArrayList<>(); 30 | 31 | BlockHitResult hitResult = new BlockHitResult(Vec3.atCenterOf(state.blockPos), Direction.UP, state.blockPos, 32 | false); 33 | ItemStack requiredItem = getRequiredItem(player).orElse(ItemStack.EMPTY); 34 | int requiredSlot = getRequiredItemStackSlot(player); 35 | 36 | if (requiredSlot == -1) 37 | return actions; 38 | 39 | PrinterPlacementContext ctx = new PrinterPlacementContext(player, hitResult, requiredItem, requiredSlot); 40 | 41 | actions.add(new ReleaseShiftAction()); 42 | actions.add(new PrepareAction(ctx)); 43 | actions.add(new InteractActionImpl(ctx)); 44 | 45 | return actions; 46 | } 47 | 48 | @Override 49 | abstract protected @Nonnull List getRequiredItems(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/PropertySpecificGuesserGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | 5 | import net.minecraft.world.level.block.*; 6 | import net.minecraft.world.level.block.state.BlockState; 7 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 8 | import net.minecraft.world.level.block.state.properties.Property; 9 | 10 | public class PropertySpecificGuesserGuide extends GuesserGuide { 11 | protected static Property[] ignoredProperties = new Property[]{ 12 | // RepeaterBlock.DELAY, 13 | // ComparatorBlock.MODE, 14 | RedStoneWireBlock.POWER, 15 | RedStoneWireBlock.EAST, 16 | RedStoneWireBlock.NORTH, 17 | RedStoneWireBlock.SOUTH, 18 | RedStoneWireBlock.WEST, 19 | BlockStateProperties.POWERED, 20 | BlockStateProperties.OPEN, 21 | PointedDripstoneBlock.THICKNESS, 22 | ScaffoldingBlock.DISTANCE, 23 | ScaffoldingBlock.BOTTOM, 24 | CactusBlock.AGE, 25 | BambooStalkBlock.AGE, 26 | BambooStalkBlock.LEAVES, 27 | BambooStalkBlock.STAGE, 28 | SaplingBlock.STAGE, 29 | CrossCollisionBlock.EAST, 30 | CrossCollisionBlock.NORTH, 31 | CrossCollisionBlock.SOUTH, 32 | CrossCollisionBlock.WEST, 33 | SnowLayerBlock.LAYERS, 34 | SeaPickleBlock.PICKLES, 35 | CandleBlock.CANDLES, 36 | EndPortalFrameBlock.HAS_EYE, 37 | BlockStateProperties.LIT, 38 | LeavesBlock.DISTANCE, 39 | LeavesBlock.PERSISTENT, 40 | BlockStateProperties.ATTACHED, 41 | // Properties.NOTE, 42 | BlockStateProperties.NOTEBLOCK_INSTRUMENT, 43 | 44 | }; 45 | 46 | public PropertySpecificGuesserGuide(SchematicBlockState state) { 47 | super(state); 48 | } 49 | 50 | @Override 51 | protected boolean statesEqual(BlockState resultState, BlockState targetState) { 52 | return statesEqualIgnoreProperties(resultState, targetState, ignoredProperties); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/lang/zh_cn.json: -------------------------------------------------------------------------------- 1 | { 2 | "litematica-printer.config.generic.comment.interactBlocks": "是否自动设置方块状态(如开关、方向等)。", 3 | "litematica-printer.config.generic.comment.printInAir": "允许方块在空中放置,无需在下方提供支撑方块。", 4 | "litematica-printer.config.generic.comment.printingDebug": "开启投影打印机调试日志。", 5 | "litematica-printer.config.generic.comment.printingInterval": "打印间隔(单位:刻)。数值越低打印速度越快。\n如果出现\"幽灵方块\"或方块朝向错误,请提高此数值。", 6 | "litematica-printer.config.generic.comment.printingMode": "自动建造/打印已加载的选区\n请注意某些服务器和反作弊插件可能禁止自动打印功能。", 7 | "litematica-printer.config.generic.comment.printingRange": "方块放置的最大距离\n建议在服务器中使用较低数值。", 8 | "litematica-printer.config.generic.comment.replaceFluidSourceBlocks": "是否自动替换流体源方块。", 9 | "litematica-printer.config.generic.comment.stripLogs": "当剥皮变种不可用时,是否先放置普通原木,\n然后用斧头进行剥皮处理。", 10 | "litematica-printer.config.generic.name.interactBlocks": "打印 - 方块交互", 11 | "litematica-printer.config.generic.name.printingDebug": "打印 - 调试模式", 12 | "litematica-printer.config.generic.name.printingInterval": "打印 - 间隔", 13 | "litematica-printer.config.generic.name.printingMode": "打印 - 模式", 14 | "litematica-printer.config.generic.name.printingRange": "打印 - 范围", 15 | "litematica-printer.config.generic.name.replaceFluidSourceBlocks": "打印 - 替换流体源方块", 16 | "litematica-printer.config.generic.name.stripLogs": "打印 - 原木剥皮", 17 | "litematica-printer.config.generic.name.printInAir": "打印 - 空中建造", 18 | "litematica-printer.config.generic.prettyName.interactBlocks": "方块交互", 19 | "litematica-printer.config.generic.prettyName.printingDebug": "打印调试模式", 20 | "litematica-printer.config.generic.prettyName.printingInterval": "打印间隔", 21 | "litematica-printer.config.generic.prettyName.printingMode": "打印模式", 22 | "litematica-printer.config.generic.prettyName.printingRange": "打印范围", 23 | "litematica-printer.config.generic.prettyName.replaceFluidSourceBlocks": "替换流体源方块", 24 | "litematica-printer.config.generic.prettyName.stripLogs": "原木剥皮", 25 | "litematica-printer.config.generic.prettyName.printInAir": "空中建造", 26 | "litematica-printer.config.hotkeys.comment.print": "按住按键时持续打印", 27 | "litematica-printer.config.hotkeys.comment.togglePrintingMode": "快速切换打印模式的开关状态", 28 | "litematica-printer.config.hotkeys.name.print": "打印", 29 | "litematica-printer.config.hotkeys.name.togglePrintingMode": "打印模式 - 开关", 30 | "litematica-printer.config.hotkeys.prettyName.print": "执行打印", 31 | "litematica-printer.config.hotkeys.prettyName.togglePrintingMode": "切换打印模式" 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/lang/zh_tw.json: -------------------------------------------------------------------------------- 1 | { 2 | "litematica-printer.config.generic.comment.interactBlocks": "是否自動設定方塊狀態(如開關、方向等)。", 3 | "litematica-printer.config.generic.comment.printInAir": "允許方塊在空中放置,無需在下方提供支撐方塊。", 4 | "litematica-printer.config.generic.comment.printingDebug": "開啟投影列印機除錯日誌。", 5 | "litematica-printer.config.generic.comment.printingInterval": "列印間隔(單位:tick)。數值越低列印速度越快。\n如果出現\"幽靈方塊\"或方塊朝向錯誤,請提高此數值。", 6 | "litematica-printer.config.generic.comment.printingMode": "自動建造/列印已載入的選區\n請注意某些伺服器和反作弊插件可能禁止自動列印功能。", 7 | "litematica-printer.config.generic.comment.printingRange": "方塊放置的最大距離\n建議在伺服器中使用較低數值。", 8 | "litematica-printer.config.generic.comment.replaceFluidSourceBlocks": "是否自動替換流體源方塊。", 9 | "litematica-printer.config.generic.comment.stripLogs": "當剝皮原木方塊不可用時,是否先放置普通原木,\n然後用斧頭進行剝皮處理。", 10 | "litematica-printer.config.generic.name.interactBlocks": "列印 - 方塊交互", 11 | "litematica-printer.config.generic.name.printingDebug": "列印 - 除錯模式", 12 | "litematica-printer.config.generic.name.printingInterval": "列印 - 間隔", 13 | "litematica-printer.config.generic.name.printingMode": "列印 - 模式", 14 | "litematica-printer.config.generic.name.printingRange": "列印 - 範圍", 15 | "litematica-printer.config.generic.name.replaceFluidSourceBlocks": "列印 - 替換流體源方塊", 16 | "litematica-printer.config.generic.name.stripLogs": "列印 - 原木剝皮", 17 | "litematica-printer.config.generic.name.printInAir": "列印 - 空中建造", 18 | "litematica-printer.config.generic.prettyName.interactBlocks": "方塊交互", 19 | "litematica-printer.config.generic.prettyName.printingDebug": "列印除錯模式", 20 | "litematica-printer.config.generic.prettyName.printingInterval": "列印間隔", 21 | "litematica-printer.config.generic.prettyName.printingMode": "列印模式", 22 | "litematica-printer.config.generic.prettyName.printingRange": "列印範圍", 23 | "litematica-printer.config.generic.prettyName.replaceFluidSourceBlocks": "替換流體源方塊", 24 | "litematica-printer.config.generic.prettyName.stripLogs": "原木剝皮", 25 | "litematica-printer.config.generic.prettyName.printInAir": "空中建造", 26 | "litematica-printer.config.hotkeys.comment.print": "按住按鍵時持續列印", 27 | "litematica-printer.config.hotkeys.comment.togglePrintingMode": "快速切換列印模式的開關狀態", 28 | "litematica-printer.config.hotkeys.name.print": "列印", 29 | "litematica-printer.config.hotkeys.name.togglePrintingMode": "列印模式 - 開關", 30 | "litematica-printer.config.hotkeys.prettyName.print": "執行列印", 31 | "litematica-printer.config.hotkeys.prettyName.togglePrintingMode": "切換列印模式" 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/RotatingBlockGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Optional; 7 | import javax.annotation.Nonnull; 8 | import me.aleksilassila.litematica.printer.SchematicBlockState; 9 | import me.aleksilassila.litematica.printer.actions.Action; 10 | import me.aleksilassila.litematica.printer.actions.PrepareAction; 11 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 12 | 13 | import net.minecraft.client.player.LocalPlayer; 14 | import net.minecraft.core.Direction; 15 | import net.minecraft.world.level.block.*; 16 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 17 | 18 | public class RotatingBlockGuide extends GeneralPlacementGuide { 19 | public RotatingBlockGuide(SchematicBlockState state) { 20 | super(state); 21 | } 22 | 23 | @Override 24 | protected List getPossibleSides() { 25 | Block block = state.targetState.getBlock(); 26 | if (block instanceof WallSkullBlock || block instanceof WallSignBlock || block instanceof WallBannerBlock) { 27 | Optional side = getProperty(state.targetState, BlockStateProperties.HORIZONTAL_FACING) 28 | .map(Direction::getOpposite); 29 | return side.map(Collections::singletonList).orElseGet(Collections::emptyList); 30 | } 31 | 32 | return Collections.singletonList(Direction.DOWN); 33 | } 34 | 35 | @Override 36 | public boolean skipOtherGuides() { 37 | return true; 38 | } 39 | 40 | @Override 41 | public @Nonnull List execute(LocalPlayer player) { 42 | PrinterPlacementContext ctx = getPlacementContext(player); 43 | 44 | if (ctx == null) 45 | return new ArrayList<>(); 46 | 47 | int rotation = getProperty(state.targetState, BlockStateProperties.ROTATION_16).orElse(0); 48 | if (targetState.getBlock() instanceof BannerBlock || targetState.getBlock() instanceof StandingSignBlock) { 49 | rotation = (rotation + 8) % 16; 50 | } 51 | 52 | int distTo0 = rotation > 8 ? 16 - rotation : rotation; 53 | float yaw = Math.round(distTo0 / 8f * 180f * (rotation > 8 ? -1 : 1)); 54 | 55 | List actions = super.execute(player); 56 | actions.set(0, new PrepareAction(ctx, yaw, 0)); 57 | 58 | return actions; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/lang/ko_kr.json: -------------------------------------------------------------------------------- 1 | { 2 | "litematica-printer.config.generic.comment.interactBlocks": "프린터가 블록 상태를 설정해야 하는지 여부입니다.", 3 | "litematica-printer.config.generic.comment.printInAir": "하부에 지지 블록 없이 공중에 블록을 설치할 수 있습니다.", 4 | "litematica-printer.config.generic.comment.printingDebug": "프린팅을 위한 디버그 로그 기록을 활성화합니다.", 5 | "litematica-printer.config.generic.comment.printingInterval": "프린트 간격입니다. 값이 낮을수록 프린트 속도가 빨라집니다.\n만약 프린트 중에 \"고스트 블록\"이 생기거나 블록의 방향이 잘못 설치된다면 값을 증가시키세요.", 6 | "litematica-printer.config.generic.comment.printingMode": "불러온 선택을 자동 건축 / 프린트 합니다.\n일부 서버와 안티치트 플러그인은 프린트를 금지할 수 있다는 것에 주의하세요.", 7 | "litematica-printer.config.generic.comment.printingRange": "프린트 블록 설치 범위입니다.\n서버에서는 낮은 값을 사용하는 것을 추천합니다.", 8 | "litematica-printer.config.generic.comment.replaceFluidSourceBlocks": "프린터가 유체 원천 블록을 교체해야 하는지 여부입니다.", 9 | "litematica-printer.config.generic.comment.stripLogs": "껍질 벗긴 원목이 없을 때 프린터가 일반 원목을 사용하고\n이후 도끼로 벗기기를 할지 여부입니다.", 10 | "litematica-printer.config.generic.name.interactBlocks": "블록 상호 작용", 11 | "litematica-printer.config.generic.name.printingDebug": "프린트 디버그", 12 | "litematica-printer.config.generic.name.printingInterval": "프린트 간격", 13 | "litematica-printer.config.generic.name.printingMode": "프린트 모드", 14 | "litematica-printer.config.generic.name.printingRange": "프린트 범위", 15 | "litematica-printer.config.generic.name.replaceFluidSourceBlocks": "유체 원천 블록 교체", 16 | "litematica-printer.config.generic.name.stripLogs": "원목 벗기기", 17 | "litematica-printer.config.generic.name.printInAir": "공중에 프린트", 18 | "litematica-printer.config.generic.prettyName.interactBlocks": "블록 상호 작용", 19 | "litematica-printer.config.generic.prettyName.printingDebug": "프린트 디버그", 20 | "litematica-printer.config.generic.prettyName.printingInterval": "프린트 간격", 21 | "litematica-printer.config.generic.prettyName.printingMode": "프린트 모드", 22 | "litematica-printer.config.generic.prettyName.printingRange": "프린트 범위", 23 | "litematica-printer.config.generic.prettyName.replaceFluidSourceBlocks": "유체 원천 블록 교체", 24 | "litematica-printer.config.generic.prettyName.stripLogs": "원목 벗기기", 25 | "litematica-printer.config.generic.prettyName.printInAir": "공중에 프린트", 26 | "litematica-printer.config.hotkeys.comment.print": "이 키를 누르고 있는 동안 프린트가 진행됩니다.", 27 | "litematica-printer.config.hotkeys.comment.togglePrintingMode": "프린트 모드를 빠르게 켜고 끌 수 있습니다.", 28 | "litematica-printer.config.hotkeys.name.print": "프린트", 29 | "litematica-printer.config.hotkeys.name.togglePrintingMode": "토글 프린트 모드", 30 | "litematica-printer.config.hotkeys.prettyName.print": "프린트", 31 | "litematica-printer.config.hotkeys.prettyName.togglePrintingMode": "토글 프린트 모드" 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/implementation/PrinterPlacementContext.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.implementation; 2 | 3 | import javax.annotation.Nullable; 4 | import org.jspecify.annotations.NonNull; 5 | 6 | import net.minecraft.core.Direction; 7 | import net.minecraft.world.InteractionHand; 8 | import net.minecraft.world.entity.player.Player; 9 | import net.minecraft.world.item.ItemStack; 10 | import net.minecraft.world.item.context.BlockPlaceContext; 11 | import net.minecraft.world.phys.BlockHitResult; 12 | 13 | public class PrinterPlacementContext extends BlockPlaceContext 14 | { 15 | public final @Nullable Direction lookDirection; 16 | public final boolean shouldSneak; 17 | public final BlockHitResult hitResult; 18 | public final int requiredItemSlot; 19 | 20 | public PrinterPlacementContext(Player player, BlockHitResult hitResult, ItemStack requiredItem, 21 | int requiredItemSlot) 22 | { 23 | this(player, hitResult, requiredItem, requiredItemSlot, null, false); 24 | } 25 | 26 | public PrinterPlacementContext(Player player, BlockHitResult hitResult, ItemStack requiredItem, 27 | int requiredItemSlot, @Nullable Direction lookDirection, boolean requiresSneaking) 28 | { 29 | super(player, InteractionHand.MAIN_HAND, requiredItem, hitResult); 30 | 31 | this.lookDirection = lookDirection; 32 | this.shouldSneak = requiresSneaking; 33 | this.hitResult = hitResult; 34 | this.requiredItemSlot = requiredItemSlot; 35 | } 36 | 37 | @Override 38 | public @NonNull Direction getNearestLookingDirection() 39 | { 40 | return lookDirection == null ? super.getNearestLookingDirection() : lookDirection; 41 | } 42 | 43 | @Override 44 | public @NonNull Direction getNearestLookingVerticalDirection() 45 | { 46 | if (lookDirection != null && lookDirection.getOpposite() == super.getNearestLookingVerticalDirection()) 47 | { 48 | return lookDirection; 49 | } 50 | return super.getNearestLookingVerticalDirection(); 51 | } 52 | 53 | @Override 54 | public @NonNull Direction getHorizontalDirection() 55 | { 56 | if (lookDirection == null || !lookDirection.getAxis().isHorizontal()) 57 | { 58 | return super.getHorizontalDirection(); 59 | } 60 | 61 | return lookDirection; 62 | } 63 | 64 | @Override 65 | public String toString() 66 | { 67 | return "PrinterPlacementContext{" + 68 | "lookDirection=" + lookDirection + 69 | ", requiresSneaking=" + shouldSneak + 70 | ", blockPos=" + hitResult.getBlockPos() + 71 | ", side=" + hitResult.getDirection() + 72 | // ", hitVec=" + hitResult + 73 | '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/lang/uk_ua.json: -------------------------------------------------------------------------------- 1 | { 2 | "litematica-printer.config.generic.comment.interactBlocks": "Чи повинен друк установлювати стан блоку.", 3 | "litematica-printer.config.generic.comment.printInAir": "Дозволяє розміщувати блоки в повітрі без необхідності підтримувальних блоків під ними.", 4 | "litematica-printer.config.generic.comment.printingDebug": "Вмикає журнал налагодження для друку.", 5 | "litematica-printer.config.generic.comment.printingInterval": "Інтервал друку. Менші значення означають більшу швидкість друку.\nЯкщо друк створює «блоки-привиди» або блоки спрямовані неправильно, збільште це значення.", 6 | "litematica-printer.config.generic.comment.printingMode": "Автоматична збірка/друк завантаженого вибору.\nЗверніть увагу, що деякі сервери та плаґіни для захисту від читів не дозволяють друкувати.", 7 | "litematica-printer.config.generic.comment.printingRange": "Діапазон місць блоку друку\nДля серверів рекомендовано нижчі значення.", 8 | "litematica-printer.config.generic.comment.replaceFluidSourceBlocks": "Чи потрібно замінити друком блоки джерела рідини.", 9 | "litematica-printer.config.generic.comment.stripLogs": "Чи повинен друк використовувати звичайні журнали, якщо\nвидалені версії недоступні, а потім знімати їх сокирою.", 10 | "litematica-printer.config.generic.name.interactBlocks": "interactBlocks", 11 | "litematica-printer.config.generic.name.printingDebug": "printingDebug", 12 | "litematica-printer.config.generic.name.printingInterval": "printingInterval", 13 | "litematica-printer.config.generic.name.printingMode": "printingMode", 14 | "litematica-printer.config.generic.name.printingRange": "printingRange", 15 | "litematica-printer.config.generic.name.replaceFluidSourceBlocks": "replaceFluidSourceBlocks", 16 | "litematica-printer.config.generic.name.stripLogs": "stripLogs", 17 | "litematica-printer.config.generic.name.printInAir": "printInAir", 18 | "litematica-printer.config.generic.prettyName.interactBlocks": "Взаємодія з блоками", 19 | "litematica-printer.config.generic.prettyName.printingDebug": "Налагодження друку", 20 | "litematica-printer.config.generic.prettyName.printingInterval": "Інтервал друку", 21 | "litematica-printer.config.generic.prettyName.printingMode": "Режим друку", 22 | "litematica-printer.config.generic.prettyName.printingRange": "Діапазон друку", 23 | "litematica-printer.config.generic.prettyName.replaceFluidSourceBlocks": "Замінити блоки джерела рідини", 24 | "litematica-printer.config.generic.prettyName.stripLogs": "Обтесані колоди", 25 | "litematica-printer.config.generic.prettyName.printInAir": "Друк в повітрі", 26 | "litematica-printer.config.hotkeys.comment.print": "Друкує під час натискання.", 27 | "litematica-printer.config.hotkeys.comment.togglePrintingMode": "Дозволяє швидко вмикати/вимикати режим друку.", 28 | "litematica-printer.config.hotkeys.name.print": "print", 29 | "litematica-printer.config.hotkeys.name.togglePrintingMode": "togglePrintingMode", 30 | "litematica-printer.config.hotkeys.prettyName.print": "Друкувати", 31 | "litematica-printer.config.hotkeys.prettyName.togglePrintingMode": "Перемикач режиму друку" 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "litematica-printer.config.generic.name.printingInterval": "printingInterval", 3 | "litematica-printer.config.generic.name.printingRange": "printingRange", 4 | "litematica-printer.config.generic.name.printingMode": "printingMode", 5 | "litematica-printer.config.generic.name.printingDebug": "printingDebug", 6 | "litematica-printer.config.generic.name.replaceFluidSourceBlocks": "replaceFluidSourceBlocks", 7 | "litematica-printer.config.generic.name.stripLogs": "stripLogs", 8 | "litematica-printer.config.generic.name.interactBlocks": "interactBlocks", 9 | "litematica-printer.config.generic.name.printInAir": "printInAir", 10 | 11 | "litematica-printer.config.generic.prettyName.printingInterval": "Printing Interval", 12 | "litematica-printer.config.generic.prettyName.printingRange": "Printing Range", 13 | "litematica-printer.config.generic.prettyName.printingMode": "Printing Mode", 14 | "litematica-printer.config.generic.prettyName.printingDebug": "Printing Debug", 15 | "litematica-printer.config.generic.prettyName.replaceFluidSourceBlocks": "Replace Fluid Source Blocks", 16 | "litematica-printer.config.generic.prettyName.stripLogs": "Strip Logs", 17 | "litematica-printer.config.generic.prettyName.interactBlocks": "Interact Blocks", 18 | "litematica-printer.config.generic.prettyName.printInAir": "Print in Air", 19 | 20 | "litematica-printer.config.generic.comment.printingInterval": "Printing interval. Lower values mean faster printing speed.\nIf the printer creates \"ghost blocks\" or blocks are facing the wrong way, raise this value.", 21 | "litematica-printer.config.generic.comment.printingRange": "Printing block place range\nLower values are recommended for servers.", 22 | "litematica-printer.config.generic.comment.printingMode": "Autobuild / print loaded selection.\nBe aware that some servers and anticheat plugins do not allow printing.", 23 | "litematica-printer.config.generic.comment.printingDebug": "Enables Debug logging for printing.", 24 | "litematica-printer.config.generic.comment.replaceFluidSourceBlocks": "Whether or not fluid source blocks should be replaced by the printer.", 25 | "litematica-printer.config.generic.comment.stripLogs": "Whether or not the printer should use normal logs if stripped\nversions are not available and then strip them with an axe.", 26 | "litematica-printer.config.generic.comment.interactBlocks": "Whether or not the printer should set block states.", 27 | "litematica-printer.config.generic.comment.printInAir": "Allow blocks to be placed in mid-air without requiring support blocks underneath.", 28 | 29 | "litematica-printer.config.hotkeys.name.print": "print", 30 | "litematica-printer.config.hotkeys.name.togglePrintingMode": "togglePrintingMode", 31 | 32 | "litematica-printer.config.hotkeys.prettyName.print": "Print", 33 | "litematica-printer.config.hotkeys.prettyName.togglePrintingMode": "Toggle Printing Mode", 34 | 35 | "litematica-printer.config.hotkeys.comment.print": "Prints while pressed", 36 | "litematica-printer.config.hotkeys.comment.togglePrintingMode": "Allows quickly toggling on/off Printing mode" 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/SlabGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.level.block.SlabBlock; 6 | import net.minecraft.world.level.block.state.BlockState; 7 | import net.minecraft.world.level.block.state.properties.SlabType; 8 | import net.minecraft.world.phys.Vec3; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class SlabGuide extends GeneralPlacementGuide { 13 | public SlabGuide(SchematicBlockState state) { 14 | super(state); 15 | } 16 | 17 | @Override 18 | protected List getPossibleSides() { 19 | List resultList = new ArrayList<>(); 20 | SlabType targetSlabType = getProperty(state.targetState, SlabBlock.TYPE).orElse(SlabType.DOUBLE); 21 | 22 | if (targetSlabType == SlabType.DOUBLE) { 23 | return super.getPossibleSides(); 24 | } 25 | 26 | Direction[] directionsToCheck = { 27 | Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST 28 | }; 29 | 30 | for (Direction direction : directionsToCheck) { 31 | SlabType neighborSlabType = getProperty(state.offset(direction).currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE); 32 | 33 | if (neighborSlabType == SlabType.DOUBLE || neighborSlabType == targetSlabType) { 34 | resultList.add(direction); 35 | } 36 | } 37 | 38 | if (targetSlabType == SlabType.TOP || targetSlabType == SlabType.BOTTOM) { 39 | Direction verticalDirection = targetSlabType == SlabType.TOP ? Direction.UP : Direction.DOWN; 40 | SlabType neighborSlabType = getProperty(state.offset(verticalDirection).currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE); 41 | 42 | if (neighborSlabType == SlabType.DOUBLE || neighborSlabType != targetSlabType) { 43 | resultList.add(verticalDirection); 44 | } 45 | } 46 | 47 | return resultList; 48 | } 49 | 50 | @Override 51 | protected Vec3 getHitModifier(Direction validSide) { 52 | Direction requiredHalf = getRequiredHalf(state); 53 | if (validSide.get2DDataValue() != -1) { 54 | return new Vec3(0, requiredHalf.getStepY() * 0.25, 0); 55 | } else { 56 | return new Vec3(0, 0, 0); 57 | } 58 | } 59 | 60 | private Direction getRequiredHalf(SchematicBlockState state) { 61 | BlockState targetState = state.targetState; 62 | BlockState currentState = state.currentState; 63 | 64 | if (!currentState.hasProperty(SlabBlock.TYPE)) { 65 | return targetState.getValue(SlabBlock.TYPE) == SlabType.TOP ? Direction.UP : Direction.DOWN; 66 | } else if (currentState.getValue(SlabBlock.TYPE) != targetState.getValue(SlabBlock.TYPE)) { 67 | return currentState.getValue(SlabBlock.TYPE) == SlabType.TOP ? Direction.DOWN : Direction.UP; 68 | } else { 69 | return Direction.DOWN; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | 74 | 75 | @rem Execute Gradle 76 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 77 | 78 | :end 79 | @rem End local scope for the variables with windows NT shell 80 | if %ERRORLEVEL% equ 0 goto mainEnd 81 | 82 | :fail 83 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 84 | rem the _cmd.exe /c_ return code! 85 | set EXIT_CODE=%ERRORLEVEL% 86 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 87 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 88 | exit /b %EXIT_CODE% 89 | 90 | :mainEnd 91 | if "%OS%"=="Windows_NT" endlocal 92 | 93 | :omega 94 | -------------------------------------------------------------------------------- /src/main/resources/assets/litematica-printer/lang/es_es.json: -------------------------------------------------------------------------------- 1 | { 2 | "litematica-printer.config.generic.comment.interactBlocks": "Si la impresora debe establecer o no estados de bloque.", 3 | "litematica-printer.config.generic.comment.printInAir": "Permitir que los bloques se coloquen en el aire sin necesidad de bloques de soporte debajo.", 4 | "litematica-printer.config.generic.comment.printingDebug": "Habilita el registro de depuración para la impresión.", 5 | "litematica-printer.config.generic.comment.printingInterval": "Intervalo de impresión. Los valores más bajos indican una mayor velocidad de impresión.\nSi la impresora crea \"Bloques fantasma\" o los bloques están orientados en la dirección incorrecta, aumente este valor.", 6 | "litematica-printer.config.generic.comment.printingMode": "Selección cargada de creación automática/impresión.\nTenga en cuenta que algunos servidores y complementos antitrampas no permiten la impresión.", 7 | "litematica-printer.config.generic.comment.printingRange": "Rango de ubicación del bloque de impresión\nSe recomiendan valores más bajos para los servidores.", 8 | "litematica-printer.config.generic.comment.replaceFluidSourceBlocks": "Si los bloques de fuente de fluido deben ser reemplazados o no por la impresora.", 9 | "litematica-printer.config.generic.comment.stripLogs": "Si la impresora debe o no utilizar registros normales si las versiones\nEliminadas no están disponibles y luego eliminarlas con un hacha.", 10 | "litematica-printer.config.generic.name.interactBlocks": "Bloques de interacción", 11 | "litematica-printer.config.generic.name.printingDebug": "Depuración Impresión", 12 | "litematica-printer.config.generic.name.printingInterval": "Intervalo de impresión", 13 | "litematica-printer.config.generic.name.printingMode": "Modo de impresión", 14 | "litematica-printer.config.generic.name.printingRange": "Rango de impresión", 15 | "litematica-printer.config.generic.name.replaceFluidSourceBlocks": "Reemplazar los bloques de fuente de fluido", 16 | "litematica-printer.config.generic.name.stripLogs": "Registros de corteza", 17 | "litematica-printer.config.generic.name.printInAir": "Imprimir en el aire", 18 | "litematica-printer.config.generic.prettyName.interactBlocks": "Bloques interactivos", 19 | "litematica-printer.config.generic.prettyName.printingDebug": "Depuración de impresión", 20 | "litematica-printer.config.generic.prettyName.printingInterval": "Intervalo de impresión", 21 | "litematica-printer.config.generic.prettyName.printingMode": "Modo de impresión", 22 | "litematica-printer.config.generic.prettyName.printingRange": "Gama de impresión", 23 | "litematica-printer.config.generic.prettyName.replaceFluidSourceBlocks": "Reemplazar los bloques de fuente de fluido", 24 | "litematica-printer.config.generic.prettyName.stripLogs": "Registro de corteza", 25 | "litematica-printer.config.generic.prettyName.printInAir": "Imprimir en el aire", 26 | "litematica-printer.config.hotkeys.comment.print": "Imprime mientras se presiona", 27 | "litematica-printer.config.hotkeys.comment.togglePrintingMode": "Permite alternar rápidamente entre habilitado y desactivado del modo de impresión", 28 | "litematica-printer.config.hotkeys.name.print": "Imprimir", 29 | "litematica-printer.config.hotkeys.name.togglePrintingMode": "Alternar modo de impresión", 30 | "litematica-printer.config.hotkeys.prettyName.print": "Imprimir", 31 | "litematica-printer.config.hotkeys.prettyName.togglePrintingMode": "Cambiar modo de impresión" 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/BlockReplacementGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.guides.Guide; 5 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.core.Direction; 8 | import net.minecraft.world.item.Item; 9 | import net.minecraft.world.item.ItemStack; 10 | import net.minecraft.world.level.block.CandleBlock; 11 | import net.minecraft.world.level.block.SeaPickleBlock; 12 | import net.minecraft.world.level.block.SlabBlock; 13 | import net.minecraft.world.level.block.SnowLayerBlock; 14 | import net.minecraft.world.level.block.state.properties.IntegerProperty; 15 | import net.minecraft.world.level.block.state.properties.SlabType; 16 | import net.minecraft.world.phys.BlockHitResult; 17 | import net.minecraft.world.phys.Vec3; 18 | import javax.annotation.Nullable; 19 | import java.util.HashMap; 20 | import java.util.Optional; 21 | 22 | public class BlockReplacementGuide extends PlacementGuide { 23 | private static final HashMap increasingProperties = new HashMap<>(); 24 | 25 | static { 26 | increasingProperties.put(SnowLayerBlock.LAYERS, null); 27 | increasingProperties.put(SeaPickleBlock.PICKLES, null); 28 | increasingProperties.put(CandleBlock.CANDLES, null); 29 | } 30 | 31 | private Integer currentLevel = null; 32 | private Integer targetLevel = null; 33 | private IntegerProperty increasingProperty = null; 34 | 35 | public BlockReplacementGuide(SchematicBlockState state) { 36 | super(state); 37 | 38 | for (IntegerProperty property : increasingProperties.keySet()) { 39 | if (targetState.hasProperty(property) && currentState.hasProperty(property)) { 40 | currentLevel = currentState.getValue(property); 41 | targetLevel = targetState.getValue(property); 42 | increasingProperty = property; 43 | break; 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | protected boolean getUseShift(SchematicBlockState state) { 50 | return false; 51 | } 52 | 53 | @Override 54 | public @Nullable PrinterPlacementContext getPlacementContext(LocalPlayer player) { 55 | Optional requiredItem = getRequiredItem(player); 56 | int slot = getRequiredItemStackSlot(player); 57 | if (requiredItem.isEmpty() || slot == -1) return null; 58 | 59 | BlockHitResult hitResult = new BlockHitResult(Vec3.atCenterOf(state.blockPos), Direction.UP, state.blockPos, false); 60 | return new PrinterPlacementContext(player, hitResult, requiredItem.get(), slot); 61 | } 62 | 63 | @Override 64 | public boolean canExecute(LocalPlayer player) { 65 | if (Guide.getProperty(targetState, SlabBlock.TYPE).orElse(null) == SlabType.DOUBLE && Guide.getProperty(currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) != SlabType.DOUBLE) { 66 | return super.canExecute(player); 67 | } 68 | 69 | if (currentLevel == null || targetLevel == null || increasingProperty == null) return false; 70 | if (!statesEqualIgnoreProperties(currentState, targetState, CandleBlock.LIT, increasingProperty)) return false; 71 | if (currentLevel >= targetLevel) return false; 72 | 73 | return super.canExecute(player); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/ChestGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.level.block.ChestBlock; 6 | import net.minecraft.world.level.block.state.BlockState; 7 | import net.minecraft.world.level.block.state.properties.ChestType; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | /** 13 | * Whilst making this guide, I learned that chests are much like humans. 14 | * Some prefer to stay single, and some want to connect with another of its 15 | * kind. 16 | * Also, that reversing chest connection logic is an enormous pain in the ass. I 17 | * spent way too long on this. 18 | * Thanks for coming to my ted talk 19 | */ 20 | public class ChestGuide extends GeneralPlacementGuide { 21 | public ChestGuide(SchematicBlockState state) { 22 | super(state); 23 | } 24 | 25 | @Override 26 | protected boolean getRequiresExplicitShift() { 27 | return true; 28 | } 29 | 30 | @Override 31 | public boolean skipOtherGuides() { 32 | return true; 33 | } 34 | 35 | @Override 36 | protected Optional getLookDirection() { 37 | return getProperty(targetState, ChestBlock.FACING) 38 | .flatMap(facing -> Optional.of(facing.getOpposite())); 39 | } 40 | 41 | @Override 42 | protected List getPossibleSides() { 43 | ChestType targetType = getProperty(targetState, ChestBlock.TYPE).orElse(null); 44 | Direction targetFacing = getProperty(targetState, ChestBlock.FACING).orElse(null); 45 | 46 | List sides = new ArrayList<>(); 47 | 48 | if (targetFacing == null || targetType == null) 49 | return sides; 50 | 51 | for (Direction direction : Direction.values()) { 52 | if (targetType == ChestType.SINGLE && !willConnectToSide(state, direction)) { 53 | sides.add(direction); 54 | } else if (wantsToConnectToSide(state, direction) && willConnectToSide(state, direction)) { // :D 55 | sides.add(direction); 56 | } 57 | } 58 | 59 | // Place single chests if you cannot connect any existing chests 60 | if (sides.isEmpty()) { 61 | for (Direction direction : Direction.values()) { 62 | if (!wantsToConnectToSide(state, direction) && !willConnectToSide(state, direction)) { 63 | sides.add(direction); 64 | } 65 | } 66 | } 67 | 68 | return sides; 69 | } 70 | 71 | private boolean willConnectToSide(SchematicBlockState state, Direction neighborDirection) { 72 | BlockState neighbor = state.offset(neighborDirection).currentState; 73 | ChestType neighborType = getProperty(neighbor, ChestBlock.TYPE).orElse(null); 74 | Direction neighborFacing = getProperty(neighbor, ChestBlock.FACING).orElse(null); 75 | Direction facing = getProperty(state.targetState, ChestBlock.FACING).orElse(null); 76 | 77 | if (neighborType == null || neighborFacing == null || facing == null) return false; 78 | 79 | if (facing.getAxis() == neighborDirection.getAxis() || neighborDirection.getAxis() == Direction.Axis.Y) 80 | return false; 81 | 82 | return neighborType == ChestType.SINGLE && neighborFacing == facing 83 | && state.targetState.getBlock() == neighbor.getBlock(); 84 | } 85 | 86 | private boolean wantsToConnectToSide(SchematicBlockState state, Direction direction) { 87 | ChestType type = getProperty(state.targetState, ChestBlock.TYPE).orElse(null); 88 | Direction facing = getProperty(state.targetState, ChestBlock.FACING).orElse(null); 89 | if (type == null || facing == null || type == ChestType.SINGLE) return false; 90 | 91 | Direction neighborDirection = type == ChestType.LEFT ? facing.getClockWise() : facing.getCounterClockWise(); 92 | 93 | return direction == neighborDirection; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/Guides.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides; 2 | 3 | import java.util.ArrayList; 4 | import me.aleksilassila.litematica.printer.SchematicBlockState; 5 | import me.aleksilassila.litematica.printer.guides.interaction.*; 6 | import me.aleksilassila.litematica.printer.guides.placement.*; 7 | 8 | import net.minecraft.util.Tuple; 9 | import net.minecraft.world.level.block.*; 10 | 11 | public class Guides { 12 | protected final static ArrayList, Class[]>> guides = new ArrayList<>(); 13 | 14 | @SafeVarargs 15 | protected static void registerGuide(Class guideClass, Class... blocks) { 16 | guides.add(new Tuple<>(guideClass, blocks)); 17 | } 18 | 19 | static { 20 | // registerGuide(SkipGuide.class, AbstractSignBlock.class, SkullBlock.class, BannerBlock.class); 21 | 22 | registerGuide(RotatingBlockGuide.class, AbstractSkullBlock.class, SignBlock.class, AbstractBannerBlock.class); 23 | registerGuide(SlabGuide.class, SlabBlock.class); 24 | registerGuide(TorchGuide.class, TorchBlock.class); 25 | registerGuide(FarmlandGuide.class, FarmBlock.class); 26 | registerGuide(TillingGuide.class, FarmBlock.class); 27 | registerGuide(RailGuesserGuide.class, BaseRailBlock.class); 28 | registerGuide(ChestGuide.class, ChestBlock.class); 29 | registerGuide(FlowerPotGuide.class, FlowerPotBlock.class); 30 | registerGuide(FlowerPotFillGuide.class, FlowerPotBlock.class); 31 | 32 | registerGuide(PropertySpecificGuesserGuide.class, 33 | RepeaterBlock.class, ComparatorBlock.class, RedStoneWireBlock.class, RedstoneTorchBlock.class, 34 | BambooStalkBlock.class, CactusBlock.class, SaplingBlock.class, ScaffoldingBlock.class, 35 | PointedDripstoneBlock.class, 36 | CrossCollisionBlock.class, DoorBlock.class, TrapDoorBlock.class, FenceGateBlock.class, 37 | ChestBlock.class, 38 | SnowLayerBlock.class, SeaPickleBlock.class, CandleBlock.class, LeverBlock.class, EndPortalFrameBlock.class, 39 | NoteBlock.class, CampfireBlock.class, PoweredRailBlock.class, LeavesBlock.class, 40 | TripWireHookBlock.class); 41 | registerGuide(FallingBlockGuide.class, FallingBlock.class); 42 | registerGuide(BlockIndifferentGuesserGuide.class, BambooStalkBlock.class, BigDripleafStemBlock.class, 43 | BigDripleafBlock.class, 44 | TwistingVinesPlantBlock.class, TripWireBlock.class); 45 | 46 | registerGuide(CampfireExtinguishGuide.class, CampfireBlock.class); 47 | registerGuide(LightCandleGuide.class, AbstractCandleBlock.class); 48 | registerGuide(EnderEyeGuide.class, EndPortalFrameBlock.class); 49 | registerGuide(CycleStateGuide.class, 50 | DoorBlock.class, FenceGateBlock.class, TrapDoorBlock.class, 51 | LeverBlock.class, 52 | RepeaterBlock.class, ComparatorBlock.class, NoteBlock.class); 53 | registerGuide(BlockReplacementGuide.class, SnowLayerBlock.class, SeaPickleBlock.class, CandleBlock.class, 54 | SlabBlock.class); 55 | registerGuide(LogGuide.class); 56 | registerGuide(LogStrippingGuide.class); 57 | registerGuide(GuesserGuide.class); 58 | } 59 | 60 | public ArrayList, Class[]>> getGuides() { 61 | return guides; 62 | } 63 | 64 | public Guide[] getInteractionGuides(SchematicBlockState state) { 65 | ArrayList, Class[]>> guides = getGuides(); 66 | 67 | ArrayList applicableGuides = new ArrayList<>(); 68 | for (Tuple, Class[]> guidePair : guides) { 69 | try { 70 | if (guidePair.getB().length == 0) { 71 | applicableGuides 72 | .add(guidePair.getA().getConstructor(SchematicBlockState.class).newInstance(state)); 73 | continue; 74 | } 75 | 76 | for (Class clazz : guidePair.getB()) { 77 | if (clazz.isInstance(state.targetState.getBlock())) { 78 | applicableGuides 79 | .add(guidePair.getA().getConstructor(SchematicBlockState.class).newInstance(state)); 80 | } 81 | } 82 | } catch (Exception ignored) { 83 | } 84 | } 85 | 86 | return applicableGuides.toArray(Guide[]::new); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Litematica Printer 2 | 3 | ![GitHub issues](https://img.shields.io/github/issues-raw/aleksilassila/litematica-printer) 4 | ![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/aleksilassila/litematica-printer) 5 | ![GitHub all releases](https://img.shields.io/github/downloads/aleksilassila/litematica-printer/total) 6 | ![GitHub Repo stars](https://img.shields.io/github/stars/aleksilassila/litematica-printer) 7 | 8 | This extension adds printing functionality for [Litematica fabric](https://github.com/maruohon/litematica). Printer 9 | allows players to build big structures more quickly by automatically placing the correct blocks around you. 10 | 11 | ![Demo](printer_demo.gif) 12 | 13 | ## Installation 14 | 15 | 1. Download and install [Fabric](https://fabricmc.net/use/installer/) if you haven't already. 16 | 2. Download the latest Litematica Printer release for your Minecraft version from the 17 | [releases page](https://github.com/aleksilassila/litematica-printer/releases) (The files can be found under 18 | "assets"). 19 | 3. Download [Litematica + MaLiLib](https://www.curseforge.com/minecraft/mc-mods/litematica) 20 | and [Fabric API](https://www.curseforge.com/minecraft/mc-mods/fabric-api/) (≠ Fabric). 21 | 4. Place the downloaded .jar files in your `mods/` folder. 22 | 23 | [If this is the first fabric mod you are installing, here's an informative video on how to install Fabric mods.](https://www.youtube.com/watch?v=x7gmfib4gHg) 24 | 25 | ## How To Use 26 | 27 | Using the printer is straightforward: You can toggle the feature by pressing `CAPS_LOCK` by default. To configure 28 | variables such as 29 | printing speed and range, open Litematica's settings by pressing `M + C` and navigate to "Generic" tab. Printer's 30 | configuration can be 31 | found at the bottom of the page. You can also rebind the printing toggle under "Hotkeys" tab. Holding down `V` by 32 | default will also 33 | print regardless if the printer is toggled on or off. 34 | 35 | ## Issues 36 | 37 | If you have issues with the printer, **do not** bother the original creator of 38 | Litematica (maruohon) with them. Contact me instead. Feature requests or bugs can 39 | be reported via [GitHub issues](https://github.com/aleksilassila/litematica-printer/issues), 40 | or in [Discord](https://discord.gg/enypPQh6pz). I'll try to keep a todo list of things 41 | I'm planning to implement and fix, so please look for duplicates there first. 42 | 43 | Before creating an issue, make sure you are using the latest version of the mod. 44 | To make fixing bugs easier, include the following information in your issue: 45 | 46 | - Minecraft version 47 | - Litematica version 48 | - Printer version 49 | - Detailed description of how to reproduce the issue 50 | - If you can, any additional information, such as error logs, screenshots or **the incorrectly printed schematics**. 51 | 52 | ### List of know issues 53 | 54 | Currently, the following features are still broken or missing: 55 | 56 | - Placing liquids (printing **in** liquids works though) 57 | - Printing without support directly in air (printInAir) 58 | - Current algorithm for placing rails isn't perfect, 59 | sometimes it can't place all the rails (to avoid placing anything incorrectly). 60 | - Legit mode? (for anticheats) 61 | 62 | Also, I have decided that features that fix existing builds, 63 | such as automatic excavation or correcting incorrectly placed blocks are out of the scope of this mod. 64 | 65 | ## Building and Contributing 66 | 67 | Each Minecraft version has its own submodule, that has the default fabric mod development tasks 68 | and contains the version-specific code. To reduce the amount of work I have to do to make 69 | it work for multiple Minecraft versions, I created this hacky gradle script that copies the 70 | common code over to the other version implementations. Currently, the script copies everything, 71 | except `implementation/` folder, which should therefore be the only places containing any 72 | version specific code. 73 | 74 | If you want to make changes to the mod, I would recommend you to first implement them for 75 | the latest Minecraft version (1.19), and then running the `syncImplementations` gradle task, 76 | found **in the same subproject** as your changes, to copy the common code of that submodule 77 | to the other implementations. After that you will only have to write / copy manually 78 | the version-specific code (found in the `implementation` folder) to the other versions and do some testing to ensure 79 | everything works. 80 | 81 | Contributions are welcome and appreciated! I have recently rewritten the whole project, 82 | so that it would be much easier to work with. 83 | 84 | Also, if you know a better way to develop for multiple 85 | Minecraft versions that doesn't involve multiple git branches or hacky gradle scripts 86 | (perhaps a way to share common code between the implementations?), please let me know. 87 | 88 | Useful gradle tasks: 89 | - `[v1_19/v1_18/v1_17]:syncImplementations` 90 | - Copy over common code to other implementations 91 | - `buildAll` 92 | - Build all implementations and copy their jars to `build/` directory for easy distribution. 93 | - `[v1_19/v1_18/v1_17]:runClient` 94 | - Start the target Minecraft version 95 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/implementation/mixin/MixinClientPlayerEntity.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.implementation.mixin; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import fi.dy.masa.litematica.world.SchematicWorldHandler; 5 | import fi.dy.masa.litematica.world.WorldSchematic; 6 | import me.aleksilassila.litematica.printer.LitematicaMixinMod; 7 | import me.aleksilassila.litematica.printer.Printer; 8 | import me.aleksilassila.litematica.printer.SchematicBlockState; 9 | import me.aleksilassila.litematica.printer.UpdateChecker; 10 | import net.minecraft.client.Minecraft; 11 | import net.minecraft.client.multiplayer.ClientLevel; 12 | import net.minecraft.client.multiplayer.ClientPacketListener; 13 | import net.minecraft.client.player.AbstractClientPlayer; 14 | import net.minecraft.client.player.LocalPlayer; 15 | import net.minecraft.network.chat.Component; 16 | import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; 17 | import net.minecraft.world.level.block.entity.BlockEntity; 18 | import net.minecraft.world.level.block.entity.SignBlockEntity; 19 | import org.spongepowered.asm.mixin.Final; 20 | import org.spongepowered.asm.mixin.Mixin; 21 | import org.spongepowered.asm.mixin.Shadow; 22 | import org.spongepowered.asm.mixin.Unique; 23 | import org.spongepowered.asm.mixin.injection.At; 24 | import org.spongepowered.asm.mixin.injection.Inject; 25 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 26 | 27 | import java.util.Optional; 28 | 29 | @Mixin(LocalPlayer.class) 30 | public class MixinClientPlayerEntity extends AbstractClientPlayer { 31 | @Unique 32 | private static boolean didCheckForUpdates = false; 33 | @Final 34 | @Shadow 35 | protected Minecraft minecraft; 36 | @Final 37 | @Shadow 38 | public ClientPacketListener connection; 39 | 40 | public MixinClientPlayerEntity(ClientLevel world, GameProfile profile) { 41 | super(world, profile); 42 | } 43 | 44 | @Inject(at = @At("TAIL"), method = "tick") 45 | public void tick(CallbackInfo ci) { 46 | LocalPlayer clientPlayer = (LocalPlayer) (Object) this; 47 | 48 | if (!didCheckForUpdates) { 49 | didCheckForUpdates = true; 50 | // checkForUpdates(); 51 | } 52 | 53 | if (LitematicaMixinMod.printer == null || LitematicaMixinMod.printer.player != clientPlayer) { 54 | Printer.printDebug("Initializing printer, player: {}, client: {}", clientPlayer, minecraft); 55 | LitematicaMixinMod.printer = new Printer(minecraft, clientPlayer); 56 | } 57 | 58 | // Dirty optimization 59 | boolean didFindPlacement = true; 60 | for (int i = 0; i < 10; i++) { 61 | if (didFindPlacement) { 62 | didFindPlacement = LitematicaMixinMod.printer.onGameTick(); 63 | } 64 | LitematicaMixinMod.printer.actionHandler.onGameTick(); 65 | } 66 | } 67 | 68 | @Unique 69 | public void checkForUpdates() { 70 | new Thread(() -> { 71 | String version = UpdateChecker.version; 72 | String newVersion = UpdateChecker.getPrinterVersion(); 73 | 74 | Printer.printDebug("Current version: [{}], detected version [{}]", version, newVersion); 75 | 76 | if (!version.equals(newVersion)) { 77 | minecraft.gui.getChat().addMessage(Component.literal("New version of Litematica Printer available in https://github.com/aleksilassila/litematica-printer/releases")); 78 | } 79 | }).start(); 80 | } 81 | 82 | @Inject(method = "openTextEdit", at = @At("HEAD"), cancellable = true) 83 | public void openEditSignScreen(SignBlockEntity sign, boolean front, CallbackInfo ci) { 84 | getTargetSignEntity(sign).ifPresent(signBlockEntity -> 85 | { 86 | ServerboundSignUpdatePacket packet = new ServerboundSignUpdatePacket(sign.getBlockPos(), 87 | front, 88 | signBlockEntity.getText(front).getMessage(0, false).getString(), 89 | signBlockEntity.getText(front).getMessage(1, false).getString(), 90 | signBlockEntity.getText(front).getMessage(2, false).getString(), 91 | signBlockEntity.getText(front).getMessage(3, false).getString()); 92 | this.connection.send(packet); 93 | ci.cancel(); 94 | }); 95 | } 96 | 97 | @Unique 98 | private Optional getTargetSignEntity(SignBlockEntity sign) { 99 | WorldSchematic worldSchematic = SchematicWorldHandler.getSchematicWorld(); 100 | if (sign.getLevel() == null || worldSchematic == null) { 101 | return Optional.empty(); 102 | } 103 | 104 | SchematicBlockState state = new SchematicBlockState(sign.getLevel(), worldSchematic, sign.getBlockPos()); 105 | BlockEntity targetBlockEntity = worldSchematic.getBlockEntity(state.blockPos); 106 | 107 | if (targetBlockEntity instanceof SignBlockEntity targetSignEntity) { 108 | return Optional.of(targetSignEntity); 109 | } 110 | 111 | return Optional.empty(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/Guide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.actions.Action; 5 | import me.aleksilassila.litematica.printer.implementation.BlockHelperImpl; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.world.entity.player.Inventory; 8 | import net.minecraft.world.item.ItemStack; 9 | import net.minecraft.world.level.block.CoralPlantBlock; 10 | import net.minecraft.world.level.block.state.BlockState; 11 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 12 | import net.minecraft.world.level.block.state.properties.Property; 13 | import javax.annotation.Nonnull; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | abstract public class Guide extends BlockHelperImpl { 18 | protected final SchematicBlockState state; 19 | protected final BlockState currentState; 20 | protected final BlockState targetState; 21 | 22 | public Guide(SchematicBlockState state) { 23 | this.state = state; 24 | this.currentState = state.currentState; 25 | this.targetState = state.targetState; 26 | } 27 | 28 | protected boolean playerHasRightItem(LocalPlayer player) { 29 | return getRequiredItemStackSlot(player) != -1; 30 | } 31 | 32 | protected int getSlotWithItem(LocalPlayer player, ItemStack itemStack) { 33 | Inventory inventory = player.getInventory(); 34 | 35 | for (int i = 0; i < inventory.getNonEquipmentItems().size(); ++i) { 36 | if (itemStack.isEmpty() && inventory.getNonEquipmentItems().get(i).is(itemStack.getItem())) { 37 | return i; 38 | } 39 | if (!inventory.getNonEquipmentItems().get(i).isEmpty() && ItemStack.isSameItem(inventory.getNonEquipmentItems().get(i), itemStack)) { 40 | return i; 41 | } 42 | } 43 | 44 | return -1; 45 | } 46 | 47 | protected int getRequiredItemStackSlot(LocalPlayer player) { 48 | if (player.getAbilities().instabuild) { 49 | return player.getInventory().getSelectedSlot(); 50 | } 51 | 52 | Optional requiredItem = getRequiredItem(player); 53 | return requiredItem.map(itemStack -> getSlotWithItem(player, itemStack)).orElse(-1); 54 | } 55 | 56 | public boolean canExecute(LocalPlayer player) { 57 | if (!playerHasRightItem(player)) { 58 | return false; 59 | } 60 | 61 | BlockState targetState = state.targetState; 62 | BlockState currentState = state.currentState; 63 | 64 | return !statesEqual(targetState, currentState); 65 | } 66 | 67 | abstract public @Nonnull List execute(LocalPlayer player); 68 | 69 | abstract protected @Nonnull List getRequiredItems(); 70 | 71 | /** 72 | * Returns the first required item that the player has access to, 73 | * or empty if the items are inaccessible. 74 | */ 75 | protected Optional getRequiredItem(LocalPlayer player) { 76 | List requiredItems = getRequiredItems(); 77 | 78 | for (ItemStack requiredItem : requiredItems) { 79 | if (player.getAbilities().instabuild) { 80 | return Optional.of(requiredItem); 81 | } 82 | 83 | int slot = getSlotWithItem(player, requiredItem); 84 | if (slot > -1) { 85 | return Optional.of(requiredItem); 86 | } 87 | } 88 | 89 | return Optional.empty(); 90 | } 91 | 92 | protected boolean statesEqualIgnoreProperties(BlockState state1, BlockState state2, 93 | Property... propertiesToIgnore) { 94 | if (state1.getBlock() != state2.getBlock()) { 95 | return false; 96 | } 97 | 98 | loop: 99 | for (Property property : state1.getProperties()) { 100 | if (property == BlockStateProperties.WATERLOGGED && !(state1.getBlock() instanceof CoralPlantBlock)) { 101 | continue; 102 | } 103 | 104 | for (Property ignoredProperty : propertiesToIgnore) { 105 | if (property == ignoredProperty) { 106 | continue loop; 107 | } 108 | } 109 | 110 | try { 111 | if (!state1.getValue(property).equals(state2.getValue(property))) { 112 | return false; 113 | } 114 | } catch (Exception e) { 115 | return false; 116 | } 117 | } 118 | 119 | return true; 120 | } 121 | 122 | protected static > Optional getProperty(BlockState blockState, Property property) { 123 | if (blockState.hasProperty(property)) { 124 | return Optional.of(blockState.getValue(property)); 125 | } 126 | return Optional.empty(); 127 | } 128 | 129 | /** 130 | * Returns true if 131 | */ 132 | protected boolean statesEqual(BlockState state1, BlockState state2) { 133 | return statesEqualIgnoreProperties(state1, state2); 134 | } 135 | 136 | public boolean skipOtherGuides() { 137 | return false; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/RailGuesserGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.level.block.state.BlockState; 6 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; 7 | import net.minecraft.world.level.block.state.properties.RailShape; 8 | import java.util.*; 9 | 10 | public class RailGuesserGuide extends GuesserGuide { 11 | static final RailShape[] STRAIGHT_RAIL_SHAPES = new RailShape[]{ 12 | RailShape.NORTH_SOUTH, 13 | RailShape.EAST_WEST 14 | }; 15 | 16 | public RailGuesserGuide(SchematicBlockState state) { 17 | super(state); 18 | } 19 | 20 | @Override 21 | public boolean skipOtherGuides() { 22 | return true; 23 | } 24 | 25 | @Override 26 | protected boolean statesEqual(BlockState resultState, BlockState targetState) { 27 | if (!wouldConnectCorrectly()) 28 | return false; 29 | // if (wouldBlockAnotherConnection()) return false; 30 | /* 31 | * TODO: Fully working rail guesser 32 | * If has a neighbor that: 33 | * - Has not been placed yet 34 | * - OR Has been placed but can change shape 35 | * - AND this placement should connect to only one rail, that is not the 36 | * neighbor 37 | * Then return false 38 | */ 39 | 40 | if (getRailShape(resultState).isPresent()) { 41 | if (Arrays.stream(STRAIGHT_RAIL_SHAPES) 42 | .anyMatch(shape -> shape == getRailShape(resultState).orElse(null))) { 43 | return super.statesEqualIgnoreProperties(resultState, targetState, BlockStateProperties.RAIL_SHAPE, 44 | BlockStateProperties.RAIL_SHAPE_STRAIGHT, BlockStateProperties.POWERED); 45 | } 46 | } 47 | 48 | return super.statesEqual(resultState, targetState); 49 | } 50 | 51 | private boolean wouldConnectCorrectly() { 52 | RailShape targetShape = getRailShape(state.targetState).orElse(null); 53 | if (targetShape == null) 54 | return false; 55 | 56 | List allowedConnections = getRailDirections(targetShape); 57 | 58 | List possibleConnections = new ArrayList<>(); 59 | for (Direction d : Direction.values()) { 60 | if (d.getAxis().isVertical()) 61 | continue; 62 | SchematicBlockState neighbor = state.offset(d); 63 | 64 | if (hasFreeConnections(neighbor)) { 65 | possibleConnections.add(d); 66 | } 67 | } 68 | 69 | if (possibleConnections.size() > 2) 70 | return false; 71 | 72 | return new HashSet<>(allowedConnections).containsAll(possibleConnections); 73 | } 74 | 75 | // private boolean wouldBlockAnotherConnection() { 76 | // List possibleConnections = new ArrayList<>(); 77 | // 78 | // for (Direction d : Direction.values()) { 79 | // if (d.getAxis().isVertical()) continue; 80 | // SchematicBlockState neighbor = state.offset(d); 81 | // 82 | // if (couldConnectWrongly(neighbor)) { 83 | // possibleConnections.add(d); 84 | // } 85 | // } 86 | // 87 | // return possibleConnections.size() > 1; 88 | // } 89 | 90 | private boolean hasFreeConnections(SchematicBlockState state) { 91 | List possibleConnections = getRailDirections(state); 92 | if (possibleConnections.isEmpty()) 93 | return false; 94 | 95 | for (Direction d : possibleConnections) { 96 | SchematicBlockState neighbor = state.offset(d); 97 | // FIXME --> when will this ever not be equal? <.< 98 | if (neighbor.currentState.getBlock() != neighbor.currentState.getBlock()) { 99 | return false; 100 | } 101 | } 102 | 103 | return possibleConnections.stream().anyMatch(possibleDirection -> { 104 | SchematicBlockState neighbor = state.offset(possibleDirection); 105 | return !getRailDirections(neighbor).contains(possibleDirection.getOpposite()); 106 | }); 107 | } 108 | 109 | private List getRailDirections(SchematicBlockState state) { 110 | RailShape shape = getRailShape(state.currentState).orElse(null); 111 | if (shape == null) 112 | return new ArrayList<>(); 113 | 114 | return getRailDirections(shape); 115 | } 116 | 117 | private List getRailDirections(RailShape railShape) { 118 | String name = railShape.getName(); 119 | 120 | if (railShape.isSlope()) { 121 | Direction d = Direction.valueOf(name.replace("ascending_", "").toUpperCase()); 122 | return Arrays.asList(d, d.getOpposite()); 123 | } else { 124 | Direction d1 = Direction.valueOf(name.split("_")[0].toUpperCase()); 125 | Direction d2 = Direction.valueOf(name.split("_")[1].toUpperCase()); 126 | return Arrays.asList(d1, d2); 127 | } 128 | } 129 | 130 | Optional getRailShape(BlockState state) { 131 | Optional shape = getProperty(state, BlockStateProperties.RAIL_SHAPE); 132 | if (shape.isEmpty()) 133 | return getProperty(state, BlockStateProperties.RAIL_SHAPE_STRAIGHT); 134 | return shape; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/Printer.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer; 2 | 3 | import fi.dy.masa.litematica.data.DataManager; 4 | import fi.dy.masa.litematica.util.RayTraceUtils; 5 | import fi.dy.masa.litematica.world.SchematicWorldHandler; 6 | import fi.dy.masa.litematica.world.WorldSchematic; 7 | import me.aleksilassila.litematica.printer.actions.Action; 8 | import me.aleksilassila.litematica.printer.config.Configs; 9 | import me.aleksilassila.litematica.printer.config.Hotkeys; 10 | import me.aleksilassila.litematica.printer.guides.Guide; 11 | import me.aleksilassila.litematica.printer.guides.Guides; 12 | import net.minecraft.client.Minecraft; 13 | import net.minecraft.client.player.LocalPlayer; 14 | import net.minecraft.core.BlockPos; 15 | import net.minecraft.util.Mth; 16 | import net.minecraft.world.entity.player.Abilities; 17 | import net.minecraft.world.phys.BlockHitResult; 18 | import net.minecraft.world.phys.Vec3; 19 | import org.apache.logging.log4j.LogManager; 20 | import org.apache.logging.log4j.Logger; 21 | 22 | import javax.annotation.Nonnull; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public class Printer { 27 | public static final Logger logger = LogManager.getLogger(PrinterReference.MOD_ID); 28 | @Nonnull 29 | public final LocalPlayer player; 30 | public final ActionHandler actionHandler; 31 | private final Guides interactionGuides = new Guides(); 32 | 33 | public Printer(@Nonnull Minecraft client, @Nonnull LocalPlayer player) { 34 | this.player = player; 35 | this.actionHandler = new ActionHandler(client, player); 36 | } 37 | 38 | public boolean onGameTick() { 39 | WorldSchematic worldSchematic = SchematicWorldHandler.getSchematicWorld(); 40 | 41 | if (!actionHandler.acceptsActions()) { 42 | return false; 43 | } 44 | 45 | if (worldSchematic == null) { 46 | return false; 47 | } 48 | 49 | if (!Configs.PRINT_MODE.getBooleanValue() && !Hotkeys.PRINT.getKeybind().isPressed()) { 50 | return false; 51 | } 52 | 53 | Abilities abilities = player.getAbilities(); 54 | if (!abilities.mayBuild) { 55 | return false; 56 | } 57 | 58 | List positions = getReachablePositions(); 59 | findBlock: 60 | for (BlockPos position : positions) { 61 | SchematicBlockState state = new SchematicBlockState(player.level(), worldSchematic, position); 62 | if (state.targetState.equals(state.currentState) || state.targetState.isAir()) { 63 | continue; 64 | } 65 | 66 | Guide[] guides = interactionGuides.getInteractionGuides(state); 67 | 68 | BlockHitResult result = RayTraceUtils.traceToSchematicWorld(player, 10, true, true); 69 | boolean isCurrentlyLookingSchematic = result != null && result.getBlockPos().equals(position); 70 | 71 | for (Guide guide : guides) { 72 | // Add INTERACT_BLOCKS pull by DarkReaper231 73 | if (guide.canExecute(player) && Configs.INTERACT_BLOCKS.getBooleanValue()) { 74 | printDebug("Executing {} for {}", guide, state); 75 | List actions = guide.execute(player); 76 | actionHandler.addActions(actions.toArray(Action[]::new)); 77 | return true; 78 | } 79 | if (guide.skipOtherGuides()) { 80 | continue findBlock; 81 | } 82 | } 83 | } 84 | 85 | return false; 86 | } 87 | 88 | private List getReachablePositions() { 89 | int maxReach = (int) Math.ceil(Configs.PRINTING_RANGE.getDoubleValue()); 90 | double maxReachSquared = Mth.square(Configs.PRINTING_RANGE.getDoubleValue()); 91 | 92 | ArrayList positions = new ArrayList<>(); 93 | 94 | for (int y = -maxReach; y < maxReach + 1; y++) { 95 | for (int x = -maxReach; x < maxReach + 1; x++) { 96 | for (int z = -maxReach; z < maxReach + 1; z++) { 97 | BlockPos blockPos = player.blockPosition().north(x).west(z).above(y); 98 | 99 | if (!DataManager.getRenderLayerRange().isPositionWithinRange(blockPos)) { 100 | continue; 101 | } 102 | if (this.player.getEyePosition().distanceToSqr(Vec3.atCenterOf(blockPos)) > maxReachSquared) { 103 | continue; 104 | } 105 | 106 | positions.add(blockPos); 107 | } 108 | } 109 | } 110 | 111 | return positions.stream() 112 | .filter(p -> 113 | { 114 | Vec3 vec = Vec3.atCenterOf(p); 115 | return this.player.position().distanceToSqr(vec) > 1 116 | && this.player.getEyePosition().distanceToSqr(vec) > 1; 117 | }) 118 | .sorted((a, b) -> 119 | { 120 | double aDistance = this.player.position().distanceToSqr(Vec3.atCenterOf(a)); 121 | double bDistance = this.player.position().distanceToSqr(Vec3.atCenterOf(b)); 122 | return Double.compare(aDistance, bDistance); 123 | }).toList(); 124 | } 125 | 126 | public static void printDebug(String key, Object... args) { 127 | if (Configs.PRINT_DEBUG.getBooleanValue()) { 128 | logger.info(key, args); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/actions/PrepareAction.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.actions; 2 | 3 | import me.aleksilassila.litematica.printer.Printer; 4 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.core.Direction; 8 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; 9 | import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; 10 | import net.minecraft.world.InteractionHand; 11 | import net.minecraft.world.entity.player.Input; 12 | import net.minecraft.world.entity.player.Inventory; 13 | import net.minecraft.world.item.ItemStack; 14 | import fi.dy.masa.litematica.util.InventoryUtils; 15 | 16 | public class PrepareAction extends Action { 17 | public final PrinterPlacementContext context; 18 | public boolean modifyYaw = true; 19 | public boolean modifyPitch = true; 20 | public float yaw = 0; 21 | public float pitch = 0; 22 | 23 | public PrepareAction(PrinterPlacementContext context) { 24 | this.context = context; 25 | Direction lookDirection = context.lookDirection; 26 | 27 | if (lookDirection != null && lookDirection.getAxis().isHorizontal()) { 28 | this.yaw = lookDirection.toYRot(); 29 | } else { 30 | this.modifyYaw = false; 31 | } 32 | 33 | if (lookDirection == Direction.UP) { 34 | this.pitch = -90; 35 | } else if (lookDirection == Direction.DOWN) { 36 | this.pitch = 90; 37 | } else if (lookDirection != null) { 38 | this.pitch = 0; 39 | } else { 40 | this.modifyPitch = false; 41 | } 42 | } 43 | 44 | public PrepareAction(PrinterPlacementContext context, float yaw, float pitch) { 45 | this.context = context; 46 | 47 | this.yaw = yaw; 48 | this.pitch = pitch; 49 | } 50 | 51 | @Override 52 | public void send(Minecraft client, LocalPlayer player) { 53 | ItemStack itemStack = context.getItemInHand(); 54 | int slot = context.requiredItemSlot; 55 | 56 | if (itemStack != null && !itemStack.isEmpty() && client.gameMode != null) { 57 | Printer.printDebug("PrepareAction#send(): slot [{}] // itemStack [{}]", slot, itemStack.toString()); 58 | // This thing is straight from MinecraftClient#doItemPick() 59 | Inventory inventory = player.getInventory(); 60 | 61 | if (player.getAbilities().instabuild) { 62 | this.addPickBlock(inventory, itemStack); 63 | client.gameMode.handleCreativeModeItemAdd(player.getItemInHand(InteractionHand.MAIN_HAND), 36 + inventory.getSelectedSlot()); 64 | } else if (slot != -1) { 65 | if (Inventory.isHotbarSlot(slot)) { 66 | inventory.setSelectedSlot(slot); 67 | } else { 68 | // TODO --> test this (pickFromInventory has been REMOVED) 69 | //client.interactionManager.pickFromInventory(slot); 70 | InventoryUtils.setPickedItemToHand(slot, itemStack, client); 71 | } 72 | } 73 | } 74 | 75 | if (modifyPitch || modifyYaw) { 76 | float yaw = modifyYaw ? this.yaw : player.getYRot(); 77 | float pitch = modifyPitch ? this.pitch : player.getXRot(); 78 | 79 | ServerboundMovePlayerPacket packet = new ServerboundMovePlayerPacket.PosRot(player.getX(), player.getY(), player.getZ(), yaw, 80 | pitch, player.onGround(), player.horizontalCollision); 81 | 82 | player.connection.send(packet); 83 | } 84 | 85 | if (context.shouldSneak) { 86 | player.input.keyPresses = new Input(player.input.keyPresses.forward(), player.input.keyPresses.backward(), player.input.keyPresses.left(), player.input.keyPresses.right(), player.input.keyPresses.jump(), true, player.input.keyPresses.sprint()); 87 | player.connection.send(new ServerboundPlayerInputPacket(player.input.keyPresses)); 88 | } else { 89 | player.input.keyPresses = new Input(player.input.keyPresses.forward(), player.input.keyPresses.backward(), player.input.keyPresses.left(), player.input.keyPresses.right(), player.input.keyPresses.jump(), false, player.input.keyPresses.sprint()); 90 | player.connection.send(new ServerboundPlayerInputPacket(player.input.keyPresses)); 91 | } 92 | } 93 | 94 | private void addPickBlock(Inventory inv, ItemStack stack) { 95 | int slot = inv.findSlotMatchingItem(stack); 96 | 97 | if (Inventory.isHotbarSlot(slot)) { 98 | inv.setSelectedSlot(slot); 99 | } else { 100 | if (slot == -1) { 101 | inv.setSelectedSlot(inv.getSuitableHotbarSlot()); 102 | 103 | if (!inv.getNonEquipmentItems().get(inv.getSelectedSlot()).isEmpty()) { 104 | int empty = inv.getFreeSlot(); 105 | 106 | if (empty != -1) { 107 | inv.getNonEquipmentItems().set(empty, inv.getNonEquipmentItems().get(inv.getSelectedSlot())); 108 | } 109 | } 110 | inv.getNonEquipmentItems().set(inv.getSelectedSlot(), stack); 111 | } else { 112 | inv.pickSlot(slot); 113 | } 114 | } 115 | } 116 | 117 | @Override 118 | public String toString() { 119 | return "PrepareAction{" + 120 | "context=" + context + 121 | '}'; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/GeneralPlacementGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.Printer; 4 | import me.aleksilassila.litematica.printer.SchematicBlockState; 5 | import me.aleksilassila.litematica.printer.config.Configs; 6 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 7 | import net.minecraft.client.player.LocalPlayer; 8 | import net.minecraft.core.Direction; 9 | import net.minecraft.world.item.ItemStack; 10 | import net.minecraft.world.level.block.SlabBlock; 11 | import net.minecraft.world.level.block.state.properties.SlabType; 12 | import net.minecraft.world.phys.BlockHitResult; 13 | import net.minecraft.world.phys.Vec3; 14 | import javax.annotation.Nullable; 15 | import java.util.ArrayList; 16 | import java.util.Arrays; 17 | import java.util.List; 18 | import java.util.Optional; 19 | 20 | /** 21 | * An old school guide where there are defined specific conditions 22 | * for player state depending on the block being placed. 23 | */ 24 | public class GeneralPlacementGuide extends PlacementGuide { 25 | public GeneralPlacementGuide(SchematicBlockState state) { 26 | super(state); 27 | } 28 | 29 | protected List getPossibleSides() { 30 | return Arrays.asList(Direction.values()); 31 | } 32 | 33 | protected Optional getLookDirection() { 34 | return Optional.empty(); 35 | } 36 | 37 | protected boolean getRequiresSupport() { 38 | return false; 39 | } 40 | 41 | protected boolean getRequiresExplicitShift() { 42 | return false; 43 | } 44 | 45 | protected Vec3 getHitModifier(Direction validSide) { 46 | return new Vec3(0, 0, 0); 47 | } 48 | 49 | private Optional getValidSide(SchematicBlockState state) { 50 | boolean printInAir = Configs.PRINT_IN_AIR.getBooleanValue(); 51 | 52 | List sides = getPossibleSides(); 53 | 54 | if (sides.isEmpty()) { 55 | return Optional.empty(); 56 | } 57 | 58 | if (printInAir && !getRequiresSupport()) { 59 | // When printInAir is enabled, we can place directly without support 60 | return Optional.of(Direction.UP); // Use any direction as we'll target the position directly 61 | } 62 | 63 | List validSides = new ArrayList<>(); 64 | for (Direction side : sides) { 65 | SchematicBlockState neighborState = state.offset(side); 66 | 67 | if (getProperty(neighborState.currentState, SlabBlock.TYPE).orElse(null) == SlabType.DOUBLE) { 68 | validSides.add(side); 69 | continue; 70 | } 71 | 72 | if (canBeClicked(neighborState.world, neighborState.blockPos) && // Handle unclickable grass for example 73 | !neighborState.currentState.canBeReplaced()) 74 | validSides.add(side); 75 | } 76 | 77 | for (Direction validSide : validSides) { 78 | if (!isInteractive(state.offset(validSide).currentState.getBlock())) { 79 | return Optional.of(validSide); 80 | } 81 | } 82 | 83 | return validSides.isEmpty() ? Optional.empty() : Optional.of(validSides.getFirst()); 84 | } 85 | 86 | protected boolean getUseShift(SchematicBlockState state) { 87 | if (getRequiresExplicitShift()) 88 | return true; 89 | 90 | Direction clickSide = getValidSide(state).orElse(null); 91 | if (clickSide == null) 92 | return false; 93 | return isInteractive(state.offset(clickSide).currentState.getBlock()); 94 | } 95 | 96 | private Optional getHitVector(SchematicBlockState state) { 97 | boolean printInAir = Configs.PRINT_IN_AIR.getBooleanValue(); 98 | 99 | if (printInAir && !getRequiresSupport()) { 100 | // For air placement, target the center of the target block position 101 | return Optional.of(Vec3.atCenterOf(state.blockPos)); 102 | } 103 | 104 | return getValidSide(state).map(side -> Vec3.atCenterOf(state.blockPos) 105 | .add(Vec3.atLowerCornerOf(side.getUnitVec3i()).scale(0.5)) 106 | .add(getHitModifier(side))); 107 | } 108 | 109 | @Nullable 110 | public PrinterPlacementContext getPlacementContext(LocalPlayer player) { 111 | try { 112 | Optional validSide = getValidSide(state); 113 | Optional hitVec = getHitVector(state); 114 | Optional requiredItem = getRequiredItem(player); 115 | int requiredSlot = getRequiredItemStackSlot(player); 116 | 117 | if (validSide.isEmpty() || hitVec.isEmpty() || requiredItem.isEmpty() || requiredSlot == -1) 118 | return null; 119 | 120 | Optional lookDirection = getLookDirection(); 121 | boolean requiresShift = getUseShift(state); 122 | 123 | boolean printInAir = Configs.PRINT_IN_AIR.getBooleanValue(); 124 | BlockHitResult blockHitResult; 125 | 126 | if (printInAir && !getRequiresSupport()) { 127 | // For air placement, target the block position directly with a reasonable side 128 | // Using UP direction as default to place block normally 129 | blockHitResult = new BlockHitResult(hitVec.get(), Direction.DOWN, state.blockPos, false); 130 | } else { 131 | blockHitResult = new BlockHitResult(hitVec.get(), validSide.get().getOpposite(), 132 | state.blockPos.relative(validSide.get()), false); 133 | } 134 | 135 | return new PrinterPlacementContext(player, blockHitResult, requiredItem.get(), requiredSlot, 136 | lookDirection.orElse(null), requiresShift); 137 | } catch (Exception e) { 138 | Printer.logger.error("getPlacementContext(): Exception caught: {}", e.getMessage()); 139 | //e.printStackTrace(); 140 | return null; 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/PlacementGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Optional; 7 | import javax.annotation.Nonnull; 8 | import javax.annotation.Nullable; 9 | import me.aleksilassila.litematica.printer.Printer; 10 | import me.aleksilassila.litematica.printer.SchematicBlockState; 11 | import me.aleksilassila.litematica.printer.actions.Action; 12 | import me.aleksilassila.litematica.printer.actions.PrepareAction; 13 | import me.aleksilassila.litematica.printer.actions.ReleaseShiftAction; 14 | import me.aleksilassila.litematica.printer.config.Configs; 15 | import me.aleksilassila.litematica.printer.guides.Guide; 16 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 17 | import me.aleksilassila.litematica.printer.implementation.actions.InteractActionImpl; 18 | 19 | import net.minecraft.client.player.LocalPlayer; 20 | import net.minecraft.core.BlockPos; 21 | import net.minecraft.world.item.BlockItem; 22 | import net.minecraft.world.item.ItemStack; 23 | import net.minecraft.world.item.Items; 24 | import net.minecraft.world.item.context.BlockPlaceContext; 25 | import net.minecraft.world.level.Level; 26 | import net.minecraft.world.level.block.*; 27 | import net.minecraft.world.level.block.state.BlockState; 28 | import net.minecraft.world.phys.shapes.Shapes; 29 | import net.minecraft.world.phys.shapes.VoxelShape; 30 | 31 | import fi.dy.masa.litematica.util.ItemUtils; 32 | 33 | /** 34 | * Guide that clicks its neighbors to create a placement in target position. 35 | */ 36 | abstract public class PlacementGuide extends Guide { 37 | public PlacementGuide(SchematicBlockState state) { 38 | super(state); 39 | } 40 | 41 | protected ItemStack getBlockItem(BlockState state) { 42 | // Let's use the Litematica Pick Block Cache for this. 43 | return ItemUtils.getItemForBlock(this.state.world, this.state.blockPos, state, true); 44 | } 45 | 46 | protected Optional getRequiredItemAsBlock(LocalPlayer player) { 47 | Optional requiredItem = getRequiredItem(player); 48 | 49 | if (requiredItem.isEmpty()) { 50 | return Optional.empty(); 51 | } else { 52 | ItemStack itemStack = requiredItem.get(); 53 | 54 | if (itemStack.getItem() instanceof BlockItem) 55 | return Optional.of(((BlockItem) itemStack.getItem()).getBlock()); 56 | else 57 | return Optional.empty(); 58 | } 59 | } 60 | 61 | @Override 62 | protected @Nonnull List getRequiredItems() { 63 | Printer.printDebug("PlacementGuide#getRequiredItems() - target state [{}]", state.targetState.toString()); 64 | return Collections.singletonList(getBlockItem(state.targetState)); 65 | } 66 | 67 | abstract protected boolean getUseShift(SchematicBlockState state); 68 | 69 | @Nullable 70 | abstract public PrinterPlacementContext getPlacementContext(LocalPlayer player); 71 | 72 | @Override 73 | public boolean canExecute(LocalPlayer player) { 74 | if (!super.canExecute(player)) 75 | return false; 76 | 77 | List requiredItems = getRequiredItems(); 78 | if (requiredItems.isEmpty() || requiredItems.stream().allMatch(i -> i.is(Items.AIR))) 79 | return false; 80 | 81 | BlockPlaceContext ctx = getPlacementContext(player); 82 | if (ctx == null || !ctx.canPlace()) return false; 83 | // if (!state.currentState.getMaterial().isReplaceable()) return false; 84 | if (!Configs.REPLACE_FLUIDS_SOURCE_BLOCKS.getBooleanValue() 85 | && getProperty(state.currentState, LiquidBlock.LEVEL).orElse(1) == 0) 86 | return false; 87 | 88 | BlockState resultState = getRequiredItemAsBlock(player) 89 | .orElse(targetState.getBlock()) 90 | .getStateForPlacement(ctx); 91 | 92 | if (resultState != null) { 93 | if (!resultState.canSurvive(state.world, state.blockPos)) 94 | return false; 95 | return !(currentState.getBlock() instanceof LiquidBlock) || canPlaceInWater(resultState); 96 | } else { 97 | return false; 98 | } 99 | } 100 | 101 | @Override 102 | public @Nonnull List execute(LocalPlayer player) { 103 | List actions = new ArrayList<>(); 104 | PrinterPlacementContext ctx = getPlacementContext(player); 105 | 106 | if (ctx == null) return actions; 107 | actions.add(new PrepareAction(ctx)); 108 | actions.add(new InteractActionImpl(ctx)); 109 | if (ctx.shouldSneak) actions.add(new ReleaseShiftAction()); 110 | 111 | return actions; 112 | } 113 | 114 | protected static boolean canBeClicked(Level world, BlockPos pos) { 115 | return getOutlineShape(world, pos) != Shapes.empty() 116 | && !(world.getBlockState(pos).getBlock() instanceof SignBlock); // FIXME signs 117 | } 118 | 119 | private static VoxelShape getOutlineShape(Level world, BlockPos pos) { 120 | return world.getBlockState(pos).getShape(world, pos); 121 | } 122 | 123 | public boolean isInteractive(Block block) { 124 | for (Class clazz : interactiveBlocks) { 125 | if (clazz.isInstance(block)) { 126 | return true; 127 | } 128 | } 129 | 130 | return false; 131 | } 132 | 133 | @SuppressWarnings("deprecation") 134 | private boolean canPlaceInWater(BlockState blockState) { 135 | Block block = blockState.getBlock(); 136 | if (block instanceof LiquidBlockContainer) { 137 | return true; 138 | } else if (!(block instanceof DoorBlock) && !(blockState.getBlock() instanceof SignBlock) 139 | && !blockState.is(Blocks.LADDER) && !blockState.is(Blocks.SUGAR_CANE) 140 | && !blockState.is(Blocks.BUBBLE_COLUMN)) { 141 | // Material material = blockState.getMaterial(); 142 | // if (material != Material.PORTAL && material != Material.STRUCTURE_VOID && material != Material.UNDERWATER_PLANT && material != Material.REPLACEABLE_UNDERWATER_PLANT) { 143 | // return material.blocksMovement(); 144 | // } else { 145 | // return true; 146 | // } 147 | // TODO --> if this ever gets removed 148 | return blockState.blocksMotion(); 149 | } 150 | 151 | return true; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/me/aleksilassila/litematica/printer/guides/placement/GuesserGuide.java: -------------------------------------------------------------------------------- 1 | package me.aleksilassila.litematica.printer.guides.placement; 2 | 3 | import me.aleksilassila.litematica.printer.SchematicBlockState; 4 | import me.aleksilassila.litematica.printer.config.Configs; 5 | import me.aleksilassila.litematica.printer.implementation.PrinterPlacementContext; 6 | import net.minecraft.client.player.LocalPlayer; 7 | import net.minecraft.core.BlockPos; 8 | import net.minecraft.core.Direction; 9 | import net.minecraft.world.item.ItemStack; 10 | import net.minecraft.world.level.block.ChestBlock; 11 | import net.minecraft.world.level.block.SlabBlock; 12 | import net.minecraft.world.level.block.state.BlockState; 13 | import net.minecraft.world.level.block.state.properties.ChestType; 14 | import net.minecraft.world.phys.BlockHitResult; 15 | import net.minecraft.world.phys.Vec3; 16 | import javax.annotation.Nullable; 17 | 18 | /** 19 | * This is the placement guide that most blocks will use. 20 | * It will try to predict the correct player state for producing the right 21 | * blockState 22 | * by brute forcing the correct hit vector and look a direction. 23 | */ 24 | public class GuesserGuide extends GeneralPlacementGuide { 25 | private PrinterPlacementContext contextCache = null; 26 | 27 | protected static Direction[] directionsToTry = new Direction[]{ 28 | Direction.NORTH, 29 | Direction.SOUTH, 30 | Direction.EAST, 31 | Direction.WEST, 32 | Direction.UP, 33 | Direction.DOWN 34 | }; 35 | protected static Vec3[] hitVecsToTry = new Vec3[]{ 36 | new Vec3(-0.25, -0.25, -0.25), 37 | new Vec3(+0.25, -0.25, -0.25), 38 | new Vec3(-0.25, +0.25, -0.25), 39 | new Vec3(-0.25, -0.25, +0.25), 40 | new Vec3(+0.25, +0.25, -0.25), 41 | new Vec3(-0.25, +0.25, +0.25), 42 | new Vec3(+0.25, -0.25, +0.25), 43 | new Vec3(+0.25, +0.25, +0.25), 44 | }; 45 | 46 | public GuesserGuide(SchematicBlockState state) { 47 | super(state); 48 | } 49 | 50 | @Nullable 51 | @Override 52 | public PrinterPlacementContext getPlacementContext(LocalPlayer player) { 53 | if (contextCache != null && !Configs.PRINT_DEBUG.getBooleanValue()) 54 | return contextCache; 55 | 56 | // First, try air placement if enabled 57 | boolean printInAir = Configs.PRINT_IN_AIR.getBooleanValue(); 58 | if (printInAir && !getRequiresSupport()) { 59 | ItemStack requiredItem = getRequiredItem(player).orElse(ItemStack.EMPTY); 60 | int slot = getRequiredItemStackSlot(player); 61 | 62 | if (slot != -1) { 63 | // Try different directions to find a successful placement 64 | for (Direction side : directionsToTry) { 65 | Vec3 hitVec = Vec3.atCenterOf(state.blockPos); 66 | BlockHitResult hitResult = new BlockHitResult(hitVec, side.getOpposite(), state.blockPos, false); 67 | 68 | boolean requiresShift = getRequiresExplicitShift() || isInteractive(state.world.getBlockState(state.blockPos.relative(side.getOpposite())).getBlock()); 69 | PrinterPlacementContext context = new PrinterPlacementContext(player, hitResult, requiredItem, slot, null, requiresShift); 70 | BlockState result = getRequiredItemAsBlock(player) 71 | .orElse(targetState.getBlock()) 72 | .getStateForPlacement(context); 73 | 74 | if (result != null && (statesEqual(result, targetState) || correctChestPlacement(targetState, result))) { 75 | contextCache = context; 76 | return context; 77 | } 78 | } 79 | } 80 | } 81 | 82 | ItemStack requiredItem = getRequiredItem(player).orElse(ItemStack.EMPTY); 83 | int slot = getRequiredItemStackSlot(player); 84 | 85 | if (slot == -1) 86 | return null; 87 | 88 | for (Direction lookDirection : directionsToTry) { 89 | for (Direction side : directionsToTry) { 90 | BlockPos neighborPos = state.blockPos.relative(side); 91 | BlockState neighborState = state.world.getBlockState(neighborPos); 92 | boolean requiresShift = getRequiresExplicitShift() || isInteractive(neighborState.getBlock()); 93 | 94 | if (!canBeClicked(state.world, neighborPos) || // Handle unclickable grass for example 95 | neighborState.canBeReplaced()) 96 | continue; 97 | 98 | Vec3 hitVec = Vec3.atCenterOf(state.blockPos) 99 | .add(Vec3.atLowerCornerOf(side.getUnitVec3i()).scale(0.5)); 100 | 101 | for (Vec3 hitVecToTry : hitVecsToTry) { 102 | Vec3 multiplier = Vec3.atLowerCornerOf(side.getUnitVec3i()); 103 | multiplier = new Vec3(multiplier.x == 0 ? 1 : 0, multiplier.y == 0 ? 1 : 0, 104 | multiplier.z == 0 ? 1 : 0); 105 | 106 | BlockHitResult hitResult = new BlockHitResult(hitVec.add(hitVecToTry.multiply(multiplier)), 107 | side.getOpposite(), neighborPos, false); 108 | PrinterPlacementContext context = new PrinterPlacementContext(player, hitResult, requiredItem, slot, 109 | lookDirection, requiresShift); 110 | BlockState result = getRequiredItemAsBlock(player) 111 | .orElse(targetState.getBlock()) 112 | .getStateForPlacement(context); // FIXME torch shift clicks another torch and getPlacementState 113 | // is the clicked block, which is true 114 | 115 | if (result != null 116 | && (statesEqual(result, targetState) || correctChestPlacement(targetState, result))) { 117 | contextCache = context; 118 | return context; 119 | } 120 | } 121 | } 122 | } 123 | 124 | return null; 125 | } 126 | 127 | @Override 128 | public boolean canExecute(LocalPlayer player) { 129 | if (targetState.getBlock() instanceof SlabBlock) 130 | return false; // Slabs are a special case 131 | 132 | return super.canExecute(player); 133 | } 134 | 135 | private boolean correctChestPlacement(BlockState targetState, BlockState result) { 136 | if (targetState.hasProperty(ChestBlock.TYPE) && result.hasProperty(ChestBlock.TYPE) 137 | && result.getValue(ChestBlock.FACING) == targetState.getValue(ChestBlock.FACING)) { 138 | ChestType targetChestType = targetState.getValue(ChestBlock.TYPE); 139 | ChestType resultChestType = result.getValue(ChestBlock.TYPE); 140 | 141 | return targetChestType != ChestType.SINGLE && resultChestType == ChestType.SINGLE; 142 | } 143 | 144 | return false; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | 118 | 119 | # Determine the Java command to use to start the JVM. 120 | if [ -n "$JAVA_HOME" ] ; then 121 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 122 | # IBM's JDK on AIX uses strange locations for the executables 123 | JAVACMD=$JAVA_HOME/jre/sh/java 124 | else 125 | JAVACMD=$JAVA_HOME/bin/java 126 | fi 127 | if [ ! -x "$JAVACMD" ] ; then 128 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 129 | 130 | Please set the JAVA_HOME variable in your environment to match the 131 | location of your Java installation." 132 | fi 133 | else 134 | JAVACMD=java 135 | if ! command -v java >/dev/null 2>&1 136 | then 137 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 138 | 139 | Please set the JAVA_HOME variable in your environment to match the 140 | location of your Java installation." 141 | fi 142 | fi 143 | 144 | # Increase the maximum file descriptors if we can. 145 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 146 | case $MAX_FD in #( 147 | max*) 148 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 149 | # shellcheck disable=SC2039,SC3045 150 | MAX_FD=$( ulimit -H -n ) || 151 | warn "Could not query maximum file descriptor limit" 152 | esac 153 | case $MAX_FD in #( 154 | '' | soft) :;; #( 155 | *) 156 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 157 | # shellcheck disable=SC2039,SC3045 158 | ulimit -n "$MAX_FD" || 159 | warn "Could not set maximum file descriptor limit to $MAX_FD" 160 | esac 161 | fi 162 | 163 | # Collect all arguments for the java command, stacking in reverse order: 164 | # * args from the command line 165 | # * the main class name 166 | # * -classpath 167 | # * -D...appname settings 168 | # * --module-path (only if needed) 169 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 170 | 171 | # For Cygwin or MSYS, switch paths to Windows format before running java 172 | if "$cygwin" || "$msys" ; then 173 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ 214 | "$@" 215 | 216 | # Stop when "xargs" is not available. 217 | if ! command -v xargs >/dev/null 2>&1 218 | then 219 | die "xargs is not available" 220 | fi 221 | 222 | # Use "xargs" to parse quoted args. 223 | # 224 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 225 | # 226 | # In Bash we could simply go: 227 | # 228 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 229 | # set -- "${ARGS[@]}" "$@" 230 | # 231 | # but POSIX shell has neither arrays nor command substitution, so instead we 232 | # post-process each arg (as a line of input to sed) to backslash-escape any 233 | # character that might be a shell metacharacter, then use eval to reverse 234 | # that process (while maintaining the separation between arguments), and wrap 235 | # the whole thing up as a single "set" statement. 236 | # 237 | # This will of course break if any of these variables contains a newline or 238 | # an unmatched quote. 239 | # 240 | 241 | eval "set -- $( 242 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 243 | xargs -n1 | 244 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 245 | tr '\n' ' ' 246 | )" '"$@"' 247 | 248 | exec "$JAVACMD" "$@" 249 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------