Skip to content

Commit

Permalink
Advanced commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Oct 24, 2023
1 parent 09b9244 commit f494380
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 52 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ dependencies {

//litematica
modImplementation "curse.maven:litematica-${project.litematica_projectid}:${project.litematica_fileid}"
modImplementation "fi.dy.masa.malilib:malilib-fabric-${project.minecraft_version}:${project.malilib_version}"

//modImplementation "fi.dy.masa.malilib:malilib-fabric-${project.minecraft_version}:${project.malilib_version}"
modImplementation "curse.maven:malilib-303119:4780782"
}

processResources {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ yarn_mappings=1.20.1+build.8
loader_version=0.14.21

# Mod Properties
mod_version=1.2
mod_version=1.3
maven_group=com.kkllffaa
archives_base_name=meteor-litematica-printer
archives_base_name=meteor-litematica-printer-advanced

litematica_fileid=3929766
litematica_fileid=4626718
litematica_projectid=308892
malilib_version = 0.16.0
malilib_version = 0.16.3

meteor_version=0.5.4
75 changes: 37 additions & 38 deletions src/main/java/com/kkllffaa/meteor_litematica_printer/MyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import baritone.api.utils.RayTraceUtils;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import fi.dy.masa.litematica.world.WorldSchematic;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
Expand Down Expand Up @@ -39,7 +40,7 @@
import net.minecraft.world.RaycastContext.ShapeType;

public class MyUtils {

public static boolean place(BlockPos blockPos, Direction direction, boolean airPlace, boolean swingHand, boolean rotate, boolean clientSide, int range) {
if (mc.player == null) return false;
if (!canPlace(blockPos)) return false;
Expand All @@ -56,18 +57,18 @@ public static boolean place(BlockPos blockPos, Direction direction, boolean airP
}else {
neighbour = blockPos.offset(direction.getOpposite());
hitPos.add(direction.getOffsetX() * 0.5, direction.getOffsetY() * 0.5, direction.getOffsetZ() * 0.5);
}
}


Direction s = direction;

if (rotate) {
BetterBlockPos placeAgainstPos = new BetterBlockPos(neighbour.getX(), neighbour.getY(), neighbour.getZ());
VoxelShape collisionShape = mc.world.getBlockState(placeAgainstPos).getCollisionShape(mc.world, placeAgainstPos);

if(collisionShape.isEmpty()) {
Rotations.rotate(Rotations.getYaw(hitPos), Rotations.getPitch(hitPos), 50, clientSide,
() ->
() ->
place(new BlockHitResult(hitPos, s, neighbour, false), swingHand)
);
return true;
Expand All @@ -78,22 +79,22 @@ public static boolean place(BlockPos blockPos, Direction direction, boolean airP
double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x);
double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);

Vec3d testHitPos = new Vec3d(placeX, placeY, placeZ);
Vec3d playerHead = new Vec3d(mc.player.getX(), mc.player.getEyeY(), mc.player.getZ());

Rotation rot = RotationUtils.calcRotationFromVec3d(playerHead, testHitPos, new Rotation(mc.player.getYaw(), mc.player.getPitch()));
HitResult res = RayTraceUtils.rayTraceTowards(mc.player, rot, range, false);
BlockHitResult blockHitRes = ((BlockHitResult) res);
if(
res == null ||
res.getType() != HitResult.Type.BLOCK ||
res.getType() != HitResult.Type.BLOCK ||
!blockHitRes.getBlockPos().equals(placeAgainstPos) ||
blockHitRes.getSide() != direction
) continue;

Rotations.rotate(Rotations.getYaw(testHitPos), Rotations.getPitch(testHitPos), 50, clientSide,
() ->
() ->
place(new BlockHitResult(testHitPos, s, neighbour, false), swingHand)
);

Expand All @@ -120,10 +121,10 @@ private static void place(BlockHitResult blockHitResult, boolean swing) {

mc.player.input.sneaking = wasSneaking;
}

public static boolean isBlockNormalCube(BlockState state) {
Block block = state.getBlock();
if (block instanceof ScaffoldingBlock
if (block instanceof ScaffoldingBlock
|| block instanceof ShulkerBoxBlock
|| block instanceof PointedDripstoneBlock
|| block instanceof AmethystClusterBlock) {
Expand All @@ -136,40 +137,40 @@ public static boolean isBlockNormalCube(BlockState state) {
}
return false;
}

public static boolean canPlaceAgainst(BlockState placeAtState, BlockState placeAgainstState, Direction against) {
// can we look at the center of a side face of this block and likely be able to place?
// therefore dont include weird things that we technically could place against (like carpet) but practically can't

return isBlockNormalCube(placeAgainstState) ||
placeAgainstState.getBlock() == Blocks.GLASS ||

return isBlockNormalCube(placeAgainstState) ||
placeAgainstState.getBlock() == Blocks.GLASS ||
placeAgainstState.getBlock() instanceof StainedGlassBlock ||
placeAgainstState.getBlock() instanceof SlabBlock &&
placeAgainstState.getBlock() instanceof SlabBlock &&
(
placeAgainstState.get(SlabBlock.TYPE) != SlabType.BOTTOM &&
placeAgainstState.get(SlabBlock.TYPE) != SlabType.BOTTOM &&
placeAtState.getBlock() == placeAgainstState.getBlock() &&
against != Direction.DOWN ||
placeAtState.getBlock() != placeAgainstState.getBlock()
);
}

public static boolean isBlockInLineOfSight(BlockPos placeAt, BlockState placeAtState) {
Vec3d playerHead = new Vec3d(mc.player.getX(), mc.player.getEyeY(), mc.player.getZ());
Vec3d placeAtVec = new Vec3d(placeAt.getX(), placeAt.getY(), placeAt.getZ());

ShapeType type = RaycastContext.ShapeType.COLLIDER;
FluidHandling fluid = RaycastContext.FluidHandling.NONE;

RaycastContext context =
new RaycastContext(playerHead, placeAtVec, type, fluid, mc.player);
BlockHitResult bhr = mc.world.raycast(context);

// check line of sight
// check line of sight
return (bhr.getType() == HitResult.Type.MISS);

}

public static Direction getVisiblePlaceSide(BlockPos placeAt, BlockState placeAtState, int range, Direction requiredDir) {
if (mc.world == null) return null;
for (Direction against : Direction.values()) {
Expand All @@ -178,37 +179,37 @@ public static Direction getVisiblePlaceSide(BlockPos placeAt, BlockState placeAt

if(requiredDir != null && requiredDir != against && requiredDir != Direction.UP)
continue;

if(!canPlaceAgainst(
placeAtState,
mc.world.getBlockState(placeAgainstPos),
against
))
continue;
Box aabb = mc.world.getBlockState(placeAgainstPos).getCollisionShape(mc.world, placeAgainstPos).getBoundingBox();

for (Vec3d placementMultiplier : aabbSideMultipliers(against)) {
double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x);
double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);

Vec3d hitPos = new Vec3d(placeX, placeY, placeZ);
Vec3d playerHead = new Vec3d(mc.player.getX(), mc.player.getEyeY(), mc.player.getZ());

Rotation rot = RotationUtils.calcRotationFromVec3d(playerHead, hitPos, new Rotation(mc.player.getYaw(), mc.player.getPitch()));
HitResult res = RayTraceUtils.rayTraceTowards(mc.player, rot, range, false);
BlockHitResult blockHitRes = ((BlockHitResult) res);

if(
res == null
|| res.getType() != HitResult.Type.BLOCK
|| !blockHitRes.getBlockPos().equals(placeAgainstPos)
res == null
|| res.getType() != HitResult.Type.BLOCK
|| !blockHitRes.getBlockPos().equals(placeAgainstPos)
|| blockHitRes.getSide() != against.getOpposite()
) continue;


return against.getOpposite();

}
}

Expand All @@ -217,10 +218,10 @@ public static Direction getVisiblePlaceSide(BlockPos placeAt, BlockState placeAt

public static Direction getPlaceSide(BlockPos blockPos, Direction requiredDir) {
for (Direction side : Direction.values()) {

BlockPos neighbor = blockPos.offset(side);
Direction side2 = side.getOpposite();

if(requiredDir != null && requiredDir != side2 && requiredDir != Direction.UP)
continue;

Expand All @@ -245,10 +246,10 @@ public static NbtCompound getNbtFromBlockState (ItemStack itemStack, BlockState
subNbt.putString(property.getName(), state.get(property).toString());
}
nbt.put("BlockStateTag", subNbt);

return nbt;
}

private static Vec3d[] aabbSideMultipliers(Direction side) {
switch (side) {
case UP:
Expand All @@ -266,6 +267,4 @@ private static Vec3d[] aabbSideMultipliers(Direction side) {
throw new IllegalStateException();
}
}


}
59 changes: 56 additions & 3 deletions src/main/java/com/kkllffaa/meteor_litematica_printer/Printer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.BaritoneUtils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.render.color.Color;
Expand All @@ -36,6 +38,7 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.Pair;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down Expand Up @@ -64,6 +67,26 @@ public class Printer extends Module {
.max(100).sliderMax(40)
.build()
);
private final Setting<Integer> travel_range = sgGeneral.add(new IntSetting.Builder()
.name("Travelling range")
.description("The range for travelling to a unplaced schematic block using baritone. (Max = 10k) (More == laggy and slower but useful sometimes) ")
.defaultValue(2)
.min(1)
.sliderMin(25)
.max(10000)
.sliderMax(100)
.build()
);
private final Setting<Integer> travel_delay = sgGeneral.add(new IntSetting.Builder()
.name("Travelling delay")
.description("Delay between travelling to a unplaced schematic block using baritone (in ticks)")
.defaultValue(2)
.min(0)
.sliderMin(3)
.max(500)
.sliderMax(200)
.build()
);

private final Setting<Integer> bpt = sgGeneral.add(new IntSetting.Builder()
.name("blocks/tick")
Expand Down Expand Up @@ -185,9 +208,10 @@ public class Printer extends Module {
.build()
);

private int timer;
private int timer, goTimer = 0;
private int usedSlot = -1;
private final List<BlockPos> toSort = new ArrayList<>();
private final List<BlockPos> gotoSort = new ArrayList<>();
private final List<Pair<Integer, BlockPos>> placed_fade = new ArrayList<>();


Expand All @@ -207,6 +231,7 @@ public void onActivate() {
@Override
public void onDeactivate() {
placed_fade.clear();
ChatUtils.sendPlayerMsg("#stop");
}

@EventHandler
Expand All @@ -227,7 +252,7 @@ private void onTick(TickEvent.Post event) {
}

toSort.clear();

gotoSort.clear();

if (timer >= printing_delay.get()) {
BlockIterator.register(printing_range.get() + 1, printing_range.get() + 1, (pos, blockState) -> {
Expand Down Expand Up @@ -307,7 +332,35 @@ private void onTick(TickEvent.Post event) {


} else timer++;
}

BlockIterator.register(travel_range.get() + 1, travel_range.get() + 1, (pos, blockState) -> {
BlockState required = worldSchematic.getBlockState(pos);

if ( blockState.isReplaceable()
&& !required.isAir()
&& blockState.getBlock() != required.getBlock()
&& required.canPlaceAt(mc.world, pos)
) {
gotoSort.add(new BlockPos(pos));
}
});
// Sort blocks by distance to player
BlockIterator.after(()->{
Comparator<BlockPos> comparator = Comparator.comparingDouble((BlockPos pos) -> mc.player.getBlockPos().getSquaredDistance(pos.getX(), pos.getY(), pos.getZ()));
gotoSort.sort(comparator);
for(BlockPos blockPos: gotoSort){
if(mc.player.getBlockPos() != blockPos && mc.player.getBlockPos().toCenterPos().distanceTo(blockPos.toCenterPos())> 5 + 1) {
if(goTimer>travel_delay.get()) {
goTimer = 0;
ChatUtils.sendPlayerMsg("#goto " + (int) blockPos.getX() + " " + (int) blockPos.getY() + " " + (int) blockPos.getZ());
}else goTimer++;
break;
}
}
});


}

public boolean place(BlockState required, BlockPos pos) {

Expand Down
11 changes: 6 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"schemaVersion": 1,
"name": "Meteor Litematica Printer",
"id": "meteor-litematica-printer",
"name": "Meteor Litematica Printer Advanced",
"id": "meteor-litematica-printer-advanced",
"version": "${version}",
"description": "Fast printer for litematica made with meteor.",
"description": "Fast printer for litematica made with meteor. Automatically uses baritone to travel to unplaced regions",
"authors": [
"kkllffaa"
"kkllffaa",
"tanishisherewith"
],
"contact": {
"repo": "https://github.com/kkllffaa/meteor-litematica-printer"
"repo": "https://github.com/tanishisherewithhh/meteor-litematica-printer"
},
"icon": "assets/meteor_litematica_printer/icon.png",
"environment": "client",
Expand Down

0 comments on commit f494380

Please sign in to comment.