-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98009a1
commit 36c98ba
Showing
53 changed files
with
2,661 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
plugins { | ||
id("fabric-loom").version("1.0-SNAPSHOT") | ||
id("maven-publish") | ||
} | ||
|
||
java.sourceCompatibility = JavaVersion.VERSION_17 | ||
java.targetCompatibility = JavaVersion.VERSION_17 | ||
|
||
val archives_base_name: String by project | ||
val minecraft_version: String by project | ||
val yarn_mappings: String by project | ||
val loader_version: String by project | ||
val fabric_version: String by project | ||
val malilib_version: String by project | ||
val litematica_projectid: String by project | ||
val litematica_fileid: String by project | ||
|
||
val mod_version: String by project | ||
|
||
dependencies { | ||
// implementation(project(":common")) | ||
minecraft("com.mojang:minecraft:${minecraft_version}") | ||
mappings("net.fabricmc:yarn:${yarn_mappings}:v2") | ||
|
||
modImplementation("net.fabricmc:fabric-loader:${loader_version}") | ||
modImplementation("net.fabricmc.fabric-api:fabric-api:${fabric_version}") | ||
modImplementation("fi.dy.masa.malilib:malilib-fabric-${malilib_version}") | ||
modImplementation("curse.maven:litematica-${litematica_projectid}:${litematica_fileid}") | ||
} | ||
|
||
repositories { | ||
maven("https://masa.dy.fi/maven") | ||
maven("https://www.cursemaven.com") | ||
} | ||
|
||
// Process resources | ||
tasks.withType<ProcessResources> { | ||
inputs.property("version", mod_version) | ||
|
||
filesMatching("fabric.mod.json") { | ||
expand(mapOf("version" to mod_version)) | ||
} | ||
} | ||
|
||
val sourceModule = "v1_19_4" | ||
val targetModules = arrayOf("v1_19", "v1_18", "v1_17") | ||
|
||
fun copyFile(source: File) { | ||
for (targetModule in targetModules) { | ||
val destination = file(source.absolutePath.replace(sourceModule, targetModule)) | ||
println("Copying ${source.absolutePath} to ${destination.absolutePath}") | ||
destination.parentFile.mkdirs() | ||
source.copyTo(destination, true) | ||
destination.writeText(destination.readText().replace(sourceModule, targetModule)) | ||
} | ||
} | ||
|
||
fun deleteOldFiles(sourceBase: File) { | ||
for (targetModule in targetModules) { | ||
val targetBase = file(sourceBase.absolutePath.replace(sourceModule, targetModule)) | ||
|
||
for (file in targetBase.listFiles()) { | ||
if (file.name.equals("implementation")) continue | ||
println("Deleting recursively ${file.absolutePath}") | ||
file.deleteRecursively() | ||
} | ||
} | ||
} | ||
|
||
val syncImplementations = tasks.create("syncImplementations") { | ||
doFirst { | ||
val sourceStart = | ||
this.project.projectDir.absolutePath + "/src/main/java/me/aleksilassila/litematica/printer/" + sourceModule | ||
val sourceDir = file(sourceStart) | ||
|
||
deleteOldFiles(sourceDir) | ||
|
||
for (sourceFile in sourceDir.listFiles()) { | ||
if (sourceFile.name.equals("implementation")) continue | ||
|
||
sourceFile.walk() | ||
.filter { it.isFile } | ||
.forEach { | ||
copyFile(it) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Done to increase the memory available to gradle. | ||
org.gradle.jvmargs=-Xmx1G | ||
# https://masa.dy.fi/maven/fi/dy/masa/malilib/ | ||
malilib_version=1.20.2:0.17.0 | ||
# https://www.curseforge.com/minecraft/mc-mods/litematica/files | ||
litematica_fileid=4789765 | ||
litematica_projectid=308892 | ||
# Fabric Properties: https://fabricmc.net/develop/ | ||
minecraft_version=1.20.2 | ||
yarn_mappings=1.20.2+build.4 | ||
loader_version=0.14.22 | ||
#Fabric api | ||
fabric_version=0.89.3+1.20.2 |
57 changes: 57 additions & 0 deletions
57
v1_20_2/src/main/java/me/aleksilassila/litematica/printer/v1_20_2/ActionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.aleksilassila.litematica.printer.v1_20_2; | ||
|
||
import me.aleksilassila.litematica.printer.v1_20_2.actions.Action; | ||
import me.aleksilassila.litematica.printer.v1_20_2.actions.PrepareAction; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Queue; | ||
|
||
public class ActionHandler { | ||
private final MinecraftClient client; | ||
private final ClientPlayerEntity player; | ||
|
||
private final Queue<Action> actionQueue = new LinkedList<>(); | ||
public PrepareAction lookAction = null; | ||
|
||
public ActionHandler(MinecraftClient client, ClientPlayerEntity player) { | ||
this.client = client; | ||
this.player = player; | ||
} | ||
|
||
private int tick = 0; | ||
|
||
public void onGameTick() { | ||
int tickRate = LitematicaMixinMod.PRINTING_INTERVAL.getIntegerValue(); | ||
|
||
tick = tick % tickRate == tickRate - 1 ? 0 : tick + 1; | ||
if (tick % tickRate != 0) { | ||
return; | ||
} | ||
|
||
Action nextAction = actionQueue.poll(); | ||
if (nextAction != null) { | ||
if (LitematicaMixinMod.DEBUG) System.out.println("Sending action " + nextAction); | ||
nextAction.send(client, player); | ||
} else { | ||
lookAction = null; | ||
} | ||
} | ||
|
||
public boolean acceptsActions() { | ||
return actionQueue.isEmpty(); | ||
} | ||
|
||
public void addActions(Action... actions) { | ||
if (!acceptsActions()) return; | ||
|
||
for (Action action : actions) { | ||
if (action instanceof PrepareAction) | ||
lookAction = (PrepareAction) action; | ||
} | ||
|
||
actionQueue.addAll(List.of(actions)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
v1_20_2/src/main/java/me/aleksilassila/litematica/printer/v1_20_2/BlockHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.aleksilassila.litematica.printer.v1_20_2; | ||
|
||
import net.minecraft.block.*; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.Items; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
abstract public class BlockHelper { | ||
public static List<Class<?>> interactiveBlocks = new ArrayList<>(Arrays.asList( | ||
AbstractChestBlock.class, AbstractFurnaceBlock.class, CraftingTableBlock.class, LeverBlock.class, | ||
DoorBlock.class, TrapdoorBlock.class, BedBlock.class, RedstoneWireBlock.class, ScaffoldingBlock.class, | ||
HopperBlock.class, EnchantingTableBlock.class, NoteBlock.class, JukeboxBlock.class, CakeBlock.class, | ||
FenceGateBlock.class, BrewingStandBlock.class, DragonEggBlock.class, CommandBlock.class, | ||
BeaconBlock.class, AnvilBlock.class, ComparatorBlock.class, RepeaterBlock.class, | ||
DropperBlock.class, DispenserBlock.class, ShulkerBoxBlock.class, LecternBlock.class, | ||
FlowerPotBlock.class, BarrelBlock.class, BellBlock.class, SmithingTableBlock.class, | ||
LoomBlock.class, CartographyTableBlock.class, GrindstoneBlock.class, | ||
StonecutterBlock.class, AbstractSignBlock.class, AbstractCandleBlock.class)); | ||
|
||
public static final Item[] SHOVEL_ITEMS = new Item[]{ | ||
Items.NETHERITE_SHOVEL, | ||
Items.DIAMOND_SHOVEL, | ||
Items.GOLDEN_SHOVEL, | ||
Items.IRON_SHOVEL, | ||
Items.STONE_SHOVEL, | ||
Items.WOODEN_SHOVEL | ||
}; | ||
} |
58 changes: 58 additions & 0 deletions
58
v1_20_2/src/main/java/me/aleksilassila/litematica/printer/v1_20_2/LitematicaMixinMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package me.aleksilassila.litematica.printer.v1_20_2; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import fi.dy.masa.litematica.config.Configs; | ||
import fi.dy.masa.litematica.config.Hotkeys; | ||
import fi.dy.masa.malilib.config.IConfigBase; | ||
import fi.dy.masa.malilib.config.options.ConfigBoolean; | ||
import fi.dy.masa.malilib.config.options.ConfigDouble; | ||
import fi.dy.masa.malilib.config.options.ConfigHotkey; | ||
import fi.dy.masa.malilib.config.options.ConfigInteger; | ||
import fi.dy.masa.malilib.hotkeys.KeyCallbackToggleBooleanConfigWithMessage; | ||
import fi.dy.masa.malilib.hotkeys.KeybindSettings; | ||
import net.fabricmc.api.ModInitializer; | ||
|
||
import java.util.List; | ||
|
||
public class LitematicaMixinMod implements ModInitializer { | ||
|
||
public static Printer printer; | ||
public static boolean DEBUG = false; | ||
// Config settings | ||
public static final ConfigInteger PRINTING_INTERVAL = new ConfigInteger("printingInterval", 12, 1, 40, "Printing interval. Lower values mean faster printing speed.\nIf the printer creates \"ghost blocks\" or blocks are facing the wrong way, raise this value."); | ||
public static final ConfigDouble PRINTING_RANGE = new ConfigDouble("printingRange", 5, 2.5, 5, "Printing block place range\nLower values are recommended for servers."); | ||
// public static final ConfigBoolean PRINT_WATER = new ConfigBoolean("printWater", false, "Whether the printer should place water\n source blocks or make blocks waterlogged."); | ||
// public static final ConfigBoolean PRINT_IN_AIR = new ConfigBoolean("printInAir", true, "Whether or not the printer should place blocks without anything to build on.\nBe aware that some anti-cheat plugins might notice this."); | ||
public static final ConfigBoolean PRINT_MODE = new ConfigBoolean("printingMode", false, "Autobuild / print loaded selection.\nBe aware that some servers and anticheat plugins do not allow printing."); | ||
public static final ConfigBoolean REPLACE_FLUIDS_SOURCE_BLOCKS = new ConfigBoolean("replaceFluidSourceBlocks", true, "Whether or not fluid source blocks should be replaced by the printer."); | ||
public static final ConfigBoolean STRIP_LOGS = new ConfigBoolean("stripLogs", true, "Whether or not the printer should use normal logs if stripped\nversions are not available and then strip them with an axe."); | ||
|
||
public static ImmutableList<IConfigBase> getConfigList() { | ||
List<IConfigBase> list = new java.util.ArrayList<>(Configs.Generic.OPTIONS); | ||
list.add(PRINT_MODE); | ||
list.add(PRINTING_INTERVAL); | ||
list.add(PRINTING_RANGE); | ||
// list.add(PRINT_IN_AIR); | ||
list.add(REPLACE_FLUIDS_SOURCE_BLOCKS); | ||
list.add(STRIP_LOGS); | ||
|
||
return ImmutableList.copyOf(list); | ||
} | ||
|
||
// Hotkeys | ||
public static final ConfigHotkey PRINT = new ConfigHotkey("print", "V", KeybindSettings.PRESS_ALLOWEXTRA_EMPTY, "Prints while pressed"); | ||
public static final ConfigHotkey TOGGLE_PRINTING_MODE = new ConfigHotkey("togglePrintingMode", "CAPS_LOCK", KeybindSettings.PRESS_ALLOWEXTRA_EMPTY, "Allows quickly toggling on/off Printing mode"); | ||
|
||
public static List<ConfigHotkey> getHotkeyList() { | ||
List<ConfigHotkey> list = new java.util.ArrayList<>(Hotkeys.HOTKEY_LIST); | ||
list.add(PRINT); | ||
list.add(TOGGLE_PRINTING_MODE); | ||
|
||
return ImmutableList.copyOf(list); | ||
} | ||
|
||
@Override | ||
public void onInitialize() { | ||
TOGGLE_PRINTING_MODE.getKeybind().setCallback(new KeyCallbackToggleBooleanConfigWithMessage(PRINT_MODE)); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
v1_20_2/src/main/java/me/aleksilassila/litematica/printer/v1_20_2/Printer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package me.aleksilassila.litematica.printer.v1_20_2; | ||
|
||
import fi.dy.masa.litematica.data.DataManager; | ||
import fi.dy.masa.litematica.util.RayTraceUtils; | ||
import fi.dy.masa.litematica.world.SchematicWorldHandler; | ||
import fi.dy.masa.litematica.world.WorldSchematic; | ||
import me.aleksilassila.litematica.printer.v1_20_2.actions.Action; | ||
import me.aleksilassila.litematica.printer.v1_20_2.guides.Guide; | ||
import me.aleksilassila.litematica.printer.v1_20_2.guides.Guides; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.entity.player.PlayerAbilities; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.Vec3d; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Printer { | ||
@NotNull | ||
public final ClientPlayerEntity player; | ||
|
||
public final ActionHandler actionHandler; | ||
|
||
private final Guides interactionGuides = new Guides(); | ||
|
||
public Printer(@NotNull MinecraftClient client, @NotNull ClientPlayerEntity player) { | ||
this.player = player; | ||
|
||
this.actionHandler = new ActionHandler(client, player); | ||
} | ||
|
||
public boolean onGameTick() { | ||
WorldSchematic worldSchematic = SchematicWorldHandler.getSchematicWorld(); | ||
|
||
if (!actionHandler.acceptsActions()) return false; | ||
|
||
if (worldSchematic == null) return false; | ||
|
||
if (!LitematicaMixinMod.PRINT_MODE.getBooleanValue() && !LitematicaMixinMod.PRINT.getKeybind().isPressed()) | ||
return false; | ||
|
||
PlayerAbilities abilities = player.getAbilities(); | ||
if (!abilities.allowModifyWorld) | ||
return false; | ||
|
||
List<BlockPos> positions = getReachablePositions(); | ||
findBlock: | ||
for (BlockPos position : positions) { | ||
SchematicBlockState state = new SchematicBlockState(player.getWorld(), worldSchematic, position); | ||
if (state.targetState.equals(state.currentState) || state.targetState.isAir()) continue; | ||
|
||
Guide[] guides = interactionGuides.getInteractionGuides(state); | ||
|
||
BlockHitResult result = RayTraceUtils.traceToSchematicWorld(player, 10, true, true); | ||
boolean isCurrentlyLookingSchematic = result != null && result.getBlockPos().equals(position); | ||
|
||
for (Guide guide : guides) { | ||
if (guide.canExecute(player)) { | ||
System.out.println("Executing " + guide + " for " + state); | ||
List<Action> actions = guide.execute(player); | ||
actionHandler.addActions(actions.toArray(Action[]::new)); | ||
return true; | ||
} | ||
if (guide.skipOtherGuides()) continue findBlock; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private List<BlockPos> getReachablePositions() { | ||
int maxReach = (int) Math.ceil(LitematicaMixinMod.PRINTING_RANGE.getDoubleValue()); | ||
double maxReachSquared = MathHelper.square(LitematicaMixinMod.PRINTING_RANGE.getDoubleValue()); | ||
|
||
ArrayList<BlockPos> positions = new ArrayList<>(); | ||
|
||
for (int y = -maxReach; y < maxReach + 1; y++) { | ||
for (int x = -maxReach; x < maxReach + 1; x++) { | ||
for (int z = -maxReach; z < maxReach + 1; z++) { | ||
BlockPos blockPos = player.getBlockPos().north(x).west(z).up(y); | ||
|
||
if (!DataManager.getRenderLayerRange().isPositionWithinRange(blockPos)) continue; | ||
if (this.player.getEyePos().squaredDistanceTo(Vec3d.ofCenter(blockPos)) > maxReachSquared) { | ||
continue; | ||
} | ||
|
||
positions.add(blockPos); | ||
} | ||
} | ||
} | ||
|
||
return positions.stream() | ||
.filter(p -> { | ||
Vec3d vec = Vec3d.ofCenter(p); | ||
return this.player.getPos().squaredDistanceTo(vec) > 1 && this.player.getEyePos().squaredDistanceTo(vec) > 1; | ||
}) | ||
.sorted((a, b) -> { | ||
double aDistance = this.player.getPos().squaredDistanceTo(Vec3d.ofCenter(a)); | ||
double bDistance = this.player.getPos().squaredDistanceTo(Vec3d.ofCenter(b)); | ||
return Double.compare(aDistance, bDistance); | ||
}).toList(); | ||
} | ||
} |
Oops, something went wrong.