Skip to content

Commit

Permalink
Revert "Replaced processRightClickBlock with direct packet sending"
Browse files Browse the repository at this point in the history
This reverts commit 7ed7613.
  • Loading branch information
IUDevman committed Feb 18, 2021
1 parent 3242b8c commit faf01c8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 62 deletions.
60 changes: 8 additions & 52 deletions src/main/java/com/gamesense/api/util/player/PlacementUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketEntityAction;
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;

public class PlacementUtil {

Expand Down Expand Up @@ -93,7 +86,7 @@ public static boolean place(BlockPos blockPos, EnumHand hand, boolean rotate) {
return false;
}

Vec3d hitVec = getHitVec(blockPos, opposite);
Vec3d hitVec = new Vec3d(neighbour).add(0.5, 0.5, 0.5).add(new Vec3d(opposite.getDirectionVec()).scale(0.5));
Block neighbourBlock = mc.world.getBlockState(neighbour).getBlock();

if (!isSneaking && BlockUtil.blackList.contains(neighbourBlock) || BlockUtil.shulkerList.contains(neighbourBlock)) {
Expand All @@ -112,53 +105,16 @@ public static boolean place(BlockPos blockPos, EnumHand hand, boolean rotate) {
BlockUtil.faceVectorPacketInstant(hitVec, true);
}

doPlace(neighbour, opposite, hand);
mc.rightClickDelayTimer = 4;
EnumActionResult action = mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, hand);
if (action == EnumActionResult.SUCCESS) {
mc.player.swingArm(hand);
mc.rightClickDelayTimer = 4;
}

if (stoppedAC) {
AutoCrystalGS.stopAC = false;
}

return true;
}

public static void doPlace(BlockPos pos, EnumFacing side, EnumHand hand) {
NetHandlerPlayClient connection = mc.getConnection();
if (connection == null) return;

Vec3d hitVecOffset = getHitVecOffset(side);
connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, side, hand, (float) hitVecOffset.x, (float) hitVecOffset.y, (float) hitVecOffset.z));
playSound(pos, side, hand, hitVecOffset);
mc.player.swingArm(hand);
}

private static Vec3d getHitVec(BlockPos pos, EnumFacing side) {
Vec3i directionVec = side.getDirectionVec();
return new Vec3d(
pos.getX() + 0.5 + directionVec.getX() * 0.5,
pos.getX() + 0.5 + directionVec.getY() * 0.5,
pos.getX() + 0.5 + directionVec.getZ() * 0.5
);
}

private static Vec3d getHitVecOffset(EnumFacing side) {
Vec3i directionVec = side.getDirectionVec();
return new Vec3d(
0.5 + directionVec.getX() * 0.5,
0.5 + directionVec.getY() * 0.5,
0.5 + directionVec.getZ() * 0.5
);
}

private static void playSound(BlockPos pos, EnumFacing side, EnumHand hand, Vec3d hitVecOffset) {
ItemStack itemStack = mc.player.getHeldItem(hand);
Block block = Block.getBlockFromItem(itemStack.getItem());
if (block == Blocks.AIR) return;

int metaDate = itemStack.getMetadata();
IBlockState blockState = block.getStateForPlacement(mc.world, pos, side, (float) hitVecOffset.x, (float) hitVecOffset.y, (float) hitVecOffset.z, metaDate, mc.player, hand);
SoundType soundType = block.getSoundType(blockState, mc.world, pos, mc.player);

mc.world.playSound(mc.player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f);
return action == EnumActionResult.SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.gamesense.api.setting.Setting;
import com.gamesense.api.util.combat.DamageUtil;
import com.gamesense.api.util.player.PlacementUtil;
import com.gamesense.api.util.world.BlockUtil;
import com.gamesense.client.module.Module;
import com.gamesense.client.module.ModuleManager;
Expand Down Expand Up @@ -248,7 +247,9 @@ private void placeBlock(BlockPos pos, int slotPressure) {
return;
}

PlacementUtil.doPlace(neighbour, opposite, swingHand);

mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, swingHand);
mc.player.swingArm(swingHand);

if (switchBack.getValue() && oldSlot != -1) {
mc.player.inventory.currentItem = oldSlot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gamesense.client.module.modules.combat;

import com.gamesense.api.setting.Setting;
import com.gamesense.api.util.player.PlacementUtil;
import com.gamesense.api.util.player.PlayerUtil;
import com.gamesense.api.util.world.BlockUtil;
import com.gamesense.api.util.world.EntityUtil;
Expand Down Expand Up @@ -418,7 +417,9 @@ private boolean placeBlock(BlockPos pos, int step) {
}

// Place the block
PlacementUtil.doPlace(neighbour, opposite, handSwing);
mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, handSwing);
mc.player.swingArm(handSwing);

// Disable fastplace
if (fastAnvil.getValue() && step == to_place.size() - 1) {
mc.rightClickDelayTimer = bef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.gamesense.api.util.combat.DamageUtil;
import com.gamesense.api.util.misc.MessageBus;
import com.gamesense.api.util.player.InventoryUtil;
import com.gamesense.api.util.player.PlacementUtil;
import com.gamesense.api.util.world.BlockUtil;
import com.gamesense.api.util.world.EntityUtil;
import com.gamesense.api.util.misc.Timer;
Expand Down Expand Up @@ -323,9 +322,8 @@ private void placeBedFinal(BlockPos blockPos, int direction, EnumFacing enumFaci
}

mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));

PlacementUtil.doPlace(neighbourPos, oppositeFacing, EnumHand.MAIN_HAND);

mc.playerController.processRightClickBlock(mc.player, mc.world, neighbourPos, oppositeFacing, vec3d, EnumHand.MAIN_HAND);
mc.player.swingArm(EnumHand.MAIN_HAND);
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
placedPos.add(blockPos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gamesense.api.setting.Setting;
import com.gamesense.api.util.combat.CrystalUtil;
import com.gamesense.api.util.misc.MessageBus;
import com.gamesense.api.util.player.PlacementUtil;
import com.gamesense.api.util.player.PlayerUtil;
import com.gamesense.api.util.world.BlockUtil;
import com.gamesense.api.util.world.EntityUtil;
Expand Down Expand Up @@ -872,7 +871,8 @@ private boolean placeBlock(BlockPos pos, int step, double offsetX, double offset
handSwing = EnumHand.OFF_HAND;

// Place the block
PlacementUtil.doPlace(neighbour, opposite, handSwing);
mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, handSwing);
mc.player.swingArm(handSwing);

return true;
}
Expand Down

0 comments on commit faf01c8

Please sign in to comment.