2018-09-13 12:03:28 -04:00
package noppes.npcs.scripted ;
import net.minecraft.block.Block ;
2023-05-31 23:59:11 -05:00
import net.minecraft.block.BlockAir ;
2018-09-13 12:03:28 -04:00
import net.minecraft.entity.Entity ;
import net.minecraft.entity.effect.EntityLightningBolt ;
import net.minecraft.entity.player.EntityPlayer ;
2022-05-03 23:09:21 -05:00
import net.minecraft.entity.player.EntityPlayerMP ;
2018-09-13 12:03:28 -04:00
import net.minecraft.init.Blocks ;
import net.minecraft.nbt.NBTBase ;
import net.minecraft.nbt.NBTBase.NBTPrimitive ;
import net.minecraft.nbt.NBTTagCompound ;
import net.minecraft.nbt.NBTTagString ;
import net.minecraft.server.MinecraftServer ;
import net.minecraft.tileentity.TileEntity ;
import net.minecraft.tileentity.TileEntitySign ;
2024-03-28 01:34:12 -04:00
import net.minecraft.util.* ;
import net.minecraft.util.math.BlockPos ;
2018-09-13 12:03:28 -04:00
import net.minecraft.world.WorldServer ;
2023-03-15 22:50:50 -05:00
import net.minecraftforge.common.MinecraftForge ;
import net.minecraftforge.common.util.BlockSnapshot ;
2023-03-15 23:10:03 -05:00
import net.minecraftforge.common.util.FakePlayer ;
2023-03-15 22:50:50 -05:00
import net.minecraftforge.event.world.BlockEvent ;
2022-06-10 17:25:58 -05:00
import noppes.npcs.CustomNpcs ;
2018-09-13 12:03:28 -04:00
import noppes.npcs.NoppesUtilServer ;
2023-01-12 21:33:06 -05:00
import noppes.npcs.api.* ;
2022-11-15 15:25:53 -05:00
import noppes.npcs.api.entity.IEntity ;
import noppes.npcs.api.entity.IPlayer ;
import noppes.npcs.api.handler.data.ISound ;
import noppes.npcs.api.item.IItemStack ;
2023-01-12 21:33:06 -05:00
import noppes.npcs.api.scoreboard.IScoreboard ;
import noppes.npcs.blocks.tiles.TileBigSign ;
import noppes.npcs.controllers.ScriptController ;
import noppes.npcs.controllers.ServerCloneController ;
2023-03-15 22:50:50 -05:00
import noppes.npcs.entity.EntityNPCInterface ;
2022-11-05 20:19:14 -05:00
import noppes.npcs.scripted.scoreboard.ScriptScoreboard ;
2018-09-13 12:03:28 -04:00
2023-01-12 21:33:06 -05:00
import java.util.* ;
2021-10-18 06:33:39 -05:00
public class ScriptWorld implements IWorld {
2022-11-05 20:19:14 -05:00
private static final Map < String , Object > tempData = new HashMap <> ();
2021-09-30 21:44:30 -05:00
public WorldServer world ;
2018-09-13 12:03:28 -04:00
public ScriptWorld ( WorldServer world ){
this . world = world ;
}
2021-09-30 21:44:30 -05:00
2022-06-10 17:25:58 -05:00
public static ScriptWorld createNew ( int dimensionId ) {
WorldServer [] worlds = CustomNpcs . getServer (). worldServers ;
WorldServer world = worlds [ 0 ] ;
for ( WorldServer w : worlds ) {
if ( w . provider . dimensionId == dimensionId ) {
world = w ;
}
}
2021-09-30 21:44:30 -05:00
return new ScriptWorld ( world );
}
2018-09-13 12:03:28 -04:00
/**
* @return The worlds time
*/
public long getTime (){
return world . getWorldTime ();
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @return The total world time
*/
public long getTotalTime (){
return world . getTotalWorldTime ();
}
2022-05-03 23:09:21 -05:00
public boolean areAllPlayersAsleep (){
return world . areAllPlayersAsleep ();
}
2022-05-27 15:31:02 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param x World position x
* @param y World position y
* @param z World position z
* @return The block at the given position. Returns null if there isn't a block
*/
2021-10-12 03:23:56 -05:00
public IBlock getBlock ( int x , int y , int z ){
2022-11-05 20:19:14 -05:00
return NpcAPI . Instance (). getIBlock ( this , x , y , z );
}
/**
* @param pos
* @return The block at the given position. Returns null if there isn't a block
*/
public IBlock getBlock ( IPos pos ){
return NpcAPI . Instance (). getIBlock ( this , pos );
}
public boolean isBlockFreezable ( IPos pos ) {
return this . isBlockFreezable ( pos . getX (), pos . getY (), pos . getZ ());
2018-09-13 12:03:28 -04:00
}
2022-05-03 23:09:21 -05:00
public boolean isBlockFreezable ( int x , int y , int z ){
return world . isBlockFreezable ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public boolean isBlockFreezableNaturally ( IPos pos ) {
return this . isBlockFreezableNaturally ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public boolean isBlockFreezableNaturally ( int x , int y , int z ){
return world . isBlockFreezableNaturally ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public boolean canBlockFreeze ( IPos pos , boolean adjacentToWater ) {
return this . canBlockFreeze ( pos . getX (), pos . getY (), pos . getZ (), adjacentToWater );
}
2022-05-03 23:09:21 -05:00
public boolean canBlockFreeze ( int x , int y , int z , boolean adjacentToWater ){
return world . canBlockFreeze ( x , y , z , adjacentToWater );
}
2022-11-05 20:19:14 -05:00
public boolean canBlockFreezeBody ( IPos pos , boolean adjacentToWater ) {
return this . canBlockFreezeBody ( pos . getX (), pos . getY (), pos . getZ (), adjacentToWater );
}
2022-05-03 23:09:21 -05:00
public boolean canBlockFreezeBody ( int x , int y , int z , boolean adjacentToWater ){
return world . canBlockFreezeBody ( x , y , z , adjacentToWater );
}
2022-11-05 20:19:14 -05:00
public boolean canSnowAt ( IPos pos , boolean checkLight ) {
return this . canSnowAt ( pos . getX (), pos . getY (), pos . getZ (), checkLight );
}
2022-05-03 23:09:21 -05:00
public boolean canSnowAt ( int x , int y , int z , boolean checkLight ){
return world . func_147478_e ( x , y , z , checkLight );
}
2022-11-05 20:19:14 -05:00
public boolean canSnowAtBody ( IPos pos , boolean checkLight ) {
return this . canSnowAtBody ( pos . getX (), pos . getY (), pos . getZ (), checkLight );
}
2022-05-03 23:09:21 -05:00
public boolean canSnowAtBody ( int x , int y , int z , boolean checkLight ){
return world . canSnowAtBody ( x , y , z , checkLight );
}
public IBlock getTopBlock ( int x , int z ){
2022-11-05 20:19:14 -05:00
return NpcAPI . Instance (). getIBlock ( this , x , world . getTopSolidOrLiquidBlock ( x , z ) , z );
}
2022-05-03 23:09:21 -05:00
2022-11-05 20:19:14 -05:00
public IBlock getTopBlock ( IPos pos ) {
return this . getTopBlock ( pos . getX (), pos . getZ ());
2022-05-03 23:09:21 -05:00
}
public int getHeightValue ( int x , int z ){
return world . getHeightValue ( x , z );
}
2022-11-05 20:19:14 -05:00
public int getHeightValue ( IPos pos ) {
return this . getHeightValue ( pos . getX (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public int getChunkHeightMapMinimum ( int x , int z ){
return world . getChunkHeightMapMinimum ( x , z );
}
2022-11-05 20:19:14 -05:00
public int getChunkHeightMapMinimum ( IPos pos ){
return this . getChunkHeightMapMinimum ( pos . getX (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public int getBlockMetadata ( int x , int y , int z ){
return world . getBlockMetadata ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public int getBlockMetadata ( IPos pos ){
return this . getBlockMetadata ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public boolean setBlockMetadataWithNotify ( int x , int y , int z , int metadata , int flag ){
return world . setBlockMetadataWithNotify ( x , y , z , metadata , flag );
}
2022-11-05 20:19:14 -05:00
public boolean setBlockMetadataWithNotify ( IPos pos , int metadata , int flag ){
return this . setBlockMetadataWithNotify ( pos . getX (), pos . getY (), pos . getZ (), metadata , flag );
}
public boolean canSeeSky ( int x , int y , int z ) {
return world . canBlockSeeTheSky ( x , y , z );
}
public boolean canSeeSky ( IPos pos ) {
return canSeeSky ( pos . getX (), pos . getY (), pos . getZ ());
2022-05-03 23:09:21 -05:00
}
public int getFullBlockLightValue ( int x , int y , int z ){
return world . getFullBlockLightValue ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public int getFullBlockLightValue ( IPos pos ){
return this . getFullBlockLightValue ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public int getBlockLightValue ( int x , int y , int z ){
return world . getBlockLightValue ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public int getBlockLightValue ( IPos pos ){
return this . getBlockLightValue ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-11 22:08:31 -05:00
public void playSoundAtEntity ( IEntity entity , String sound , float volume , float pitch ){
2022-05-03 23:09:21 -05:00
world . playSoundAtEntity ( entity . getMCEntity (), sound , volume , pitch );
}
2022-05-11 22:08:31 -05:00
public void playSoundToNearExcept ( IPlayer player , String sound , float volume , float pitch ){
2022-05-03 23:09:21 -05:00
world . playSoundToNearExcept (( EntityPlayerMP ) player . getMCEntity (), sound , volume , pitch );
}
2022-07-13 19:27:27 -05:00
public void playSound ( int id , ISound sound ) {
IPlayer [] players = getAllServerPlayers ();
for ( IPlayer player : players ) {
if ( player . getDimension () == this . getDimensionID ()) {
player . playSound ( id , sound );
}
}
}
public void stopSound ( int id ) {
IPlayer [] players = getAllServerPlayers ();
for ( IPlayer player : players ) {
if ( player . getDimension () == this . getDimensionID ()) {
player . stopSound ( id );
}
}
}
public void pauseSounds () {
IPlayer [] players = getAllServerPlayers ();
for ( IPlayer player : players ) {
if ( player . getDimension () == this . getDimensionID ()) {
player . pauseSounds ();
}
}
}
public void continueSounds () {
IPlayer [] players = getAllServerPlayers ();
for ( IPlayer player : players ) {
if ( player . getDimension () == this . getDimensionID ()) {
player . continueSounds ();
}
}
}
public void stopSounds () {
IPlayer [] players = getAllServerPlayers ();
for ( IPlayer player : players ) {
if ( player . getDimension () == this . getDimensionID ()) {
player . stopSounds ();
}
}
}
2022-05-11 13:30:13 -05:00
public IEntity getEntityByID ( int id ){
2022-05-11 22:08:31 -05:00
return NpcAPI . Instance (). getIEntity ( world . getEntityByID ( id ));
2022-05-03 23:09:21 -05:00
}
2022-05-11 22:08:31 -05:00
public boolean spawnEntityInWorld ( IEntity entity ){
2022-05-03 23:09:21 -05:00
return world . spawnEntityInWorld ( entity . getMCEntity ());
}
2022-11-05 20:19:14 -05:00
public boolean spawnEntityInWorld ( IEntity entity , double x , double y , double z ){
entity . setPosition ( x , y , z );
return this . spawnEntityInWorld ( entity );
}
public boolean spawnEntityInWorld ( IEntity entity , IPos pos ) {
return this . spawnEntityInWorld ( entity , pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-11 22:08:31 -05:00
public IPlayer getClosestPlayerToEntity ( IEntity entity , double range ){
return ( IPlayer ) NpcAPI . Instance (). getIEntity ( world . getClosestPlayerToEntity ( entity . getMCEntity (), range ));
2022-05-03 23:09:21 -05:00
}
2022-05-11 22:08:31 -05:00
public IPlayer getClosestPlayer ( double x , double y , double z , double range ){
return ( IPlayer ) NpcAPI . Instance (). getIEntity ( world . getClosestPlayer ( x , y , z , range ));
2022-05-03 23:09:21 -05:00
}
2022-11-05 20:19:14 -05:00
public IPlayer getClosestPlayer ( IPos pos , double range ){
return this . getClosestPlayer ( pos . getX (), pos . getY (), pos . getZ (), range );
}
2022-05-11 22:08:31 -05:00
public IPlayer getClosestVulnerablePlayerToEntity ( IEntity entity , double range ){
return ( IPlayer ) NpcAPI . Instance (). getIEntity ( world . getClosestVulnerablePlayerToEntity ( entity . getMCEntity (), range ));
2022-05-03 23:09:21 -05:00
}
2022-05-11 22:08:31 -05:00
public IPlayer getClosestVulnerablePlayer ( double x , double y , double z , double range ){
return ( IPlayer ) NpcAPI . Instance (). getIEntity ( world . getClosestVulnerablePlayer ( x , y , z , range ));
2022-05-03 23:09:21 -05:00
}
2022-11-05 20:19:14 -05:00
public IPlayer getClosestVulnerablePlayer ( IPos pos , double range ){
return this . getClosestVulnerablePlayer ( pos . getX (), pos . getY (), pos . getZ (), range );
}
2022-05-11 22:08:31 -05:00
public int countEntities ( IEntity entity ){
2022-05-03 23:09:21 -05:00
return world . countEntities ( entity . getMCEntity (). getClass ());
}
2022-06-12 01:26:23 -05:00
public IEntity [] getLoadedEntities () {
ArrayList < IEntity > list = new ArrayList <> ();
for ( Object obj : world . loadedEntityList ) {
list . add ( NpcAPI . Instance (). getIEntity (( Entity ) obj ));
}
return list . toArray ( new IEntity [ 0 ] );
}
2022-07-06 17:51:26 -05:00
public IEntity [] getEntitiesNear ( IPos position , double range ) {
ArrayList < IEntity > list = new ArrayList <> ();
List < Entity > entities = world . getEntitiesWithinAABB ( Entity . class , AxisAlignedBB . getBoundingBox (
position . getX () - range , position . getY () - range , position . getZ () - range ,
position . getX () + range , position . getY () + range , position . getZ () + range ));
for ( Entity entity : entities ){
list . add ( NpcAPI . Instance (). getIEntity ( entity ));
}
2022-07-06 18:12:32 -05:00
list . sort (( e1 , e2 ) -> {
2022-11-05 20:19:14 -05:00
double dist1 = e1 . getPosition (). distanceTo ( position );
double dist2 = e2 . getPosition (). distanceTo ( position );
2022-07-06 18:12:32 -05:00
if ( dist1 > dist2 ) {
return 1 ;
} else if ( dist1 < dist2 ) {
return - 1 ;
}
return 0 ;
});
2022-07-06 17:51:26 -05:00
return list . toArray ( new IEntity [ 0 ] );
}
2022-07-06 18:12:32 -05:00
public IEntity [] getEntitiesNear ( double x , double y , double z , double range ) {
2022-11-05 20:19:14 -05:00
return getEntitiesNear ( NpcAPI . Instance (). getIPos ( x , y , z ), range );
2022-07-06 18:12:32 -05:00
}
2022-05-11 22:08:31 -05:00
public void setTileEntity ( int x , int y , int z , ITileEntity tileEntity ){
2022-05-03 23:09:21 -05:00
world . setTileEntity ( x , y , z , tileEntity . getMCTileEntity ());
}
2022-11-05 20:19:14 -05:00
public void setTileEntity ( IPos pos , ITileEntity tileEntity ){
this . setTileEntity ( pos . getX (), pos . getY (), pos . getZ (), tileEntity );
}
2022-05-03 23:09:21 -05:00
public void removeTileEntity ( int x , int y , int z ){
world . removeTileEntity ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public void removeTileEntity ( IPos pos ){
this . removeTileEntity ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public boolean isBlockFullCube ( int x , int y , int z ){
return world . func_147469_q ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public boolean isBlockFullCube ( IPos pos ){
return this . isBlockFullCube ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public long getSeed (){
return world . getSeed ();
}
public void setSpawnLocation ( int x , int y , int z ){
world . setSpawnLocation ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public void setSpawnLocation ( IPos pos ){
this . setSpawnLocation ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public boolean canLightningStrikeAt ( int x , int y , int z ){
return world . canLightningStrikeAt ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public boolean canLightningStrikeAt ( IPos pos ){
return this . canLightningStrikeAt ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-05-03 23:09:21 -05:00
public boolean isBlockHighHumidity ( int x , int y , int z ){
return world . isBlockHighHumidity ( x , y , z );
}
2022-11-05 20:19:14 -05:00
public boolean isBlockHighHumidity ( IPos pos ){
return this . canLightningStrikeAt ( pos . getX (), pos . getY (), pos . getZ ());
2022-05-26 02:10:25 -05:00
}
2018-09-13 12:03:28 -04:00
/**
* @param x World position x
* @param y World position y
* @param z World position z
* @return Text from signs
* @since 1.7.10d
*/
public String getSignText ( int x , int y , int z ){
TileEntity tile = world . getTileEntity ( x , y , z );
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
if ( tile instanceof TileBigSign )
return (( TileBigSign ) tile ). getText ();
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
if ( tile instanceof TileEntitySign ){
TileEntitySign tileSign = ( TileEntitySign ) tile ;
String s = tileSign . signText [ 0 ] + "\n" ;
s += tileSign . signText [ 1 ] + "\n" ;
s += tileSign . signText [ 2 ] + "\n" ;
s += tileSign . signText [ 3 ] ;
return s ;
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
return null ;
}
2022-11-05 20:19:14 -05:00
public String getSignText ( IPos pos ) {
return this . getSignText ( pos . getX (), pos . getY (), pos . getZ ());
}
2022-11-06 15:08:58 -06:00
public boolean setBlock ( int x , int y , int z , IBlock block ){
2022-05-26 01:51:05 -05:00
if ( block == null || block . getMCBlock (). isAir ( world , x , y , z )){
2022-11-05 20:19:14 -05:00
this . removeBlock ( x , y , z );
2022-11-06 15:08:58 -06:00
return false ;
2022-05-26 01:51:05 -05:00
}
2022-11-06 15:08:58 -06:00
return world . setBlock ( x , y , z , block . getMCBlock ());
2022-05-26 01:51:05 -05:00
}
2022-05-27 15:31:02 -05:00
2022-11-06 15:08:58 -06:00
public boolean setBlock ( IPos pos , IBlock block ){
return this . setBlock ( pos . getX (), pos . getY (), pos . getZ (), block );
2022-11-05 20:19:14 -05:00
}
2018-09-13 12:03:28 -04:00
/**
* @param x World position x
* @param y World position y
* @param z World position z
* @param item The block to be set
*/
2022-11-06 15:08:58 -06:00
public boolean setBlock ( int x , int y , int z , IItemStack item ){
2018-09-13 12:03:28 -04:00
if ( item == null ){
2022-11-05 20:19:14 -05:00
this . removeBlock ( x , y , z );
2022-11-06 15:08:58 -06:00
return false ;
2018-09-13 12:03:28 -04:00
}
2022-05-11 22:08:31 -05:00
Block block = Block . getBlockFromItem ( item . getMCItemStack (). getItem ());
2018-09-13 12:03:28 -04:00
if ( block == null || block == Blocks . air )
2022-11-06 15:08:58 -06:00
return false ;
return world . setBlock ( x , y , z , block );
2018-09-13 12:03:28 -04:00
}
2022-11-05 20:19:14 -05:00
2022-11-06 15:08:58 -06:00
public boolean setBlock ( IPos pos , IItemStack itemStack ){
return this . setBlock ( pos . getX (), pos . getY (), pos . getZ (), itemStack );
2022-11-05 20:19:14 -05:00
}
2018-09-13 12:03:28 -04:00
/**
* @param x World position x
* @param y World position y
* @param z World position z
*/
public void removeBlock ( int x , int y , int z ){
world . setBlock ( x , y , z , Blocks . air );
}
2022-05-27 15:31:02 -05:00
2022-11-05 20:19:14 -05:00
public void removeBlock ( IPos pos ){
this . removeBlock ( pos . getX (), pos . getY (), pos . getZ ());
}
2023-03-15 22:50:50 -05:00
public boolean isPlaceCancelled ( int posX , int posY , int posZ ) {
IBlock block = this . getBlock ( posX , posY , posZ );
if ( block == null ) {
return false ;
}
Block mcBlock = block . getMCBlock ();
int metadata = this . getBlockMetadata ( posX , posY , posZ );
2023-03-15 23:10:03 -05:00
FakePlayer fakePlayer = new FakePlayer ( this . world , EntityNPCInterface . chateventProfile );
IItemStack stack = NpcAPI . Instance (). createItem ( "minecraft:stone" , 0 , 1 );
fakePlayer . setCurrentItemOrArmor ( 0 , stack . getMCItemStack ());
2023-03-15 22:50:50 -05:00
final BlockEvent . PlaceEvent placeEvent = new BlockEvent . PlaceEvent (
new BlockSnapshot ( this . world , ( int ) Math . floor ( posX ), ( int ) Math . floor ( posY ), ( int ) Math . floor ( posZ ), mcBlock , metadata ),
2023-03-15 23:10:03 -05:00
Blocks . air , fakePlayer );
2023-03-15 22:50:50 -05:00
MinecraftForge . EVENT_BUS . post ( placeEvent );
return placeEvent . isCanceled ();
}
public boolean isPlaceCancelled ( IPos pos ) {
return this . isPlaceCancelled ( pos . getX (), pos . getY (), pos . getZ ());
}
public boolean isBreakCancelled ( int posX , int posY , int posZ ) {
IBlock block = this . getBlock ( posX , posY , posZ );
if ( block == null ) {
return false ;
}
Block mcBlock = block . getMCBlock ();
int metadata = this . getBlockMetadata ( posX , posY , posZ );
2023-03-15 23:10:03 -05:00
FakePlayer fakePlayer = new FakePlayer ( this . world , EntityNPCInterface . chateventProfile );
IItemStack stack = NpcAPI . Instance (). createItem ( "minecraft:stone" , 0 , 1 );
fakePlayer . setCurrentItemOrArmor ( 0 , stack . getMCItemStack ());
2023-03-15 22:50:50 -05:00
final BlockEvent . BreakEvent placeEvent = new BlockEvent . BreakEvent ( posX , posY , posZ , world ,
2023-03-15 23:10:03 -05:00
mcBlock , metadata , fakePlayer );
2023-03-15 22:50:50 -05:00
MinecraftForge . EVENT_BUS . post ( placeEvent );
return placeEvent . isCanceled ();
}
public boolean isBreakCancelled ( IPos pos ) {
return this . isBreakCancelled ( pos . getX (), pos . getY (), pos . getZ ());
}
2023-06-01 21:24:59 -05:00
public MovingObjectPosition rayCast ( Vec3 startVec , Vec3 endVec , boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision )
2023-05-31 23:59:11 -05:00
{
if ( ! Double . isNaN ( startVec . xCoord ) && ! Double . isNaN ( startVec . yCoord ) && ! Double . isNaN ( startVec . zCoord ))
{
if ( ! Double . isNaN ( endVec . xCoord ) && ! Double . isNaN ( endVec . yCoord ) && ! Double . isNaN ( endVec . zCoord ))
{
int endX = MathHelper . floor_double ( endVec . xCoord );
int endY = MathHelper . floor_double ( endVec . yCoord );
int endZ = MathHelper . floor_double ( endVec . zCoord );
int l = MathHelper . floor_double ( startVec . xCoord );
int i1 = MathHelper . floor_double ( startVec . yCoord );
int j1 = MathHelper . floor_double ( startVec . zCoord );
Block block = this . world . getBlock ( l , i1 , j1 );
int k1 = this . world . getBlockMetadata ( l , i1 , j1 );
if ( block . canCollideCheck ( k1 , false ))
{
MovingObjectPosition movingobjectposition = block . collisionRayTrace ( this . world , l , i1 , j1 , startVec , endVec );
if ( movingobjectposition != null )
{
return movingobjectposition ;
}
}
k1 = 200 ;
while ( k1 -- >= 0 )
{
if ( Double . isNaN ( startVec . xCoord ) || Double . isNaN ( startVec . yCoord ) || Double . isNaN ( startVec . zCoord ))
{
return null ;
}
if ( l == endX && i1 == endY && j1 == endZ )
{
return null ;
}
boolean flag6 = true ;
boolean flag3 = true ;
boolean flag4 = true ;
double d0 = 999 . 0D ;
double d1 = 999 . 0D ;
double d2 = 999 . 0D ;
if ( endX > l )
{
d0 = ( double ) l + 1 . 0D ;
}
else if ( endX < l )
{
d0 = ( double ) l + 0 . 0D ;
}
else
{
flag6 = false ;
}
if ( endY > i1 )
{
d1 = ( double ) i1 + 1 . 0D ;
}
else if ( endY < i1 )
{
d1 = ( double ) i1 + 0 . 0D ;
}
else
{
flag3 = false ;
}
if ( endZ > j1 )
{
d2 = ( double ) j1 + 1 . 0D ;
}
else if ( endZ < j1 )
{
d2 = ( double ) j1 + 0 . 0D ;
}
else
{
flag4 = false ;
}
double d3 = 999 . 0D ;
double d4 = 999 . 0D ;
double d5 = 999 . 0D ;
double d6 = endVec . xCoord - startVec . xCoord ;
double d7 = endVec . yCoord - startVec . yCoord ;
double d8 = endVec . zCoord - startVec . zCoord ;
if ( flag6 )
{
d3 = ( d0 - startVec . xCoord ) / d6 ;
}
if ( flag3 )
{
d4 = ( d1 - startVec . yCoord ) / d7 ;
}
if ( flag4 )
{
d5 = ( d2 - startVec . zCoord ) / d8 ;
}
byte b0 ;
if ( d3 < d4 && d3 < d5 )
{
if ( endX > l )
{
b0 = 4 ;
}
else
{
b0 = 5 ;
}
startVec . xCoord = d0 ;
startVec . yCoord += d7 * d3 ;
startVec . zCoord += d8 * d3 ;
}
else if ( d4 < d5 )
{
if ( endY > i1 )
{
b0 = 0 ;
}
else
{
b0 = 1 ;
}
startVec . xCoord += d6 * d4 ;
startVec . yCoord = d1 ;
startVec . zCoord += d8 * d4 ;
}
else
{
if ( endZ > j1 )
{
b0 = 2 ;
}
else
{
b0 = 3 ;
}
startVec . xCoord += d6 * d5 ;
startVec . yCoord += d7 * d5 ;
startVec . zCoord = d2 ;
}
Vec3 vec32 = Vec3 . createVectorHelper ( startVec . xCoord , startVec . yCoord , startVec . zCoord );
l = ( int )( vec32 . xCoord = ( double ) MathHelper . floor_double ( startVec . xCoord ));
if ( b0 == 5 )
{
-- l ;
++ vec32 . xCoord ;
}
i1 = ( int )( vec32 . yCoord = ( double ) MathHelper . floor_double ( startVec . yCoord ));
if ( b0 == 1 )
{
-- i1 ;
++ vec32 . yCoord ;
}
j1 = ( int )( vec32 . zCoord = ( double ) MathHelper . floor_double ( startVec . zCoord ));
if ( b0 == 3 )
{
-- j1 ;
++ vec32 . zCoord ;
}
Block block1 = this . world . getBlock ( l , i1 , j1 );
int l1 = this . world . getBlockMetadata ( l , i1 , j1 );
MovingObjectPosition movingobjectposition1 = block1 . collisionRayTrace ( this . world , l , i1 , j1 , startVec , endVec );
if ( movingobjectposition1 != null )
{
if ( block1 . canCollideCheck ( l1 , false ) && stopOnBlock ||
block1 . getMaterial (). isLiquid () && stopOnLiquid ||
! ( block1 instanceof BlockAir ) && block1 . getCollisionBoundingBoxFromPool ( this . world , l , i1 , j1 ) == null && ! stopOnCollision )
{
return movingobjectposition1 ;
}
}
}
return null ;
}
else
{
return null ;
}
}
else
{
return null ;
}
}
2022-07-07 20:49:03 -05:00
public IPos rayCastPos ( double [] startPos , double [] lookVector , int maxDistance , boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
2022-07-06 17:51:26 -05:00
if ( startPos . length != 3 || lookVector . length != 3 ) {
return null ;
}
2023-05-31 23:59:11 -05:00
Vec3 startVec = Vec3 . createVectorHelper ( startPos [ 0 ] , startPos [ 1 ] , startPos [ 2 ] );
Vec3 endVec = startVec . addVector ( lookVector [ 0 ]* maxDistance , lookVector [ 1 ]* maxDistance , lookVector [ 2 ]* maxDistance );
2022-07-06 17:51:26 -05:00
2023-05-31 23:59:11 -05:00
IPos endPos = NpcAPI . Instance (). getIPos ( endVec . xCoord , endVec . yCoord , endVec . zCoord );
if ( ! stopOnBlock && ! stopOnLiquid && ! stopOnCollision ) {
return endPos ;
2022-07-06 17:51:26 -05:00
}
2023-06-01 21:24:59 -05:00
MovingObjectPosition mob = this . rayCast ( startVec , endVec , stopOnBlock , stopOnLiquid , stopOnCollision );
2023-05-31 23:59:11 -05:00
return mob != null ? NpcAPI . Instance (). getIPos ( mob . blockX , mob . blockY , mob . blockZ ) : endPos ;
2022-07-06 17:51:26 -05:00
}
2022-07-07 20:49:03 -05:00
public IPos rayCastPos ( double [] startPos , double [] lookVector , int maxDistance ) {
return rayCastPos ( startPos , lookVector , maxDistance , true , false , false );
}
public IPos rayCastPos ( IPos startPos , IPos lookVector , int maxDistance , boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
2023-04-11 23:26:10 -05:00
return rayCastPos ( new double [] { startPos . getX (), startPos . getY (), startPos . getZ ()}, lookVector . normalizeDouble (), maxDistance , stopOnBlock , stopOnLiquid , stopOnCollision );
2022-07-07 20:49:03 -05:00
}
2022-07-06 17:51:26 -05:00
public IPos rayCastPos ( IPos startPos , IPos lookVector , int maxDistance ) {
2023-04-11 23:26:10 -05:00
return rayCastPos ( new double [] { startPos . getX (), startPos . getY (), startPos . getZ ()}, lookVector . normalizeDouble (), maxDistance , true , false , false );
2022-07-07 20:49:03 -05:00
}
public IBlock rayCastBlock ( double [] startPos , double [] lookVector , int maxDistance , boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
return getBlock ( rayCastPos ( startPos , lookVector , maxDistance , stopOnBlock , stopOnLiquid , stopOnCollision ));
}
public IBlock rayCastBlock ( double [] startPos , double [] lookVector , int maxDistance ) {
return rayCastBlock ( startPos , lookVector , maxDistance , true , false , false );
}
public IBlock rayCastBlock ( IPos startPos , IPos lookVector , int maxDistance , boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
2023-04-11 23:26:10 -05:00
return rayCastBlock ( new double [] { startPos . getX (), startPos . getY (), startPos . getZ ()}, lookVector . normalizeDouble (), maxDistance , stopOnBlock , stopOnLiquid , stopOnCollision );
2022-07-07 20:49:03 -05:00
}
public IBlock rayCastBlock ( IPos startPos , IPos lookVector , int maxDistance ) {
2023-04-11 23:26:10 -05:00
return rayCastBlock ( new double [] { startPos . getX (), startPos . getY (), startPos . getZ ()}, lookVector . normalizeDouble (), maxDistance );
2022-07-06 17:51:26 -05:00
}
2022-05-26 02:10:25 -05:00
public IPos getNearestAir ( IPos pos , int maxHeight ) {
2022-05-24 03:06:16 -05:00
if ( pos == null ) return null ;
2022-05-26 02:10:25 -05:00
IPos currentPos = pos ;
2022-05-24 03:06:16 -05:00
IBlock block = null ; int rep = 0 ;
while ( rep ++ < maxHeight ) {
//check +x
2022-05-26 02:10:25 -05:00
currentPos = currentPos . add ( 1 , 0 , 0 );
block = getBlock ( currentPos );
2022-05-24 03:06:16 -05:00
if ( block == null ) break ;
//check -x
2022-05-26 02:10:25 -05:00
currentPos = currentPos . add ( - 2 , 0 , 0 );
block = getBlock ( currentPos );
2022-05-24 03:06:16 -05:00
if ( block == null ) break ;
//check +z
2022-05-26 02:10:25 -05:00
currentPos = currentPos . add ( 1 , 0 , 1 );
block = getBlock ( currentPos );
2022-05-24 03:06:16 -05:00
if ( block == null ) break ;
//check -z
2022-05-26 02:10:25 -05:00
currentPos = currentPos . add ( 0 , 0 , - 2 );
block = getBlock ( currentPos );
2022-05-24 03:06:16 -05:00
if ( block == null ) break ;
//check up 1
2022-05-26 02:10:25 -05:00
currentPos = currentPos . add ( 0 , 1 , 1 );
block = getBlock ( currentPos );
2022-05-24 03:06:16 -05:00
if ( block == null ) break ;
}
2022-05-26 02:10:25 -05:00
return currentPos ;
2022-05-24 03:06:16 -05:00
}
2022-05-27 15:31:02 -05:00
2022-07-10 23:17:17 -05:00
public IEntity [] rayCastEntities ( double [] startPos , double [] lookVector ,
int maxDistance , double offset , double range ,
boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
2023-06-01 22:02:27 -05:00
return rayCastEntities ( null , startPos , lookVector , maxDistance , offset , range , stopOnBlock , stopOnLiquid , stopOnCollision );
}
public IEntity [] rayCastEntities ( IEntity [] ignoreEntities , double [] startPos , double [] lookVector ,
int maxDistance , double offset , double range ,
boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
if ( ignoreEntities == null ) {
ignoreEntities = new IEntity [ 0 ] ;
}
2023-06-01 21:24:59 -05:00
Vec3 startVec = Vec3 . createVectorHelper ( startPos [ 0 ] , startPos [ 1 ] , startPos [ 2 ] );
Vec3 endVec = startVec . addVector ( lookVector [ 0 ]* maxDistance , lookVector [ 1 ]* maxDistance , lookVector [ 2 ]* maxDistance );
2023-06-01 21:29:29 -05:00
startVec = startVec . addVector ( lookVector [ 0 ]* offset , lookVector [ 1 ]* offset , lookVector [ 2 ]* offset );
2022-07-10 23:17:17 -05:00
2023-06-01 22:02:27 -05:00
LinkedHashSet < IEntity > ignoredEntitiesSet = new LinkedHashSet <> ();
Collections . addAll ( ignoredEntitiesSet , ignoreEntities );
Set < IEntity <?>> entities = this . rayCastEntities ( ignoredEntitiesSet , startVec , endVec , range , stopOnBlock , stopOnLiquid , stopOnCollision );
2023-06-01 21:24:59 -05:00
return entities . toArray ( new IEntity [ 0 ] );
}
2022-07-10 23:17:17 -05:00
2023-06-01 22:02:27 -05:00
public Set < IEntity <?>> rayCastEntities ( LinkedHashSet < IEntity > ignoredEntitiesSet , Vec3 startVec , Vec3 endVec , double range , boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision )
2023-06-01 21:24:59 -05:00
{
LinkedHashSet < IEntity <?>> entities = new LinkedHashSet <> ();
2022-07-10 23:17:17 -05:00
2023-06-01 21:24:59 -05:00
if ( ! Double . isNaN ( startVec . xCoord ) && ! Double . isNaN ( startVec . yCoord ) && ! Double . isNaN ( startVec . zCoord ))
{
if ( ! Double . isNaN ( endVec . xCoord ) && ! Double . isNaN ( endVec . yCoord ) && ! Double . isNaN ( endVec . zCoord ))
{
int endX = MathHelper . floor_double ( endVec . xCoord );
int endY = MathHelper . floor_double ( endVec . yCoord );
int endZ = MathHelper . floor_double ( endVec . zCoord );
int l = MathHelper . floor_double ( startVec . xCoord );
int i1 = MathHelper . floor_double ( startVec . yCoord );
int j1 = MathHelper . floor_double ( startVec . zCoord );
Block block = this . world . getBlock ( l , i1 , j1 );
int k1 = this . world . getBlockMetadata ( l , i1 , j1 );
2023-06-01 21:29:29 -05:00
IEntity <?>[] surrounding = this . getEntitiesNear ( l , i1 , j1 , range );
2023-06-01 22:02:27 -05:00
for ( IEntity <?> entity : surrounding ) {
if ( ! ignoredEntitiesSet . contains ( entity )) {
entities . add ( entity );
}
}
2022-07-10 23:17:17 -05:00
2023-06-01 21:24:59 -05:00
if ( block . canCollideCheck ( k1 , false ))
{
MovingObjectPosition movingobjectposition = block . collisionRayTrace ( this . world , l , i1 , j1 , startVec , endVec );
if ( movingobjectposition != null )
{
return entities ;
}
2022-07-10 23:17:17 -05:00
}
2023-06-01 21:24:59 -05:00
k1 = 200 ;
while ( k1 -- >= 0 )
{
if ( Double . isNaN ( startVec . xCoord ) || Double . isNaN ( startVec . yCoord ) || Double . isNaN ( startVec . zCoord ))
{
2023-06-01 22:02:27 -05:00
return entities ;
2023-06-01 21:24:59 -05:00
}
if ( l == endX && i1 == endY && j1 == endZ )
{
2023-06-01 22:02:27 -05:00
return entities ;
2023-06-01 21:24:59 -05:00
}
boolean flag6 = true ;
boolean flag3 = true ;
boolean flag4 = true ;
double d0 = 999 . 0D ;
double d1 = 999 . 0D ;
double d2 = 999 . 0D ;
if ( endX > l )
{
d0 = ( double ) l + 1 . 0D ;
}
else if ( endX < l )
{
d0 = ( double ) l + 0 . 0D ;
}
else
{
flag6 = false ;
}
if ( endY > i1 )
{
d1 = ( double ) i1 + 1 . 0D ;
}
else if ( endY < i1 )
{
d1 = ( double ) i1 + 0 . 0D ;
}
else
{
flag3 = false ;
}
if ( endZ > j1 )
{
d2 = ( double ) j1 + 1 . 0D ;
}
else if ( endZ < j1 )
{
d2 = ( double ) j1 + 0 . 0D ;
}
else
{
flag4 = false ;
}
double d3 = 999 . 0D ;
double d4 = 999 . 0D ;
double d5 = 999 . 0D ;
double d6 = endVec . xCoord - startVec . xCoord ;
double d7 = endVec . yCoord - startVec . yCoord ;
double d8 = endVec . zCoord - startVec . zCoord ;
if ( flag6 )
{
d3 = ( d0 - startVec . xCoord ) / d6 ;
}
if ( flag3 )
{
d4 = ( d1 - startVec . yCoord ) / d7 ;
}
if ( flag4 )
{
d5 = ( d2 - startVec . zCoord ) / d8 ;
}
byte b0 ;
if ( d3 < d4 && d3 < d5 )
{
if ( endX > l )
{
b0 = 4 ;
}
else
{
b0 = 5 ;
}
startVec . xCoord = d0 ;
startVec . yCoord += d7 * d3 ;
startVec . zCoord += d8 * d3 ;
}
else if ( d4 < d5 )
{
if ( endY > i1 )
{
b0 = 0 ;
}
else
{
b0 = 1 ;
}
startVec . xCoord += d6 * d4 ;
startVec . yCoord = d1 ;
startVec . zCoord += d8 * d4 ;
}
else
{
if ( endZ > j1 )
{
b0 = 2 ;
}
else
{
b0 = 3 ;
}
startVec . xCoord += d6 * d5 ;
startVec . yCoord += d7 * d5 ;
startVec . zCoord = d2 ;
}
Vec3 vec32 = Vec3 . createVectorHelper ( startVec . xCoord , startVec . yCoord , startVec . zCoord );
l = ( int )( vec32 . xCoord = ( double ) MathHelper . floor_double ( startVec . xCoord ));
if ( b0 == 5 )
{
-- l ;
++ vec32 . xCoord ;
}
i1 = ( int )( vec32 . yCoord = ( double ) MathHelper . floor_double ( startVec . yCoord ));
if ( b0 == 1 )
{
-- i1 ;
++ vec32 . yCoord ;
}
j1 = ( int )( vec32 . zCoord = ( double ) MathHelper . floor_double ( startVec . zCoord ));
if ( b0 == 3 )
{
-- j1 ;
++ vec32 . zCoord ;
}
Block block1 = this . world . getBlock ( l , i1 , j1 );
int l1 = this . world . getBlockMetadata ( l , i1 , j1 );
2023-06-01 21:29:29 -05:00
IEntity <?>[] surroundingEntities = this . getEntitiesNear ( l , i1 , j1 , range );
2023-06-01 22:02:27 -05:00
for ( IEntity <?> entity : surroundingEntities ) {
if ( ! ignoredEntitiesSet . contains ( entity )) {
entities . add ( entity );
}
}
2023-06-01 21:24:59 -05:00
MovingObjectPosition movingobjectposition1 = block1 . collisionRayTrace ( this . world , l , i1 , j1 , startVec , endVec );
if ( movingobjectposition1 != null )
{
if ( block1 . canCollideCheck ( l1 , false ) && stopOnBlock ||
block1 . getMaterial (). isLiquid () && stopOnLiquid ||
! ( block1 instanceof BlockAir ) && block1 . getCollisionBoundingBoxFromPool ( this . world , l , i1 , j1 ) == null && ! stopOnCollision )
{
return entities ;
}
}
}
return entities ;
}
else
{
return entities ;
2022-07-10 23:17:17 -05:00
}
}
2023-06-01 21:24:59 -05:00
else
{
return entities ;
}
2022-07-10 23:17:17 -05:00
}
public IEntity [] rayCastEntities ( IPos startPos , IPos lookVector ,
int maxDistance , double offset , double range ,
boolean stopOnBlock , boolean stopOnLiquid , boolean stopOnCollision ) {
2023-04-11 23:26:10 -05:00
return rayCastEntities ( new double [] { startPos . getX (), startPos . getY (), startPos . getZ ()}, lookVector . normalizeDouble (), maxDistance , offset , range , stopOnBlock , stopOnLiquid , stopOnCollision );
2022-07-10 23:17:17 -05:00
}
public IEntity [] rayCastEntities ( double [] startPos , double [] lookVector ,
int maxDistance , double offset , double range ) {
return rayCastEntities ( startPos , lookVector , maxDistance , offset , range , true , false , true );
}
public IEntity [] rayCastEntities ( IPos startPos , IPos lookVector ,
int maxDistance , double offset , double range ) {
2023-04-11 23:26:10 -05:00
return rayCastEntities ( new double [] { startPos . getX (), startPos . getY (), startPos . getZ ()}, lookVector . normalizeDouble (), maxDistance , offset , range , true , false , true );
2022-07-10 23:17:17 -05:00
}
2022-11-06 01:59:34 -05:00
@Deprecated
2018-09-13 12:03:28 -04:00
/**
2022-11-06 01:59:34 -05:00
* Deprecated. Use NpcAPI.Instance().getPlayer(name) instead.
2018-09-13 12:03:28 -04:00
*/
2022-05-11 22:08:31 -05:00
public IPlayer getPlayer ( String name ){
2018-09-13 12:03:28 -04:00
EntityPlayer player = world . getPlayerEntityByName ( name );
if ( player == null )
return null ;
2022-05-11 22:08:31 -05:00
return ( IPlayer ) NpcAPI . Instance (). getIEntity ( player );
2018-09-13 12:03:28 -04:00
}
2022-05-03 23:09:21 -05:00
2022-05-11 22:08:31 -05:00
public IPlayer getPlayerByUUID ( String uuid ){
return ( IPlayer ) NpcAPI . Instance (). getIEntity ( world . func_152378_a ( UUID . fromString ( uuid )));
2018-09-13 12:03:28 -04:00
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param time The world time to be set
*/
public void setTime ( long time ){
world . setWorldTime ( time );
}
2022-05-03 23:09:21 -05:00
2018-09-13 12:03:28 -04:00
/**
* @return Whether or not its daytime
*/
public boolean isDay (){
return world . getWorldTime () % 24000 < 12000 ;
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @return Whether or not its currently raining
*/
public boolean isRaining (){
return world . getWorldInfo (). isRaining ();
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param bo Set if it's raining
*/
public void setRaining ( boolean bo ){
world . getWorldInfo (). setRaining ( bo );
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param x The x position
* @param y The y position
* @param z The z position
*/
public void thunderStrike ( double x , double y , double z ){
world . addWeatherEffect ( new EntityLightningBolt ( world , x , y , z ));
}
2022-11-05 20:19:14 -05:00
public void thunderStrike ( IPos pos ){
this . thunderStrike ( pos . getX (), pos . getY (), pos . getZ ());
}
2018-09-13 12:03:28 -04:00
/**
* Sends a packet from the server to the client everytime its called. Probably should not use this too much.
2024-01-18 16:05:38 -05:00
* @param particle Particle name. Particle name list: http://minecraft.wiki/w/Particles
2018-09-13 12:03:28 -04:00
* @param x The x position
* @param y The y position
* @param z The z position
* @param dx Usually used for the x motion
* @param dy Usually used for the y motion
* @param dz Usually used for the z motion
* @param speed Speed of the particles, usually between 0 and 1
* @param count Particle count
*/
public void spawnParticle ( String particle , double x , double y , double z , double dx , double dy , double dz , double speed , int count ){
world . func_147487_a ( particle , x , y , z , count , dx , dy , dz , speed );
}
2022-11-05 20:19:14 -05:00
public void spawnParticle ( String particle , IPos pos , double dx , double dy , double dz , double speed , int count ){
this . spawnParticle ( particle , pos . getX (), pos . getY (), pos . getZ (), dx , dy , dz , speed , count );
}
2018-09-13 12:03:28 -04:00
/**
* @param id The items name
* @param damage The damage value
* @param size The number of items in the item
* @return Returns the item
*/
2022-05-11 01:10:31 -05:00
public IItemStack createItem ( String id , int damage , int size ){
2022-05-11 17:12:48 -05:00
return NpcAPI . Instance (). createItem ( id , damage , size );
2018-09-13 12:03:28 -04:00
}
2021-09-08 13:41:57 -05:00
/**
2022-05-07 01:40:41 -05:00
* @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/bubble.png"
* @return Returns ScriptParticle object
2021-09-08 13:41:57 -05:00
*/
2022-05-07 03:46:37 -05:00
@Deprecated
2022-05-11 22:08:31 -05:00
public IParticle createEntityParticle ( String directory ){
return NpcAPI . Instance (). createEntityParticle ( directory );
2021-09-08 13:41:57 -05:00
}
2022-05-07 01:40:41 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param key Get temp data for this key
* @return Returns the stored temp data
*/
public Object getTempData ( String key ){
return tempData . get ( key );
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* Tempdata gets cleared when the server restarts. All worlds share the same temp data.
* @param key The key for the data stored
* @param value The data stored
*/
public void setTempData ( String key , Object value ){
tempData . put ( key , value );
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param key The key thats going to be tested against the temp data
* @return Whether or not temp data containes the key
*/
public boolean hasTempData ( String key ){
return tempData . containsKey ( key );
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param key The key for the temp data to be removed
*/
public void removeTempData ( String key ){
tempData . remove ( key );
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* Removes all tempdata
*/
public void clearTempData (){
tempData . clear ();
}
2022-11-05 20:19:14 -05:00
2022-12-27 16:46:59 -06:00
public String [] getTempDataKeys () {
return tempData . keySet (). toArray ( new String [ 0 ] );
}
2018-09-13 12:03:28 -04:00
/**
* @param key The key of the data to be returned
* @return Returns the stored data
*/
public Object getStoredData ( String key ){
NBTTagCompound compound = ScriptController . Instance . compound ;
if ( ! compound . hasKey ( key ))
return null ;
NBTBase base = compound . getTag ( key );
if ( base instanceof NBTPrimitive )
return (( NBTPrimitive ) base ). func_150286_g ();
return (( NBTTagString ) base ). func_150285_a_ ();
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved
* @param key The key for the data stored
* @param value The data stored. This data can be either a Number or a String. Other data is not stored
*/
public void setStoredData ( String key , Object value ){
NBTTagCompound compound = ScriptController . Instance . compound ;
if ( value instanceof Number )
compound . setDouble ( key , (( Number ) value ). doubleValue ());
else if ( value instanceof String )
compound . setString ( key , ( String ) value );
ScriptController . Instance . shouldSave = true ;
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param key The key of the data to be checked
* @return Returns whether or not the stored data contains the key
*/
public boolean hasStoredData ( String key ){
return ScriptController . Instance . compound . hasKey ( key );
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* @param key The key of the data to be removed
*/
public void removeStoredData ( String key ){
ScriptController . Instance . compound . removeTag ( key );
ScriptController . Instance . shouldSave = true ;
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
/**
* Remove all stored data
*/
public void clearStoredData (){
ScriptController . Instance . compound = new NBTTagCompound ();
ScriptController . Instance . shouldSave = true ;
}
2022-11-05 20:19:14 -05:00
2022-12-27 16:46:59 -06:00
public String [] getStoredDataKeys () {
NBTTagCompound compound = ScriptController . Instance . compound ;
if ( compound != null ) {
2023-11-07 01:38:24 -05:00
Set keySet = compound . func_150296_c ();
List < String > list = new ArrayList <> ();
for ( Object o : keySet ){
list . add (( String ) o );
}
String [] array = list . toArray ( new String [ list . size () ] );
return array ;
2022-12-27 16:46:59 -06:00
}
return new String [ 0 ] ;
}
2018-09-13 12:03:28 -04:00
/**
* @param x Position x
* @param y Position y
* @param z Position z
* @param range Range of the explosion
* @param fire Whether or not the explosion does fire damage
* @param grief Whether or not the explosion does damage to blocks
*/
public void explode ( double x , double y , double z , float range , boolean fire , boolean grief ){
world . newExplosion ( null , x , y , z , range , fire , grief );
}
2022-07-13 19:27:27 -05:00
2022-11-05 20:19:14 -05:00
public void explode ( IPos pos , float range , boolean fire , boolean grief ){
this . explode ( pos . getX (), pos . getY (), pos . getZ (), range , fire , grief );
}
2022-07-13 19:27:27 -05:00
@Deprecated
2022-05-11 22:08:31 -05:00
public IPlayer [] getAllServerPlayers (){
2018-09-13 12:03:28 -04:00
List < EntityPlayer > list = MinecraftServer . getServer (). getConfigurationManager (). playerEntityList ;
2022-05-11 22:08:31 -05:00
IPlayer [] arr = new IPlayer [ list . size () ] ;
2018-09-13 12:03:28 -04:00
for ( int i = 0 ; i < list . size (); i ++ ){
2022-05-11 22:08:31 -05:00
arr [ i ] = ( IPlayer ) NpcAPI . Instance (). getIEntity ( list . get ( i ));
2018-09-13 12:03:28 -04:00
}
2022-11-05 20:19:14 -05:00
2018-09-13 12:03:28 -04:00
return arr ;
}
2022-05-27 15:54:12 -05:00
2022-07-13 19:27:27 -05:00
@Deprecated
2022-05-27 15:54:12 -05:00
public String [] getPlayerNames () {
IPlayer [] players = getAllServerPlayers ();
String [] names = new String [ players . length ] ;
for ( int i = 0 ; i < names . length ; ++ i ) names [ i ] = players [ i ] . getDisplayName ();
return names ;
}
2018-09-13 12:03:28 -04:00
/**
* @since 1.7.10c
* @param x Position x
* @param z Position z
* @return Returns the name of the biome
*/
public String getBiomeName ( int x , int z ){
return world . getBiomeGenForCoords ( x , z ). biomeName ;
}
2022-11-05 20:19:14 -05:00
public String getBiomeName ( IPos pos ){
return this . getBiomeName ( pos . getX (), pos . getZ ());
}
2018-09-13 12:03:28 -04:00
/**
* Lets you spawn a server side cloned entity
* @param x The x position the clone will be spawned at
* @param y The y position the clone will be spawned at
* @param z The z position the clone will be spawned at
* @param tab The tab in which the clone is
* @param name Name of the cloned entity
* @return Returns the entity which was spawned
*/
2022-07-06 01:29:43 -07:00
public IEntity spawnClone ( int x , int y , int z , int tab , String name , boolean ignoreProtection ){
2018-09-13 12:03:28 -04:00
NBTTagCompound compound = ServerCloneController . Instance . getCloneData ( null , name , tab );
if ( compound == null )
return null ;
2022-07-06 01:29:43 -07:00
Entity entity ;
if ( ! ignoreProtection ) {
entity = NoppesUtilServer . spawnCloneWithProtection ( compound , x , y , z , world );
} else {
entity = NoppesUtilServer . spawnClone ( compound , x , y , z , world );
}
return entity == null ? null : NpcAPI . Instance (). getIEntity ( entity );
}
2022-11-05 20:19:14 -05:00
public IEntity spawnClone ( IPos pos , int tab , String name , boolean ignoreProtection ) {
return this . spawnClone ( pos . getX (), pos . getY (), pos . getZ (), tab , name , ignoreProtection );
}
2022-07-06 01:29:43 -07:00
public IEntity spawnClone ( int x , int y , int z , int tab , String name ) {
return this . spawnClone ( x , y , z , tab , name , true );
2018-09-13 12:03:28 -04:00
}
2022-11-05 20:19:14 -05:00
public IEntity spawnClone ( IPos pos , int tab , String name ) {
return this . spawnClone ( pos . getX (), pos . getY (), pos . getZ (), tab , name );
}
2022-11-23 23:59:01 -06:00
public IScoreboard getScoreboard (){
2018-09-13 12:03:28 -04:00
return new ScriptScoreboard ();
}
2021-10-12 03:23:56 -05:00
2018-09-13 12:03:28 -04:00
/**
* @since 1.7.10c
* Expert use only
* @return Returns minecraft world object
*/
2021-10-19 16:59:09 -05:00
public WorldServer getMCWorld (){
return this . world ;
2018-09-13 12:03:28 -04:00
}
2021-11-22 01:10:27 -06:00
public int getDimensionID (){
return world . provider . dimensionId ;
}
2022-11-06 15:08:58 -06:00
public String toString () {
return "DIM" + this . getDimensionID ();
}
2024-03-28 01:34:12 -04:00
@Override
public void broadcast ( String message ){
world . func_73046_m (). getConfigurationManager (). sendChatMsg ( new ChatComponentText ( message ));
}
2018-09-13 12:03:28 -04:00
}