2019-10-27 15:45:44 +00:00
package me.rigamortis.seppuku.impl.module.combat ;
import me.rigamortis.seppuku.Seppuku ;
import me.rigamortis.seppuku.api.event.EventStageable ;
import me.rigamortis.seppuku.api.event.player.EventUpdateWalkingPlayer ;
import me.rigamortis.seppuku.api.module.Module ;
import me.rigamortis.seppuku.api.util.MathUtil ;
2019-12-03 21:59:48 +00:00
import me.rigamortis.seppuku.api.util.Timer ;
2019-12-01 16:45:36 +00:00
import me.rigamortis.seppuku.api.value.Value ;
2019-10-27 15:45:44 +00:00
import me.rigamortis.seppuku.impl.module.player.FreeCamModule ;
import net.minecraft.block.Block ;
2019-12-04 17:10:26 +00:00
import net.minecraft.block.state.IBlockState ;
2019-10-27 15:45:44 +00:00
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 ;
2019-12-04 13:57:55 +00:00
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock ;
2019-10-27 15:45:44 +00:00
import net.minecraft.util.EnumFacing ;
import net.minecraft.util.EnumHand ;
import net.minecraft.util.math.AxisAlignedBB ;
import net.minecraft.util.math.BlockPos ;
import net.minecraft.util.math.Vec3d ;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener ;
/ * *
* Author Seth
* 5 / 15 / 2019 @ 9 : 20 AM .
* /
public final class NoCrystalModule extends Module {
private final Minecraft mc = Minecraft . getMinecraft ( ) ;
2019-12-04 13:57:55 +00:00
public final Value < Mode > mode = new Value ( " Mode " , new String [ ] { " Mode " , " M " } , " The NoCrystal mode to use. Visible shows the swing animation and makes a sound, whereas packet does not. " , Mode . PACKET ) ;
2019-12-04 17:10:26 +00:00
public final Value < Boolean > rotate = new Value ( " Rotate " , new String [ ] { " rotation " , " r " , " rotate " } , " Rotate to place blocks " , true ) ;
2019-12-01 16:45:36 +00:00
public final Value < Boolean > disable = new Value < Boolean > ( " Disable " , new String [ ] { " dis " } , " Automatically disable after it places. " , false ) ;
2019-12-03 21:59:48 +00:00
public final Value < Boolean > sneak = new Value < Boolean > ( " PlaceOnSneak " , new String [ ] { " sneak " , " s " , " pos " , " sneakPlace " } , " When false, NoCrystal will not place while the player is sneaking. " , false ) ;
public final Value < Float > placeDelay = new Value ( " Delay " , new String [ ] { " PlaceDelay " , " PlaceDel " } , " The delay between obsidian blocks being placed. " , 100 . 0f , 0 . 0f , 1000 . 0f , 1 . 0f ) ;
private Timer placeTimer = new Timer ( ) ;
2019-12-05 22:21:35 +00:00
private int placeIndex = 0 ;
2019-10-27 15:45:44 +00:00
public NoCrystalModule ( ) {
2019-12-03 21:59:48 +00:00
super ( " NoCrystal " , new String [ ] { " AntiCrystal " , " FeetPlace " , " Surround " } , " Automatically places obsidian in 4 cardinal directions " , " NONE " , - 1 , ModuleType . COMBAT ) ;
2019-10-27 15:45:44 +00:00
}
2019-12-04 13:57:55 +00:00
@Override
public String getMetaData ( ) {
return this . mode . getValue ( ) . name ( ) ;
}
private enum Mode {
VISIBLE , PACKET
}
2019-10-27 15:45:44 +00:00
@Listener
public void onWalkingUpdate ( EventUpdateWalkingPlayer event ) {
2019-12-05 03:10:22 +00:00
final boolean instant = placeDelay . getValue ( ) = = 0 ;
if ( this . placeTimer . passed ( this . placeDelay . getValue ( ) ) | | instant ) {
if ( event . getStage ( ) = = EventStageable . EventStage . PRE ) {
final FreeCamModule freeCam = ( FreeCamModule ) Seppuku . INSTANCE . getModuleManager ( ) . find ( FreeCamModule . class ) ;
2019-10-27 15:45:44 +00:00
2019-12-05 03:10:22 +00:00
if ( freeCam ! = null & & freeCam . isEnabled ( ) ) {
return ;
}
2019-10-27 15:45:44 +00:00
2019-12-05 03:10:22 +00:00
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 ) ;
2019-10-27 15:45:44 +00:00
2019-12-05 03:10:22 +00:00
final BlockPos interpPos = new BlockPos ( pos . x , pos . y , pos . z ) ;
2019-11-27 02:54:16 +00:00
2019-12-05 03:10:22 +00:00
final BlockPos north = interpPos . north ( ) ;
final BlockPos south = interpPos . south ( ) ;
final BlockPos east = interpPos . east ( ) ;
final BlockPos west = interpPos . west ( ) ;
2019-12-04 14:39:06 +00:00
2019-12-05 03:10:22 +00:00
final BlockPos northBelow = north . down ( ) ;
final BlockPos southBelow = south . down ( ) ;
final BlockPos eastBelow = east . down ( ) ;
final BlockPos westBelow = west . down ( ) ;
2019-11-27 02:54:16 +00:00
2019-12-05 22:21:35 +00:00
final BlockPos [ ] surroundBlocks = { northBelow , southBelow , eastBelow , westBelow ,
north , south , east , west } ;
2019-12-05 21:42:14 +00:00
2019-12-05 03:10:22 +00:00
int lastSlot = 0 ;
final int slot = findStackHotbar ( Blocks . OBSIDIAN ) ;
if ( hasStack ( Blocks . OBSIDIAN ) | | slot ! = - 1 ) {
if ( ( mc . player . onGround & & playerSpeed < = 0 . 005f ) & & ( this . sneak . getValue ( ) | | ( ! mc . gameSettings . keyBindSneak . isKeyDown ( ) ) ) ) {
lastSlot = mc . player . inventory . currentItem ;
mc . player . inventory . currentItem = slot ;
mc . playerController . updateController ( ) ;
2019-12-05 21:42:14 +00:00
if ( valid ( surroundBlocks [ placeIndex ] ) )
place ( surroundBlocks [ placeIndex ] ) ;
if ( ! instant ) this . placeTimer . reset ( ) ;
2019-12-05 22:21:35 +00:00
if ( placeIndex > = surroundBlocks . length - 1 ) {
2019-12-05 21:42:14 +00:00
placeIndex = 0 ;
if ( this . disable . getValue ( ) ) this . toggle ( ) ;
2019-12-05 22:21:35 +00:00
} else placeIndex + + ;
2019-11-27 02:54:16 +00:00
}
if ( ! slotEqualsBlock ( lastSlot , Blocks . OBSIDIAN ) ) {
mc . player . inventory . currentItem = lastSlot ;
}
2019-10-27 15:45:44 +00:00
mc . playerController . updateController ( ) ;
}
}
}
}
private boolean hasStack ( Block type ) {
if ( mc . player . inventory . getCurrentItem ( ) . getItem ( ) instanceof ItemBlock ) {
final ItemBlock block = ( ItemBlock ) mc . player . inventory . getCurrentItem ( ) . getItem ( ) ;
2019-11-27 02:54:16 +00:00
return block . getBlock ( ) = = type ;
2019-10-27 15:45:44 +00:00
}
return false ;
}
2019-11-27 02:54:16 +00:00
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 ;
2019-10-27 15:45:44 +00:00
}
2019-11-27 02:54:16 +00:00
return false ;
2019-10-27 15:45:44 +00:00
}
private int findStackHotbar ( Block type ) {
for ( int i = 0 ; i < 9 ; i + + ) {
final ItemStack stack = Minecraft . getMinecraft ( ) . player . inventory . getStackInSlot ( i ) ;
if ( stack . getItem ( ) instanceof ItemBlock ) {
final ItemBlock block = ( ItemBlock ) stack . getItem ( ) ;
if ( block . getBlock ( ) = = type ) {
return i ;
}
}
}
return - 1 ;
}
2019-11-27 02:54:16 +00:00
private boolean valid ( BlockPos pos ) {
// There are no entities to block placement,
if ( ! mc . world . checkNoEntityCollision ( new AxisAlignedBB ( pos ) ) ) {
return false ;
}
2019-10-27 15:45:44 +00:00
2019-11-27 02:54:16 +00:00
// Check if the block is replaceable
return mc . world . getBlockState ( pos ) . getBlock ( ) . isReplaceable ( mc . world , pos ) ;
2019-10-27 15:45:44 +00:00
}
2019-12-04 17:10:26 +00:00
private void place ( BlockPos pos ) {
2019-11-27 02:54:16 +00:00
final Block block = mc . world . getBlockState ( pos ) . getBlock ( ) ;
2019-12-04 17:10:26 +00:00
final EnumFacing direction = calcSide ( pos ) ;
2019-11-27 02:54:16 +00:00
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 ) ) ;
}
2019-12-04 17:10:26 +00:00
if ( direction ! = null ) {
2019-12-05 22:21:35 +00:00
final EnumFacing otherSide = direction . getOpposite ( ) ;
final BlockPos sideOffset = pos . offset ( direction ) ;
2019-12-04 13:57:55 +00:00
2019-12-04 17:10:26 +00:00
if ( rotate . getValue ( ) ) {
final float [ ] angle = MathUtil . calcAngle ( mc . player . getPositionEyes ( mc . getRenderPartialTicks ( ) ) , new Vec3d ( pos . getX ( ) + 0 . 5f , pos . getY ( ) + 0 . 5f , pos . getZ ( ) + 0 . 5f ) ) ;
Seppuku . INSTANCE . getRotationManager ( ) . setPlayerRotations ( angle [ 0 ] , angle [ 1 ] ) ;
}
if ( mode . getValue ( ) = = Mode . PACKET ) {
2019-12-05 22:21:35 +00:00
mc . player . connection . sendPacket ( new CPacketPlayerTryUseItemOnBlock ( sideOffset , otherSide , EnumHand . MAIN_HAND , 0 . 5F , 0 . 5F , 0 . 5F ) ) ;
2019-12-04 17:17:43 +00:00
mc . player . swingArm ( EnumHand . MAIN_HAND ) ;
2019-12-04 17:10:26 +00:00
} else if ( mode . getValue ( ) = = Mode . VISIBLE ) {
2019-12-05 22:21:35 +00:00
mc . playerController . processRightClickBlock ( mc . player , mc . world , sideOffset , otherSide , new Vec3d ( 0 . 5F , 0 . 5F , 0 . 5F ) , EnumHand . MAIN_HAND ) ;
2019-12-04 17:17:43 +00:00
mc . player . swingArm ( EnumHand . MAIN_HAND ) ;
2019-12-04 13:57:55 +00:00
}
2019-12-04 03:56:41 +00:00
}
2019-11-27 02:54:16 +00:00
if ( activated ) {
mc . player . connection . sendPacket ( new CPacketEntityAction ( mc . player , CPacketEntityAction . Action . STOP_SNEAKING ) ) ;
}
}
2019-12-04 17:10:26 +00:00
private EnumFacing calcSide ( BlockPos pos ) {
for ( EnumFacing side : EnumFacing . values ( ) ) {
2019-12-05 03:10:22 +00:00
BlockPos sideOffset = pos . offset ( side ) ;
IBlockState offsetState = mc . world . getBlockState ( sideOffset ) ;
if ( ! offsetState . getBlock ( ) . canCollideCheck ( offsetState , false ) ) {
2019-12-04 17:10:26 +00:00
continue ;
}
2019-12-05 03:10:22 +00:00
if ( ! offsetState . getMaterial ( ) . isReplaceable ( ) ) {
2019-12-04 17:10:26 +00:00
return side ;
}
}
return null ;
}
2019-10-27 15:45:44 +00:00
}