Skip to content

Commit

Permalink
Fix Easyplace Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
aria1th authored Aug 16, 2021
1 parent 0f3202a commit 351cd11
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import fi.dy.masa.litematica.util.InventoryUtils;
import fi.dy.masa.litematica.util.RayTraceUtils;
import fi.dy.masa.litematica.util.RayTraceUtils.RayTraceWrapper;
import fi.dy.masa.litematica.util.WorldUtils;
import fi.dy.masa.litematica.world.SchematicWorldHandler;
import fi.dy.masa.malilib.util.IntBoundingBox;
import fi.dy.masa.malilib.util.LayerRange;
Expand All @@ -48,6 +47,7 @@
import net.minecraft.block.CarvedPumpkinBlock;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.ComparatorBlock;
import net.minecraft.block.enums.ComparatorMode;
import net.minecraft.block.ComposterBlock;
import net.minecraft.block.DetectorRailBlock;
import net.minecraft.block.DispenserBlock;
Expand Down Expand Up @@ -764,7 +764,7 @@ else if (sBlock instanceof ObserverBlock || sBlock instanceof PistonBlock) {
Vec3d hitPos = new Vec3d(offX, offY, offZ);
// Carpet Accurate Placement protocol support, plus BlockSlab support
hitPos = applyHitVec(npos, stateSchematic, hitPos, side);
if(CanUseProtocol) {hitPos = WorldUtils.applyCarpetProtocolHitVec(npos,stateSchematic,hitPos);} else {hitPos = applyHitVec(npos, stateSchematic, hitPos, side);}
if(CanUseProtocol) {hitPos = applyCarpetProtocolHitVec(npos,stateSchematic,hitPos);} else {hitPos = applyHitVec(npos, stateSchematic, hitPos, side);}

// Mark that this position has been handled (use the non-offset position that is
// checked above)
Expand Down Expand Up @@ -1127,6 +1127,57 @@ private static void cacheEasyPlacePosition(BlockPos pos, boolean useClicked) {
item.hasClicked = true;
positionCache.add(item);
}
public static Vec3d applyCarpetProtocolHitVec(BlockPos pos, BlockState state, Vec3d hitVecIn)
{
double x = hitVecIn.x;
double y = hitVecIn.y;
double z = hitVecIn.z;
Block block = state.getBlock();
Direction facing = fi.dy.masa.malilib.util.BlockUtils.getFirstPropertyFacingValue(state);
final int propertyIncrement = 32;
double relX = hitVecIn.x - pos.getX();

if (facing != null)
{
x = pos.getX() + relX + 2 + (facing.getId() * 2);
}
if (block instanceof RepeaterBlock)
{
x += ((state.get(RepeaterBlock.DELAY))) * propertyIncrement;
}
else if (block instanceof TrapdoorBlock && state.get(TrapdoorBlock.HALF) == BlockHalf.TOP)
{
x += propertyIncrement;
}
else if (block instanceof ComparatorBlock && state.get(ComparatorBlock.MODE) == ComparatorMode.SUBTRACT)
{
x += propertyIncrement;
}
else if (block instanceof TrapdoorBlock && state.get(TrapdoorBlock.HALF) == BlockHalf.TOP)
{
x += propertyIncrement;
}
else if (block instanceof StairsBlock && state.get(StairsBlock.HALF) == BlockHalf.TOP)
{
x += propertyIncrement;
}
else if (block instanceof SlabBlock && state.get(SlabBlock.TYPE) != SlabType.DOUBLE)
{
//x += 10; // Doesn't actually exist (yet?)

// Do it via vanilla
if (state.get(SlabBlock.TYPE) == SlabType.TOP)
{
y = pos.getY() + 0.9;
}
else
{
y = pos.getY();
}
}

return new Vec3d(x, y, z);
}

public static class PositionCache {
private final BlockPos pos;
Expand Down

0 comments on commit 351cd11

Please sign in to comment.