Merge pull request #15 from Old-Chum/Update-NoCrystal
Fixed various problems with NoCrystal
This commit is contained in:
commit
5ecfa1183d
|
@ -8,15 +8,12 @@ import me.rigamortis.seppuku.api.util.MathUtil;
|
|||
import me.rigamortis.seppuku.api.value.BooleanValue;
|
||||
import me.rigamortis.seppuku.impl.module.player.FreeCamModule;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
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.math.AxisAlignedBB;
|
||||
|
@ -34,7 +31,8 @@ public final class NoCrystalModule extends Module {
|
|||
|
||||
public final BooleanValue disable = new BooleanValue("Disable", new String[]{"dis"}, false);
|
||||
|
||||
private int lastSlot;
|
||||
// When false, NoCrystal will not place while the player is sneaking
|
||||
public final BooleanValue sneak = new BooleanValue("PlaceOnSneak", new String[]{"sneak", "s", "pos", "sneakPlace"}, false);
|
||||
|
||||
public NoCrystalModule() {
|
||||
super("NoCrystal", new String[]{"AntiCrystal", "FeetPlace"}, "Automatically places obsidian in 4 cardinal directions", "NONE", -1, ModuleType.COMBAT);
|
||||
|
@ -43,7 +41,6 @@ public final class NoCrystalModule extends Module {
|
|||
@Listener
|
||||
public void onWalkingUpdate(EventUpdateWalkingPlayer event) {
|
||||
if (event.getStage() == EventStageable.EventStage.PRE) {
|
||||
|
||||
final FreeCamModule freeCam = (FreeCamModule) Seppuku.INSTANCE.getModuleManager().find(FreeCamModule.class);
|
||||
|
||||
if(freeCam != null && freeCam.isEnabled()) {
|
||||
|
@ -51,6 +48,7 @@ public final class NoCrystalModule extends Module {
|
|||
}
|
||||
|
||||
final Vec3d pos = MathUtil.interpolateEntity(mc.player, mc.getRenderPartialTicks());
|
||||
final float playerSpeed = (float) MathUtil.getDistance(pos, mc.player.posX, mc.player.posY, mc.player.posZ);
|
||||
|
||||
final BlockPos interpPos = new BlockPos(pos.x, pos.y, pos.z);
|
||||
|
||||
|
@ -59,39 +57,58 @@ public final class NoCrystalModule extends Module {
|
|||
final BlockPos east = interpPos.east();
|
||||
final BlockPos west = interpPos.west();
|
||||
|
||||
final boolean canPlace = valid(north) || valid(south) || valid(east) || valid(west);
|
||||
final BlockPos northBelow = interpPos.north().down();
|
||||
final BlockPos southBelow = interpPos.south().down();
|
||||
final BlockPos eastBelow = interpPos.east().down();
|
||||
final BlockPos westBelow = interpPos.west().down();
|
||||
|
||||
if (hasStack(Blocks.OBSIDIAN)) {
|
||||
if ((mc.player.onGround && mc.player.movementInput.moveForward == 0 && mc.player.movementInput.moveStrafe == 0)) {
|
||||
int lastSlot;
|
||||
final int slot = findStackHotbar(Blocks.OBSIDIAN);
|
||||
if (hasStack(Blocks.OBSIDIAN) || slot != -1) {
|
||||
if ((mc.player.onGround && playerSpeed <= 0.005f)
|
||||
&& (sneak.getBoolean() || (!mc.gameSettings.keyBindSneak.isKeyDown()))) {
|
||||
|
||||
lastSlot = mc.player.inventory.currentItem;
|
||||
mc.player.inventory.currentItem = slot;
|
||||
mc.playerController.updateController();
|
||||
|
||||
// Place supporting blocks
|
||||
if (valid(northBelow)) {
|
||||
place(northBelow, EnumFacing.SOUTH);
|
||||
}
|
||||
if (valid(southBelow)) {
|
||||
place(southBelow, EnumFacing.NORTH);
|
||||
}
|
||||
if (valid(eastBelow)) {
|
||||
place(eastBelow, EnumFacing.WEST);
|
||||
}
|
||||
if (valid(westBelow)) {
|
||||
place(westBelow, EnumFacing.EAST);
|
||||
}
|
||||
|
||||
// Place protecting blocks
|
||||
if (valid(north)) {
|
||||
place(north);
|
||||
place(north, EnumFacing.SOUTH);
|
||||
}
|
||||
if (valid(south)) {
|
||||
place(south);
|
||||
place(south, EnumFacing.NORTH);
|
||||
}
|
||||
if (valid(east)) {
|
||||
place(east);
|
||||
place(east, EnumFacing.WEST);
|
||||
}
|
||||
if (valid(west)) {
|
||||
place(west);
|
||||
place(west, EnumFacing.EAST);
|
||||
}
|
||||
|
||||
mc.player.inventory.currentItem = this.lastSlot;
|
||||
if (!slotEqualsBlock(lastSlot, Blocks.OBSIDIAN)) {
|
||||
mc.player.inventory.currentItem = lastSlot;
|
||||
}
|
||||
mc.playerController.updateController();
|
||||
|
||||
if(this.disable.getBoolean()) {
|
||||
this.toggle();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (canPlace && (mc.player.onGround && mc.player.movementInput.moveForward == 0 && mc.player.movementInput.moveStrafe == 0)) {
|
||||
final int slot = findStackHotbar(Blocks.OBSIDIAN);
|
||||
if (slot != -1) {
|
||||
this.lastSlot = mc.player.inventory.currentItem;
|
||||
mc.player.inventory.currentItem = slot;
|
||||
mc.playerController.updateController();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,118 +116,18 @@ public final class NoCrystalModule extends Module {
|
|||
private boolean hasStack(Block type) {
|
||||
if (mc.player.inventory.getCurrentItem().getItem() instanceof ItemBlock) {
|
||||
final ItemBlock block = (ItemBlock) mc.player.inventory.getCurrentItem().getItem();
|
||||
if (block.getBlock() == type) {
|
||||
return true;
|
||||
}
|
||||
return block.getBlock() == type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void place(BlockPos pos) {
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
final Block north = mc.world.getBlockState(pos.add(0, 0, -1)).getBlock();
|
||||
final Block south = mc.world.getBlockState(pos.add(0, 0, 1)).getBlock();
|
||||
final Block east = mc.world.getBlockState(pos.add(1, 0, 0)).getBlock();
|
||||
final Block west = mc.world.getBlockState(pos.add(-1, 0, 0)).getBlock();
|
||||
final Block up = mc.world.getBlockState(pos.add(0, 1, 0)).getBlock();
|
||||
final Block down = mc.world.getBlockState(pos.add(0, -1, 0)).getBlock();
|
||||
|
||||
if (up != null && up != Blocks.AIR && !(up instanceof BlockLiquid)) {
|
||||
final boolean activated = up.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.DOWN, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
private boolean slotEqualsBlock (int slot, Block type) {
|
||||
if (mc.player.inventory.getStackInSlot(slot).getItem() instanceof ItemBlock) {
|
||||
final ItemBlock block = (ItemBlock) mc.player.inventory.getStackInSlot(slot).getItem();
|
||||
return block.getBlock() == type;
|
||||
}
|
||||
|
||||
if (mc.playerController.processRightClickBlock(mc.player, mc.world, pos.add(0, 1, 0), EnumFacing.DOWN, new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
|
||||
if (down != null && down != Blocks.AIR && !(down instanceof BlockLiquid)) {
|
||||
final boolean activated = down.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
}
|
||||
|
||||
if (mc.playerController.processRightClickBlock(mc.player, mc.world, pos.add(0, -1, 0), EnumFacing.UP, new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
|
||||
if (north != null && north != Blocks.AIR && !(north instanceof BlockLiquid)) {
|
||||
final boolean activated = north.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
}
|
||||
|
||||
if (mc.playerController.processRightClickBlock(mc.player, mc.world, pos.add(0, 0, -1), EnumFacing.SOUTH, new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
|
||||
if (south != null && south != Blocks.AIR && !(south instanceof BlockLiquid)) {
|
||||
final boolean activated = south.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
}
|
||||
|
||||
if (mc.playerController.processRightClickBlock(mc.player, mc.world, pos.add(0, 0, 1), EnumFacing.NORTH, new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
|
||||
if (east != null && east != Blocks.AIR && !(east instanceof BlockLiquid)) {
|
||||
final boolean activated = east.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
}
|
||||
|
||||
if (mc.playerController.processRightClickBlock(mc.player, mc.world, pos.add(1, 0, 0), EnumFacing.WEST, new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
|
||||
if (west != null && west != Blocks.AIR && !(west instanceof BlockLiquid)) {
|
||||
final boolean activated = west.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
}
|
||||
|
||||
if (mc.playerController.processRightClickBlock(mc.player, mc.world, pos.add(-1, 0, 0), EnumFacing.EAST, new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int findStackHotbar(Block type) {
|
||||
|
@ -227,25 +144,28 @@ public final class NoCrystalModule extends Module {
|
|||
return -1;
|
||||
}
|
||||
|
||||
private boolean valid(BlockPos pos) {
|
||||
final Block block = mc.world.getBlockState(pos).getBlock();
|
||||
|
||||
final Block up = mc.world.getBlockState(pos.add(0, 1, 0)).getBlock();
|
||||
final Block down = mc.world.getBlockState(pos.add(0, -1, 0)).getBlock();
|
||||
final Block north = mc.world.getBlockState(pos.add(0, 0, -1)).getBlock();
|
||||
final Block south = mc.world.getBlockState(pos.add(0, 0, 1)).getBlock();
|
||||
final Block east = mc.world.getBlockState(pos.add(1, 0, 0)).getBlock();
|
||||
final Block west = mc.world.getBlockState(pos.add(-1, 0, 0)).getBlock();
|
||||
|
||||
return (block instanceof BlockAir)
|
||||
&& mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos)).isEmpty()
|
||||
&& ((up != null && up != Blocks.AIR && !(up instanceof BlockLiquid))
|
||||
|| (down != null && down != Blocks.AIR && !(down instanceof BlockLiquid))
|
||||
|| (north != null && north != Blocks.AIR && !(north instanceof BlockLiquid))
|
||||
|| (south != null && south != Blocks.AIR && !(south instanceof BlockLiquid))
|
||||
|| (east != null && east != Blocks.AIR && !(east instanceof BlockLiquid))
|
||||
|| (west != null && west != Blocks.AIR && !(west instanceof BlockLiquid)));
|
||||
private boolean valid (BlockPos pos) {
|
||||
// There are no entities to block placement,
|
||||
if (!mc.world.checkNoEntityCollision(new AxisAlignedBB(pos))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the block is replaceable
|
||||
return mc.world.getBlockState(pos).getBlock().isReplaceable(mc.world, pos);
|
||||
}
|
||||
|
||||
private void place (BlockPos pos, EnumFacing direction) {
|
||||
final Block block = mc.world.getBlockState(pos).getBlock();
|
||||
final boolean activated = block.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, direction, 0, 0, 0);
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||
}
|
||||
|
||||
this.mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, direction, EnumHand.MAIN_HAND, 0.0F, 0.0F, 0.0F));
|
||||
|
||||
if (activated) {
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue