Skip to content

Commit

Permalink
Smarter than smart
Browse files Browse the repository at this point in the history
  • Loading branch information
aria1th authored Jul 26, 2022
1 parent 9224f2d commit ed4de60
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.eatmyvenom.litematicin.mixin.quasiEssentialClient;

import io.github.eatmyvenom.litematicin.utils.FakeAccurateBlockPlacement;
import net.minecraft.block.LeverBlock;
import net.minecraft.block.PistonBlock;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -13,9 +15,7 @@ public class ItemPlacementContextMixin {
@Inject(method = "getPlayerLookDirection", at = @At("HEAD"), cancellable = true, require = 0)
private void onGetDirection(CallbackInfoReturnable<Direction> cir) {
if (FakeAccurateBlockPlacement.fakeDirection != null && FakeAccurateBlockPlacement.requestedTicks > -3) {
if (FakeAccurateBlockPlacement.fakeDirection.getAxis() != Direction.Axis.Y){
cir.setReturnValue(FakeAccurateBlockPlacement.fakeDirection);
}
cir.setReturnValue(FakeAccurateBlockPlacement.fakeDirection);
}
}
@Inject(method = "getVerticalPlayerLookDirection", at = @At("HEAD"), cancellable = true, require = 0)
Expand All @@ -24,4 +24,10 @@ private void onGetVerticalDirection(CallbackInfoReturnable<Direction> cir) {
cir.setReturnValue(FakeAccurateBlockPlacement.fakeDirection);
}
}
@Inject(method = "getPlacementDirections", at = @At("HEAD"), cancellable = true, require = 0)
private void onGetArrayDirections(CallbackInfoReturnable<Direction[]> cir) {
if (FakeAccurateBlockPlacement.fakeDirection != null && FakeAccurateBlockPlacement.requestedTicks > -3) {
cir.setReturnValue(FakeAccurateBlockPlacement.getEntityFacingOrder());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static io.github.eatmyvenom.litematicin.utils.FakeAccurateBlockPlacement.getPlayerFacing;

@Mixin(value = ItemUsageContext.class, priority = 1010)
public class ItemUsageContextMixin {
@Inject(method = "getPlayerFacing", at = @At("HEAD"), cancellable = true, require = 0)
private void onGetFacing(CallbackInfoReturnable<Direction> cir) {
Direction direction = FakeAccurateBlockPlacement.fakeDirection;
Direction direction = getPlayerFacing();
if (direction != null && FakeAccurateBlockPlacement.requestedTicks > -3 && FakeAccurateBlockPlacement.fakeDirection.getAxis() != Direction.Axis.Y) {
cir.setReturnValue(direction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
Expand All @@ -27,6 +29,8 @@
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.EASY_PLACE_MODE_MAX_BLOCKS;

public class FakeAccurateBlockPlacement{

// We implement FIFO Queue structure with responsible ticks.
Expand All @@ -40,6 +44,7 @@ public class FakeAccurateBlockPlacement{
private static float previousFakeYaw = 0;
private static float previousFakePitch = 0;
private static int tickElapsed = 0;
private static int blockPlacedInTick = 0;
public static Item currentHandling = Items.AIR;
private static boolean betweenStartAndEnd = false;
private static final Queue<PosWithBlock> waitingQueue = new ArrayBlockingQueue<>(1) {
Expand All @@ -65,6 +70,7 @@ public static boolean canHandleOther(Item item){
}
public static void starttick(MinecraftClient minecraftClient){
betweenStartAndEnd = false;
blockPlacedInTick = 0;
}
public static void endtick(MinecraftClient minecraftClient){
betweenStartAndEnd = true;
Expand Down Expand Up @@ -215,6 +221,28 @@ else if (lookRefdir == Direction.SOUTH) {
}
return false;
}
public static Direction getPlayerFacing(){
if (fakeYaw == -87){
return Direction.EAST;
}
else if (fakeYaw == 87){
return Direction.WEST;
}
else if (fakeYaw == 177){
return Direction.NORTH;
}
else if (fakeYaw == 3){
return Direction.SOUTH;
}
return null;
}
public static Direction[] getEntityFacingOrder(){
Entity entity = new ZombieEntity(MinecraftClient.getInstance().world);
entity.setYaw(fakeYaw);
entity.setPitch(fakePitch);
entity.remove(Entity.RemovalReason.DISCARDED);
return Direction.getEntityFacingOrder(entity);
}
/***
*
* @param blockState : Block object(terracotta, etc...)
Expand Down Expand Up @@ -363,9 +391,12 @@ public static boolean canPlace(BlockState state){
if (stateGrindStone != null)
return stateGrindStone.get(GrindstoneBlock.FACE) == state.get(GrindstoneBlock.FACE) && stateGrindStone.get(GrindstoneBlock.FACING) == state.get(GrindstoneBlock.FACING);
}
return betweenStartAndEnd && state.getBlock().asItem() == currentHandling || currentHandling == Items.AIR;
return betweenStartAndEnd && canHandleOther(state.getBlock().asItem());
}
private static boolean placeBlock(BlockPos pos, BlockState blockState){
if(blockPlacedInTick > EASY_PLACE_MODE_MAX_BLOCKS.getIntegerValue()){
return false;
}
final MinecraftClient minecraftClient = MinecraftClient.getInstance();
final ClientPlayerEntity player = minecraftClient.player;
final ClientPlayerInteractionManager interactionManager = minecraftClient.interactionManager;
Expand Down Expand Up @@ -400,6 +431,7 @@ else if (blockState.getBlock() instanceof TorchBlock){
MessageHolder.sendDebugMessage(player, "Placing "+blockState.getBlock().getName()+" at "+ pos.toShortString() + " facing : " + fi.dy.masa.malilib.util.BlockUtils.getFirstPropertyFacingValue(blockState));
MessageHolder.sendDebugMessage(player, "Player facing is set to : " + fakeDirection + " Yaw : " + fakeYaw + " Pitch : "+ fakePitch + " ticks : "+ requestedTicks + " for pos "+ pos.toShortString());
interactionManager.interactBlock(player, Hand.MAIN_HAND, blockHitResult);
blockPlacedInTick++;
Printer.cacheEasyPlacePosition(pos, false);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public static void sendDebugMessage(ClientPlayerEntity player, String string){
player.sendMessage(Text.of(string));
}
}
public static void sendMessageUncheckedUnique(ClientPlayerEntity player, String string){
if (!uniqueStrings.contains(string)) {
player.sendMessage(Text.of(string));
uniqueStrings.add(string);
}
}
public static void sendUniqueMessage(ClientPlayerEntity player, String string){
if (!DEBUG_MESSAGE.getBooleanValue()){
uniqueStrings.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ public static ActionResult doPrinterAction(MinecraftClient mc) {
}
}
}
if (BEDROCK_BREAKING.getBooleanValue()) {continue;} // don't process other actions
if (BEDROCK_BREAKING.getBooleanValue()) {
continue;
} // don't process other actions
if (!(stateSchematic.getBlock() instanceof NetherPortalBlock) && stateSchematic.isAir() && !ClearArea)
continue;

Expand Down Expand Up @@ -796,8 +798,7 @@ else if (sBlock instanceof SandBlock || sBlock instanceof DragonEggBlock || sBlo
lastPlaced = new Date().getTime();
interact++;
}
Direction facing = fi.dy.masa.malilib.util.BlockUtils
.getFirstPropertyFacingValue(stateSchematic);
Direction facing = fi.dy.masa.malilib.util.BlockUtils.getFirstPropertyFacingValue(stateSchematic);
if (facing != null) {
facing = facing.getOpposite();
}
Expand All @@ -807,6 +808,7 @@ else if (sBlock instanceof SandBlock || sBlock instanceof DragonEggBlock || sBlo
if (facing != null) {
FacingData facedata = FacingData.getFacingData(stateSchematic);
if(facedata == null && !simulateFacingData(stateSchematic, pos, new Vec3d(0.5, 0.5, 0.5)) && !(stateSchematic.getBlock() instanceof AbstractRailBlock)){
MessageHolder.sendMessageUncheckedUnique(mc.player, stateSchematic.getBlock() + " does not have facing data, please add this!");
continue;
}
if (!(CanUseProtocol && IsBlockSupportedCarpet(stateSchematic.getBlock())) && !FAKE_ROTATION_BETA.getBooleanValue() && !canPlaceFace(facedata, stateSchematic, primaryFacing, horizontalFacing))
Expand All @@ -815,9 +817,7 @@ else if (sBlock instanceof SandBlock || sBlock instanceof DragonEggBlock || sBlo
if ((stateSchematic.getBlock() instanceof DoorBlock
&& stateSchematic.get(DoorBlock.HALF) == DoubleBlockHalf.UPPER)
|| (stateSchematic.getBlock() instanceof BedBlock
&& stateSchematic.get(BedBlock.PART) == BedPart.HEAD)

) {
&& stateSchematic.get(BedBlock.PART) == BedPart.HEAD)) {
continue;
}
}
Expand Down Expand Up @@ -908,7 +908,7 @@ else if (blockSchematic instanceof TorchBlock){
if (hasGui(world.getBlockState(npos).getBlock())){
if (FAKE_ROTATION_BETA.getBooleanValue()){
FakeAccurateBlockPlacement.request(stateSchematic, pos);
interact++;
//interact++;
continue;
}
recordCause(pos, "Block at "+ pos.toShortString() + " can't be placed due to block at "+ npos.toShortString() +" has GUI");
Expand Down Expand Up @@ -1054,7 +1054,7 @@ else if (blockSchematic instanceof GrindstoneBlock){
}
else {
FakeAccurateBlockPlacement.request(stateSchematic, pos);
interact++;
//interact++;
//System.out.print("Requested\n");
}
if (stateSchematic.getBlock() instanceof SlabBlock
Expand Down

0 comments on commit ed4de60

Please sign in to comment.