idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
39,300
public static int getEntityRotation ( Entity entity , boolean sixWays ) { if ( entity == null ) return 6 ; float pitch = entity . rotationPitch ; if ( sixWays && pitch < - 45 ) return 4 ; if ( sixWays && pitch > 45 ) return 5 ; return ( MathHelper . floor ( entity . rotationYaw * 4.0F / 360.0F + 0.5D ) + 2 ) & 3 ; }
Gets the entity rotation based on where it s currently facing .
39,301
@ SuppressWarnings ( "unchecked" ) public static List < EntityPlayerMP > getPlayersWatchingChunk ( WorldServer world , int x , int z ) { if ( playersWatchingChunk == null ) return new ArrayList < > ( ) ; try { PlayerChunkMapEntry entry = world . getPlayerChunkMap ( ) . getEntry ( x , z ) ; if ( entry == null ) return Lists . newArrayList ( ) ; return ( List < EntityPlayerMP > ) playersWatchingChunk . get ( entry ) ; } catch ( ReflectiveOperationException e ) { MalisisCore . log . info ( "Failed to get players watching chunk :" , e ) ; return new ArrayList < > ( ) ; } }
Gets the list of players currently watching the chunk at the coordinate .
39,302
public static Point getRenderViewOffset ( float partialTick ) { Entity entity = Minecraft . getMinecraft ( ) . getRenderViewEntity ( ) ; if ( partialTick == 0 ) return new Point ( entity . posX , entity . posY , entity . posZ ) ; double x = entity . lastTickPosX + ( entity . posX - entity . lastTickPosX ) * partialTick ; double y = entity . lastTickPosY + ( entity . posY - entity . lastTickPosY ) * partialTick ; double z = entity . lastTickPosZ + ( entity . posZ - entity . lastTickPosZ ) * partialTick ; return new Point ( x , y , z ) ; }
Gets the render view offset for the current view entity .
39,303
public EnumActionResult onItemUse ( EntityPlayer player , World world , BlockPos pos , EnumHand hand , EnumFacing side , float hitX , float hitY , float hitZ ) { ItemStack itemStack = player . getHeldItem ( hand ) ; if ( itemStack . isEmpty ( ) ) return EnumActionResult . FAIL ; if ( ! player . canPlayerEdit ( pos . offset ( side ) , side , itemStack ) ) return EnumActionResult . FAIL ; IBlockState placedState = checkMerge ( itemStack , player , world , pos , side , hitX , hitY , hitZ ) ; BlockPos p = pos ; if ( placedState == null ) { p = pos . offset ( side ) ; float x = hitX - side . getFrontOffsetX ( ) ; float y = hitY - side . getFrontOffsetY ( ) ; float z = hitZ - side . getFrontOffsetZ ( ) ; placedState = checkMerge ( itemStack , player , world , p , side , x , y , z ) ; } if ( placedState == null ) return super . onItemUse ( player , world , pos , hand , side , hitX , hitY , hitZ ) ; Block block = placedState . getBlock ( ) ; if ( world . checkNoEntityCollision ( placedState . getCollisionBoundingBox ( world , p ) ) && world . setBlockState ( p , placedState , 3 ) ) { SoundType soundType = block . getSoundType ( placedState , world , pos , player ) ; world . playSound ( player , pos , soundType . getPlaceSound ( ) , SoundCategory . BLOCKS , ( soundType . getVolume ( ) + 1.0F ) / 2.0F , soundType . getPitch ( ) * 0.8F ) ; itemStack . shrink ( 1 ) ; } return EnumActionResult . SUCCESS ; }
onItemUse needs to be overriden to be able to handle merged blocks and components .
39,304
private IBlockState checkMerge ( ItemStack itemStack , EntityPlayer player , World world , BlockPos pos , EnumFacing side , float hitX , float hitY , float hitZ ) { IBlockState state = world . getBlockState ( pos ) ; IMergedBlock mergedBlock = getMerged ( state ) ; if ( mergedBlock == null || ! mergedBlock . canMerge ( itemStack , player , world , pos , side ) ) return null ; return mergedBlock . mergeBlock ( world , pos , state , itemStack , player , side , hitX , hitY , hitZ ) ; }
Checks whether the block can be merged with the one already in the world .
39,305
protected Scale from ( float x , float y , float z ) { fromX = x ; fromY = y ; fromZ = z ; return this ; }
Sets the starting scale .
39,306
protected Scale to ( float x , float y , float z ) { toX = x ; toY = y ; toZ = z ; return this ; }
Sets the target scale .
39,307
public Scale offset ( float x , float y , float z ) { offsetX = x ; offsetY = y ; offsetZ = z ; return this ; }
Sets the offset for the scaling .
39,308
protected void doTransform ( ITransformable . Scale transformable , float comp ) { float fromX = reversed ? this . toX : this . fromX ; float toX = reversed ? this . fromX : this . toX ; float fromY = reversed ? this . toY : this . fromY ; float toY = reversed ? this . fromY : this . toY ; float fromZ = reversed ? this . toZ : this . fromZ ; float toZ = reversed ? this . fromZ : this . toZ ; transformable . scale ( fromX + ( toX - fromX ) * comp , fromY + ( toY - fromY ) * comp , fromZ + ( toZ - fromZ ) * comp , offsetX , offsetY , offsetZ ) ; }
Calculate the transformation .
39,309
public void onDataSave ( ChunkDataEvent . Save event ) { NBTTagCompound nbt = event . getData ( ) ; for ( HandlerInfo < ? > handlerInfo : handlerInfos . values ( ) ) { ChunkData < ? > chunkData = chunkData ( handlerInfo . identifier , event . getWorld ( ) , event . getChunk ( ) ) ; if ( chunkData != null && chunkData . hasData ( ) ) { ByteBuf buf = Unpooled . buffer ( ) ; chunkData . toBytes ( buf ) ; nbt . setByteArray ( handlerInfo . identifier , buf . capacity ( buf . writerIndex ( ) ) . array ( ) ) ; } if ( event . getChunk ( ) . unloadQueued ) datas . get ( ) . remove ( handlerInfo . identifier , event . getChunk ( ) ) ; } }
On data save .
39,310
public static < T > void registerBlockData ( String identifier , Function < ByteBuf , T > fromBytes , Function < T , ByteBuf > toBytes ) { instance . handlerInfos . put ( identifier , new HandlerInfo < > ( identifier , fromBytes , toBytes ) ) ; }
Registers a custom block data with the specified identifier .
39,311
static void setBlockData ( int chunkX , int chunkZ , String identifier , ByteBuf data ) { HandlerInfo < ? > handlerInfo = instance . handlerInfos . get ( identifier ) ; if ( handlerInfo == null ) return ; Chunk chunk = Utils . getClientWorld ( ) . getChunkFromChunkCoords ( chunkX , chunkZ ) ; ChunkData < ? > chunkData = new ChunkData < > ( handlerInfo ) . fromBytes ( data ) ; datas . get ( ) . put ( handlerInfo . identifier , chunk , chunkData ) ; }
Called on the client when receiving the data from the server either because client started to watch the chunk or server manually sent the data .
39,312
public void setup ( float partialTick ) { this . partialTick = partialTick ; currentTexture = null ; bindDefaultTexture ( ) ; GlStateManager . pushMatrix ( ) ; if ( ignoreScale ) { GlStateManager . scale ( 1F / scaleFactor , 1F / scaleFactor , 1 ) ; } setupGl ( ) ; startDrawing ( ) ; }
Sets up the rendering and start drawing .
39,313
public void enableBlending ( ) { GlStateManager . enableBlend ( ) ; GlStateManager . tryBlendFuncSeparate ( GL11 . GL_SRC_ALPHA , GL11 . GL_ONE_MINUS_SRC_ALPHA , GL11 . GL_ONE , GL11 . GL_ZERO ) ; GlStateManager . alphaFunc ( GL11 . GL_GREATER , 0.0F ) ; GlStateManager . shadeModel ( GL11 . GL_SMOOTH ) ; GlStateManager . enableColorMaterial ( ) ; }
Enables the blending for the rendering .
39,314
public void bindTexture ( GuiTexture texture ) { if ( texture == currentTexture ) return ; next ( ) ; Minecraft . getMinecraft ( ) . getTextureManager ( ) . bindTexture ( texture . getResourceLocation ( ) ) ; currentTexture = texture ; }
Bind a new texture for rendering .
39,315
public void drawItemStack ( ItemStack itemStack , int x , int y ) { drawItemStack ( itemStack , x , y , null , null , true ) ; }
Draws an itemStack to the GUI at the specified coordinates .
39,316
public void drawItemStack ( ItemStack itemStack , int x , int y , Style format ) { drawItemStack ( itemStack , x , y , null , format , true ) ; }
Draws an itemStack to the GUI at the specified coordinates with a custom format for the label .
39,317
public void drawItemStack ( ItemStack itemStack , int x , int y , String label ) { drawItemStack ( itemStack , x , y , label , null , true ) ; }
Draws an itemStack to the GUI at the specified coordinates with a custom label .
39,318
public boolean renderPickedItemStack ( ItemStack itemStack ) { if ( itemStack == null || itemStack == ItemStack . EMPTY ) return false ; int size = itemStack . getCount ( ) ; String label = null ; if ( size == 0 ) { itemStack . setCount ( size != 0 ? size : 1 ) ; label = TextFormatting . YELLOW + "0" ; } itemRenderer . zLevel = 100 ; drawItemStack ( itemStack , MalisisGui . MOUSE_POSITION . x ( ) - 8 , MalisisGui . MOUSE_POSITION . y ( ) - 8 , label , null , false ) ; itemRenderer . zLevel = 0 ; return true ; }
Render the picked up itemStack at the cursor position .
39,319
public void startClipping ( ClipArea area ) { if ( area . noClip ( ) ) return ; GL11 . glPushAttrib ( GL11 . GL_SCISSOR_BIT ) ; GL11 . glEnable ( GL11 . GL_SCISSOR_TEST ) ; int f = ignoreScale ? 1 : scaleFactor ; int x = area . x * f ; int y = Minecraft . getMinecraft ( ) . displayHeight - ( area . y + area . height ( ) ) * f ; int w = area . width ( ) * f ; int h = area . height ( ) * f ; ; GL11 . glScissor ( x , y , w , h ) ; }
Starts clipping an area to prevent drawing outside of it .
39,320
public void endClipping ( ClipArea area ) { if ( area . noClip ( ) ) return ; next ( ) ; GL11 . glDisable ( GL11 . GL_SCISSOR_TEST ) ; GL11 . glPopAttrib ( ) ; }
Ends the clipping .
39,321
public void render ( Block block , MalisisRenderer < ? extends TileEntity > renderer ) { if ( renderer . getRenderType ( ) == RenderType . BLOCK && animatedShapes . size ( ) != 0 ) onRender ( renderer . getWorldAccess ( ) , renderer . getPos ( ) , renderer . getBlockState ( ) ) ; model . resetState ( ) ; if ( renderer . getRenderType ( ) == RenderType . BLOCK ) model . rotate ( DirectionalComponent . getDirection ( renderer . getBlockState ( ) ) ) ; staticShapes . forEach ( name -> model . render ( renderer , name , rp ) ) ; if ( renderer . getRenderType ( ) == RenderType . ITEM ) animatedShapes . forEach ( name -> model . render ( renderer , name , rp ) ) ; }
Only called for BLOCK and ITEM render type
39,322
public boolean process ( ) { if ( toProcess . size ( ) <= 0 ) return false ; BlockPos pos = toProcess . removeFirst ( ) ; process ( pos ) ; if ( onProcess != null ) onProcess . accept ( world , pos ) ; return true ; }
Processes a single position .
39,323
protected boolean shouldProcessed ( BlockPos pos ) { if ( toProcess . contains ( pos ) || processed . contains ( pos ) ) return false ; return shouldProcess == null || shouldProcess . test ( world , pos ) ; }
Checks whether the position should be processed .
39,324
protected void process ( BlockPos pos ) { for ( EnumFacing dir : searchDirs ) { BlockPos newPos = pos . offset ( dir ) ; if ( ! processed . contains ( newPos ) && shouldProcessed ( newPos ) ) toProcess . add ( newPos ) ; } processed . add ( pos ) ; if ( processed . size ( ) >= countLimit ) toProcess . clear ( ) ; }
Processes the position .
39,325
@ SideOnly ( Side . CLIENT ) public static World getClientWorld ( ) { return Minecraft . getMinecraft ( ) != null ? Minecraft . getMinecraft ( ) . world : null ; }
Gets the client world .
39,326
@ SideOnly ( Side . CLIENT ) public static EntityPlayer getClientPlayer ( ) { return Minecraft . getMinecraft ( ) != null ? Minecraft . getMinecraft ( ) . player : null ; }
Gets the client player .
39,327
public boolean canMerge ( ItemStack itemStack , EntityPlayer player , World world , BlockPos pos , EnumFacing side ) { IBlockState state = world . getBlockState ( pos ) ; if ( isCorner ( state ) ) return false ; return EnumFacingUtils . getRealSide ( state , side ) != EnumFacing . NORTH ; }
Checks whether the block can be merged into a corner .
39,328
public AxisAlignedBB [ ] getBoundingBoxes ( Block block , IBlockAccess world , BlockPos pos , IBlockState state , BoundingBoxType type ) { boolean corner = isCorner ( state ) ; if ( type == BoundingBoxType . SELECTION && corner ) return AABBUtils . identities ( ) ; AxisAlignedBB aabb = new AxisAlignedBB ( 0 , 0 , 0 , 1 , 1 , 3 / 16F ) ; if ( world == null ) aabb = AABBUtils . rotate ( aabb . offset ( 0 , 0 , 0.5F ) , - 1 ) ; if ( ! corner ) return new AxisAlignedBB [ ] { aabb } ; return new AxisAlignedBB [ ] { aabb , AABBUtils . rotate ( aabb , - 1 ) } ; }
Gets the bounding boxes for the block .
39,329
public void load ( Configuration config ) { String comment = "" ; for ( String c : comments ) { if ( MalisisCore . isClient ( ) ) comment += I18n . format ( c ) + " " ; else comment += c + " " ; } property = config . get ( category , key , writeValue ( defaultValue ) , comment , type ) ; value = readValue ( property . getString ( ) ) ; if ( value == null ) throw new NullPointerException ( "readPropertyValue should not return null!" ) ; }
Loads the configuration .
39,330
private int getFieldIndexes ( ISyncHandler < ? , ? extends ISyncableData > handler , String ... syncNames ) { int indexes = 0 ; for ( String str : syncNames ) { ObjectData od = handler . getObjectData ( str ) ; if ( od != null ) indexes |= 1 << od . getIndex ( ) ; } return indexes ; }
Gets the indexes of the sync fields into a single integer .
39,331
private Map < String , Object > getFieldValues ( Object caller , ISyncHandler < ? , ? extends ISyncableData > handler , String ... syncNames ) { Map < String , Object > values = new LinkedHashMap < > ( ) ; for ( String str : syncNames ) { ObjectData od = handler . getObjectData ( str ) ; if ( od != null ) values . put ( str , od . get ( caller ) ) ; } return values ; }
Gets the field values for the specified names .
39,332
private < T , S extends ISyncableData > void doSync ( T caller , String ... syncNames ) { @ SuppressWarnings ( "unchecked" ) ISyncHandler < T , S > handler = ( ISyncHandler < T , S > ) getHandler ( caller ) ; if ( handler == null ) return ; S data = handler . getSyncData ( caller ) ; int indexes = getFieldIndexes ( handler , syncNames ) ; Map < String , Object > values = getFieldValues ( caller , handler , syncNames ) ; SyncerMessage . Packet < T , S > packet = new Packet < > ( getHandlerId ( caller . getClass ( ) ) , data , indexes , values ) ; handler . send ( caller , packet ) ; }
Synchronizes the specified fields names and sends the corresponding packet .
39,333
public < T > void updateValues ( T receiver , ISyncHandler < T , ? extends ISyncableData > handler , Map < String , Object > values ) { if ( receiver == null || handler == null ) return ; for ( Entry < String , Object > entry : values . entrySet ( ) ) { ObjectData od = handler . getObjectData ( entry . getKey ( ) ) ; if ( od != null ) od . set ( receiver , entry . getValue ( ) ) ; } }
Update the fields values for the receiver object .
39,334
@ Inject ( method = "loadTextureAtlas" , at = @ At ( "RETURN" ) , locals = LocalCapture . CAPTURE_FAILSOFT ) private void onLoadTextureAtlas ( IResourceManager resourceManager , CallbackInfo ci , int i , Stitcher stitcher , int j , int k , ProgressManager . ProgressBar bar ) { Icon . BLOCK_TEXTURE_WIDTH = stitcher . getCurrentWidth ( ) ; Icon . BLOCK_TEXTURE_HEIGHT = stitcher . getCurrentHeight ( ) ; }
capture atlas size
39,335
protected void updateText ( ) { this . text . setLength ( 0 ) ; this . text . append ( password . toString ( ) . replaceAll ( "(?s)." , String . valueOf ( passwordChar ) ) ) ; guiText . setText ( text . toString ( ) ) ; }
Updates the text from the password value
39,336
public void addText ( String text ) { if ( selectingText ) deleteSelectedText ( ) ; final StringBuilder oldText = this . password ; final String oldValue = oldText . toString ( ) ; String newValue = oldText . insert ( this . cursor . index , text ) . toString ( ) ; if ( this . filterFunction != null ) newValue = this . filterFunction . apply ( newValue ) ; if ( ! fireEvent ( new ComponentEvent . ValueChange < > ( this , oldValue , newValue ) ) ) return ; this . password = new StringBuilder ( newValue ) ; this . updateText ( ) ; this . cursor . jumpBy ( text . length ( ) ) ; }
Adds the text .
39,337
public void deleteSelectedText ( ) { if ( ! selectingText ) return ; int start = Math . min ( selectionCursor . index , cursor . index ) ; int end = Math . max ( selectionCursor . index , cursor . index ) ; password . delete ( start , end ) ; updateText ( ) ; selectingText = false ; cursor . jumpTo ( start ) ; }
Delete selected text .
39,338
protected boolean handleCtrlKeyDown ( int keyCode ) { return GuiScreen . isCtrlKeyDown ( ) && ! ( keyCode == Keyboard . KEY_C || keyCode == Keyboard . KEY_X ) && super . handleCtrlKeyDown ( keyCode ) ; }
Handle ctrl key down .
39,339
public void setUVs ( float u , float v , float U , float V ) { minU = u ; minV = v ; maxU = U ; maxV = V ; }
Sets the u vs .
39,340
public String getSelectedText ( ) { if ( ! selectingText ) return "" ; int start = Math . min ( selectionCursor . index , cursor . index ) ; int end = Math . max ( selectionCursor . index , cursor . index ) ; return this . text . substring ( start , end ) ; }
Gets the currently selected text .
39,341
public UITextField setColors ( int bgColor , int cursorColor , int selectColor ) { setColor ( bgColor ) ; this . cursorColor = cursorColor ; this . selectColor = selectColor ; return this ; }
Sets the options .
39,342
public void setFocused ( boolean focused ) { if ( ! isEnabled ( ) || ! isVisible ( ) ) return ; if ( ! this . focused ) selectAllOnRelease = true ; super . setFocused ( focused ) ; }
Sets the focused .
39,343
public void setFilter ( Function < String , String > filterFunction ) { this . filterFunction = filterFunction ; this . text = new StringBuilder ( this . filterFunction . apply ( this . text . toString ( ) ) ) ; }
Sets the function that applies to all incoming text . Immediately applies filter to current text .
39,344
public void addText ( String str ) { if ( selectingText ) deleteSelectedText ( ) ; final StringBuilder oldText = this . text ; final String oldValue = this . text . toString ( ) ; String newValue = oldText . insert ( this . cursor . index , str ) . toString ( ) ; if ( this . filterFunction != null ) newValue = this . filterFunction . apply ( newValue ) ; if ( ! fireEvent ( new ComponentEvent . ValueChange < > ( this , oldValue , newValue ) ) ) return ; this . text = new StringBuilder ( newValue ) ; guiText . setText ( newValue ) ; cursor . jumpBy ( str . length ( ) ) ; }
Adds text at current cursor position . If some text is selected it s deleted first .
39,345
public void deleteSelectedText ( ) { if ( ! selectingText ) return ; int start = Math . min ( selectionCursor . index , cursor . index ) ; int end = Math . max ( selectionCursor . index , cursor . index ) ; String oldValue = this . text . toString ( ) ; String newValue = new StringBuilder ( oldValue ) . delete ( start , end ) . toString ( ) ; if ( ! fireEvent ( new ComponentEvent . ValueChange < > ( this , oldValue , newValue ) ) ) return ; this . text = new StringBuilder ( newValue ) ; guiText . setText ( newValue ) ; selectingText = false ; cursor . jumpTo ( start ) ; }
Deletes the text currently selected .
39,346
public void deleteWord ( boolean backwards ) { if ( ! selectingText ) { selectingText = true ; selectionCursor . from ( cursor ) ; cursor . jumpToNextSpace ( backwards ) ; } deleteSelectedText ( ) ; }
Deletes the text from current cursor position to the next space .
39,347
public void selectWord ( int position ) { if ( text . length ( ) == 0 ) return ; selectingText = true ; selectionCursor . jumpTo ( position ) ; selectionCursor . jumpToNextSpace ( true ) ; if ( Character . isWhitespace ( text . charAt ( selectionCursor . index ) ) ) selectionCursor . shiftRight ( ) ; cursor . jumpTo ( position ) ; cursor . jumpToNextSpace ( false ) ; }
Select word .
39,348
public T selected ( ) { return selectedIndex < 0 || selectedIndex >= options ( ) . size ( ) ? null : options ( ) . get ( selectedIndex ) ; }
Gets the currently selected option .
39,349
public T select ( T option ) { int index = options ( ) . indexOf ( option ) ; if ( index == - 1 || index == selectedIndex ) return selected ( ) ; if ( fireEvent ( new SelectEvent < > ( this , option ) ) ) setSelected ( option ) ; return selected ( ) ; }
Selects the option .
39,350
public static IntSupplier leftOf ( ISized owner , IPositioned other , int spacing ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . x ( ) - owner . size ( ) . width ( ) - spacing ; } ; }
Positions the owner to the left of the other .
39,351
public static < T extends IPositioned & ISized > IntSupplier rightOf ( T other , int spacing ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . x ( ) + other . size ( ) . width ( ) + spacing ; } ; }
Positions the owner to the right of the other .
39,352
public static IntSupplier above ( ISized owner , IPositioned other , int spacing ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . y ( ) - owner . size ( ) . height ( ) - spacing ; } ; }
Positions the owner above the other .
39,353
public static < T extends IPositioned & ISized > IntSupplier below ( T other , int spacing ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . y ( ) + other . size ( ) . height ( ) + spacing ; } ; }
Positions the owner below the other .
39,354
public static IntSupplier leftAlignedTo ( IPositioned other , int offset ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . x ( ) + offset ; } ; }
Left aligns the owner to the other .
39,355
public static < T extends IPositioned & ISized > IntSupplier centeredTo ( ISized owner , T other , int offset ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . x ( ) + ( other . size ( ) . width ( ) - owner . size ( ) . width ( ) ) / 2 + offset ; } ; }
Centers the owner to the other .
39,356
public static IntSupplier topAlignedTo ( IPositioned other , int offset ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . y ( ) + offset ; } ; }
Top aligns the owner to the other .
39,357
public static < T extends IPositioned & ISized > IntSupplier bottomAlignedTo ( ISized owner , T other , int offset ) { checkNotNull ( other ) ; return ( ) -> { return other . position ( ) . y ( ) + other . size ( ) . height ( ) - owner . size ( ) . height ( ) + offset ; } ; }
Bottom aligns the owner to the other .
39,358
public static < T extends IPositioned & ISized > IntSupplier middleAlignedTo ( ISized owner , T other , int offset ) { checkNotNull ( other ) ; return ( ) -> { return ( int ) ( other . position ( ) . y ( ) + Math . ceil ( ( ( float ) other . size ( ) . height ( ) - owner . size ( ) . height ( ) ) / 2 ) + offset ) ; } ; }
Middle aligns the owner to the other .
39,359
public static int getRotationCount ( EnumFacing facing ) { if ( facing == null ) return 0 ; switch ( facing ) { case EAST : return 1 ; case NORTH : return 2 ; case WEST : return 3 ; case SOUTH : default : return 0 ; } }
Gets the rotation count for the facing .
39,360
public static EnumFacing getRealSide ( IBlockState state , EnumFacing side ) { if ( state == null || side == null ) return side ; EnumFacing direction = DirectionalComponent . getDirection ( state ) ; if ( direction == EnumFacing . SOUTH ) return side ; if ( direction == EnumFacing . DOWN ) return side . rotateAround ( Axis . X ) ; else if ( direction == EnumFacing . UP ) switch ( side ) { case UP : return EnumFacing . SOUTH ; case DOWN : return EnumFacing . NORTH ; case NORTH : return EnumFacing . UP ; case SOUTH : return EnumFacing . DOWN ; default : return side ; } int count = EnumFacingUtils . getRotationCount ( direction ) ; side = EnumFacingUtils . rotateFacing ( side , count ) ; return side ; }
Gets the real side of a rotated block .
39,361
public < REQ extends IMessage , REPLY extends IMessage > void registerMessage ( Class < ? extends IMessageHandler < REQ , REPLY > > messageHandler , Class < REQ > requestMessageType , Side side ) { super . registerMessage ( messageHandler , requestMessageType , discriminator ++ , side ) ; MalisisCore . log . info ( "Registering " + messageHandler . getSimpleName ( ) + " for " + requestMessageType . getSimpleName ( ) + " with discriminator " + discriminator + " in channel " + name ) ; }
Register a message with the next discriminator available .
39,362
private void buildVertexes ( ) { vertexes . clear ( ) ; if ( controlPoints . size ( ) == 0 ) return ; double step = 1D / ( precision + 1 ) ; double t = 0 ; vertexes . add ( controlPoints . get ( 0 ) ) ; for ( int i = 1 ; i <= precision ; i ++ ) { t = i * step ; vertexes . add ( i , interpolateAll ( controlPoints , controlPoints . size ( ) - 1 , 0 , t ) ) ; } vertexes . add ( controlPoints . get ( controlPoints . size ( ) - 1 ) ) ; dirty = false ; }
Builds the vertexes .
39,363
public Vertex interpolateAll ( List < Vertex > vertexes , int r , int index , double t ) { if ( vertexes . size ( ) == 1 ) return vertexes . get ( 0 ) ; if ( r == 0 ) return vertexes . get ( index ) ; Vertex v1 = interpolateAll ( vertexes , r - 1 , index , t ) ; Vertex v2 = interpolateAll ( vertexes , r - 1 , index + 1 , t ) ; return interpolate ( v1 , v2 , t ) ; }
Interpolate the vertexes places .
39,364
public int setItemStackSize ( int stackSize ) { if ( itemStack . isEmpty ( ) ) return 0 ; int start = itemStack . getCount ( ) ; itemStack . setCount ( Math . min ( stackSize , Math . min ( itemStack . getMaxStackSize ( ) , getSlotStackLimit ( ) ) ) ) ; return itemStack . getCount ( ) - start ; }
Sets the item stack size .
39,365
public UITab setActive ( boolean active ) { if ( container == null ) { this . active = active ; return this ; } this . active = active ; this . container . setVisible ( active ) ; this . container . setEnabled ( active ) ; this . zIndex = container . getZIndex ( ) + ( active ? 1 : 0 ) ; setColor ( this . color ) ; fireEvent ( new ActiveStateChange < > ( this , active ) ) ; return this ; }
Sets this tab to be active . Enables and sets visibility for its container .
39,366
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) protected void doTransform ( ITransformable transformable , float comp ) { if ( listTransformations . size ( ) == 0 ) return ; for ( Transformation transformation : listTransformations ) transformation . transform ( transformable , elapsedTimeCurrentLoop ) ; }
Calculates the tranformation .
39,367
public ParallelTransformation reversed ( boolean reversed ) { if ( ! reversed ) return this ; for ( Transformation < ? , ? > transformation : listTransformations ) transformation . reversed ( true ) ; return this ; }
Sets this trasformation in reverse .
39,368
public void preInit ( FMLPreInitializationEvent event ) { asmDataTable = event . getAsmData ( ) ; autoLoadClasses ( ) ; MinecraftForge . EVENT_BUS . register ( this ) ; settings = new MalisisCoreSettings ( event . getSuggestedConfigurationFile ( ) ) ; Registries . processFMLStateEvent ( event ) ; }
Pre - initialization event
39,369
public double intersectX ( double x ) { if ( direction . x == 0 ) return Double . NaN ; return ( x - origin . x ) / direction . x ; }
Gets the distance to the plane at x .
39,370
public double intersectY ( double y ) { if ( direction . y == 0 ) return Double . NaN ; return ( y - origin . y ) / direction . y ; }
Gets the distance to the plane at y .
39,371
public double intersectZ ( double z ) { if ( direction . z == 0 ) return Double . NaN ; return ( z - origin . z ) / direction . z ; }
Gets the distance to the plane at z .
39,372
public static IPosition inParent ( IChild < ? > owner , int x , int y ) { return new DynamicPosition ( 0 , 0 , leftAligned ( owner , x ) , topAligned ( owner , y ) ) ; }
position relative to parent
39,373
public static < T extends IPositioned & ISized , U extends IPositioned & ISized > IPosition leftOf ( ISized owner , U other , int spacing ) { return of ( Positions . leftOf ( owner , other , spacing ) , middleAlignedTo ( owner , other , 0 ) ) ; }
position relative to other
39,374
public void handleMouseInput ( ) { try { MOUSE_POSITION . udpate ( this ) ; UIComponent component = getComponentAt ( MOUSE_POSITION . x ( ) , MOUSE_POSITION . y ( ) ) ; int button = Mouse . getEventButton ( ) ; if ( Mouse . getEventButtonState ( ) ) { if ( this . mc . gameSettings . touchscreen && this . touchValue ++ > 0 ) return ; this . eventButton = button ; this . lastMouseEvent = Minecraft . getSystemTime ( ) ; this . mousePressed ( component , this . eventButton ) ; } else if ( button != - 1 ) { if ( this . mc . gameSettings . touchscreen && -- this . touchValue > 0 ) return ; this . eventButton = - 1 ; this . mouseReleased ( component , button ) ; this . draggedComponent = null ; } else if ( this . eventButton != - 1 && this . lastMouseEvent > 0L ) { this . mouseDragged ( this . eventButton ) ; } if ( MOUSE_POSITION . hasChanged ( ) ) { if ( component != null ) { tooltip = component . getTooltip ( ) ; if ( component . isEnabled ( ) ) { component . onMouseMove ( ) ; component . setHovered ( true ) ; } } else { setHoveredComponent ( null , false ) ; tooltip = null ; } } int delta = Mouse . getEventDWheel ( ) ; if ( delta == 0 ) return ; else if ( delta > 1 ) delta = 1 ; else if ( delta < - 1 ) delta = - 1 ; if ( component != null && component . isEnabled ( ) ) { component . onScrollWheel ( delta ) ; } } catch ( Exception e ) { MalisisCore . message ( "A problem occured : " + e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ) ; e . printStackTrace ( new PrintStream ( new FileOutputStream ( FileDescriptor . out ) ) ) ; } }
Called every frame to handle mouse input .
39,375
protected void mousePressed ( UIComponent component , int button ) { try { long time = System . currentTimeMillis ( ) ; if ( component != null && component . isEnabled ( ) ) { boolean regularClick = true ; if ( button == lastClickButton && time - lastClickTime < 250 && component == focusedComponent ) { regularClick = ! component . onDoubleClick ( MouseButton . getButton ( button ) ) ; lastClickTime = 0 ; } if ( regularClick ) { component . onButtonPress ( MouseButton . getButton ( button ) ) ; if ( draggedComponent == null ) draggedComponent = component ; } component . setFocused ( true ) ; } else { setFocusedComponent ( null , true ) ; if ( inventoryContainer != null && ! inventoryContainer . getPickedItemStack ( ) . isEmpty ( ) ) { ActionType action = button == 1 ? ActionType . DROP_ONE : ActionType . DROP_STACK ; MalisisGui . sendAction ( action , null , button ) ; } } lastClickTime = time ; lastClickButton = button ; } catch ( Exception e ) { MalisisCore . message ( "A problem occured : " + e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ) ; e . printStackTrace ( new PrintStream ( new FileOutputStream ( FileDescriptor . out ) ) ) ; } }
Called when a mouse button is pressed down .
39,376
protected void mouseDragged ( int button ) { try { if ( draggedComponent != null ) draggedComponent . onDrag ( MouseButton . getButton ( button ) ) ; } catch ( Exception e ) { MalisisCore . message ( "A problem occured : " + e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ) ; e . printStackTrace ( new PrintStream ( new FileOutputStream ( FileDescriptor . out ) ) ) ; } }
Called when the mouse is moved while a button is pressed .
39,377
protected void keyTyped ( char keyChar , int keyCode ) { try { boolean ret = false ; for ( IKeyListener listener : keyListeners ) ret |= listener . onKeyTyped ( keyChar , keyCode ) ; if ( ret ) return ; if ( focusedComponent != null && ! keyListeners . contains ( focusedComponent ) && focusedComponent . onKeyTyped ( keyChar , keyCode ) ) return ; if ( hoveredComponent != null && ! keyListeners . contains ( hoveredComponent ) && hoveredComponent . onKeyTyped ( keyChar , keyCode ) ) return ; if ( isGuiCloseKey ( keyCode ) && mc . currentScreen == this ) close ( ) ; if ( ! MalisisCore . isObfEnv && isCtrlKeyDown ( ) && ( current ( ) != null || isOverlay ) ) { if ( keyCode == Keyboard . KEY_R ) { clearScreen ( ) ; setResolution ( ) ; setHoveredComponent ( null , true ) ; setFocusedComponent ( null , true ) ; constructed = false ; doConstruct ( ) ; } if ( keyCode == Keyboard . KEY_D ) { debug = ! debug ; debugComponent . setEnabled ( debug ) ; } if ( keyCode == Keyboard . KEY_P ) { Position . CACHED = ! Position . CACHED ; } if ( keyCode == Keyboard . KEY_S ) { Size . CACHED = ! Size . CACHED ; } } } catch ( Exception e ) { MalisisCore . message ( "A problem occured while handling key typed for " + e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ) ; e . printStackTrace ( new PrintStream ( new FileOutputStream ( FileDescriptor . out ) ) ) ; } }
Called when a key is pressed on the keyboard .
39,378
public static void sendAction ( ActionType action , MalisisSlot slot , int code ) { if ( action == null || current ( ) == null || current ( ) . inventoryContainer == null ) return ; int inventoryId = slot != null ? slot . getInventoryId ( ) : 0 ; int slotNumber = slot != null ? slot . getSlotIndex ( ) : 0 ; current ( ) . inventoryContainer . handleAction ( action , inventoryId , slotNumber , code ) ; InventoryActionMessage . sendAction ( action , inventoryId , slotNumber , code ) ; }
Sends a GUI action to the server .
39,379
private void runQuery ( ) { if ( this . rowKeysList != null && this . rowKeysList . size ( ) > 0 ) { if ( threadCount > 1 ) { ExecutorService executor = Executors . newFixedThreadPool ( threadCount ) ; List < Future < ? > > futures = new LinkedList < Future < ? > > ( ) ; for ( final List < K > param : this . rowKeysList ) { Future < ? > future = executor . submit ( new Runnable ( ) { public void run ( ) { runMultigetSliceQuery ( param ) ; } } ) ; futures . add ( future ) ; } for ( Future < ? > f : futures ) { try { f . get ( ) ; } catch ( InterruptedException e ) { throw new HectorException ( "Failed to retrieve rows from Cassandra." , e ) ; } catch ( ExecutionException e ) { throw new HectorException ( "Failed to retrieve rows from Cassandra." , e ) ; } } executor . shutdown ( ) ; rowKeysIndex = this . rowKeysList . size ( ) ; } else { runMultigetSliceQuery ( this . rowKeysList . get ( rowKeysIndex ) ) ; rowKeysIndex ++ ; } } ArrayList < Row < K , N , V > > resultList = new ArrayList < Row < K , N , V > > ( queryResult . size ( ) ) ; synchronized ( queryResult ) { if ( queryResult != null && queryResult . size ( ) > 0 ) { for ( Rows < K , N , V > rows : queryResult ) { if ( rows != null && rows . getCount ( ) > 0 ) { for ( Row < K , N , V > row : rows ) { resultList . add ( row ) ; } } } } } iterator = resultList . iterator ( ) ; }
This method prepares keys for execution determines whether to use parallelism or not to query Cassandra executes the query and collects the result
39,380
private List < List < K > > prepareKeysForParallelism ( ) { List < List < K > > returnKeys = new LinkedList < List < K > > ( ) ; int numKeys = rowKeys . size ( ) ; int numThreads = 1 ; if ( maxRowCountPerQuery > 0 ) { numThreads = ( int ) Math . ceil ( ( numKeys / ( double ) maxRowCountPerQuery ) ) ; numThreads = Math . max ( numThreads , 1 ) ; } threadCount = Math . min ( numThreads , maxThreads ) ; numKeysPerThread = ( int ) Math . ceil ( numKeys / ( double ) numThreads ) ; numKeysPerThread = Math . max ( numKeysPerThread , 1 ) ; if ( this . rowKeys != null && this . rowKeys . size ( ) > 0 ) { returnKeys = Lists . partition ( rowKeys , numKeysPerThread ) ; } return returnKeys ; }
prepare row Keys For Parallelism by considering maxRowCountPerQuery m_maxThreads and numKeys
39,381
public void write ( ByteBuffer buffer ) { if ( buffer . remaining ( ) < 8196 ) { write ( buffer . array ( ) , buffer . arrayOffset ( ) + buffer . position ( ) , buffer . remaining ( ) ) ; } else { ByteBuffer dup = buffer . duplicate ( ) ; dup . position ( buffer . limit ( ) ) ; buffers . add ( dup ) ; } }
Add a buffer to the output without copying if possible .
39,382
void updateInternal ( ) { if ( ! subColumns . isEmpty ( ) ) { log . debug ( "Adding column {} for key {} and cols {}" , new Object [ ] { getCurrentSuperColumn ( ) , getCurrentKey ( ) , subColumns } ) ; HSuperColumnImpl < SN , N , ? > column = new HSuperColumnImpl ( getCurrentSuperColumn ( ) , subColumns , 0 , template . getTopSerializer ( ) , template . getSubSerializer ( ) , TypeInferringSerializer . get ( ) ) ; mutator . addInsertion ( getCurrentKey ( ) , template . getColumnFamily ( ) , column ) ; } }
collapse the state of the active HSuperColumn
39,383
public < T , I > T getObject ( Keyspace keyspace , String colFamName , I pkObj ) { if ( null == pkObj ) { throw new IllegalArgumentException ( "object ID cannot be null or empty" ) ; } CFMappingDef < T > cfMapDef = cacheMgr . getCfMapDef ( colFamName , true ) ; byte [ ] colFamKey = generateColumnFamilyKeyFromPkObj ( cfMapDef , pkObj ) ; SliceQuery < byte [ ] , String , byte [ ] > q = HFactory . createSliceQuery ( keyspace , BytesArraySerializer . get ( ) , StringSerializer . get ( ) , BytesArraySerializer . get ( ) ) ; q . setColumnFamily ( colFamName ) ; q . setKey ( colFamKey ) ; if ( cfMapDef . isColumnSliceRequired ( ) ) { q . setColumnNames ( cfMapDef . getSliceColumnNameArr ( ) ) ; } else { q . setRange ( "" , "" , false , maxNumColumns ) ; } QueryResult < ColumnSlice < String , byte [ ] > > result = q . execute ( ) ; if ( null == result || null == result . get ( ) ) { return null ; } T obj = createObject ( cfMapDef , pkObj , result . get ( ) ) ; return obj ; }
Retrieve columns from cassandra keyspace and column family instantiate a new object of required type and then map them to the object s properties .
39,384
public static Subject loginService ( String serviceName ) throws LoginException { LoginContext loginCtx = new LoginContext ( serviceName , new CallbackHandler ( ) { public void handle ( Callback [ ] callbacks ) throws IOException , UnsupportedCallbackException { } } ) ; loginCtx . login ( ) ; return loginCtx . getSubject ( ) ; }
Log in using the service name for jaas . conf file and . keytab instead of specifying username and password
39,385
public static GSSContext authenticateClient ( final Socket socket , Subject subject , final String servicePrincipalName ) { return Subject . doAs ( subject , new PrivilegedAction < GSSContext > ( ) { public GSSContext run ( ) { try { GSSManager manager = GSSManager . getInstance ( ) ; GSSName peerName = manager . createName ( servicePrincipalName , GSSName . NT_HOSTBASED_SERVICE ) ; GSSContext context = manager . createContext ( peerName , null , null , GSSContext . DEFAULT_LIFETIME ) ; while ( ! context . isEstablished ( ) ) { context . initSecContext ( socket . getInputStream ( ) , socket . getOutputStream ( ) ) ; } return context ; } catch ( Exception e ) { log . error ( "Unable to authenticate client against Kerberos" , e ) ; return null ; } } } ) ; }
Authenticate client to use this service and return secure context
39,386
public BatchMutation < K > addDeletion ( K key , List < String > columnFamilies , Deletion deletion ) { Mutation mutation = new Mutation ( ) ; mutation . setDeletion ( deletion ) ; addMutation ( key , columnFamilies , mutation ) ; return this ; }
Add a deletion request to the batch mutation .
39,387
public int countColumns ( K key , SN start , SN end , int max ) { SuperCountQuery < K , SN > query = HFactory . createSuperCountQuery ( keyspace , keySerializer , topSerializer ) ; query . setKey ( key ) ; query . setColumnFamily ( columnFamily ) ; query . setRange ( start , end , max ) ; return query . execute ( ) . get ( ) ; }
Counts columns in the specified range of a super column family
39,388
public int countSubColumns ( K key , SN superColumnName , N start , N end , int max ) { SubCountQuery < K , SN , N > query = HFactory . createSubCountQuery ( keyspace , keySerializer , topSerializer , subSerializer ) ; query . setKey ( key ) ; query . setColumnFamily ( columnFamily ) ; query . setSuperColumn ( superColumnName ) ; query . setRange ( start , end , max ) ; return query . execute ( ) . get ( ) ; }
Counts child columns in the specified range of a children in a specified super column
39,389
public SuperCfResult < K , SN , N > querySuperColumns ( K key , HSlicePredicate < SN > predicate ) { return doExecuteSlice ( key , null , predicate ) ; }
Query super columns using the provided predicate instead of the internal one
39,390
public void deleteColumn ( K key , SN sColumnName ) { createMutator ( ) . superDelete ( key , getColumnFamily ( ) , sColumnName , topSerializer ) ; }
Immediately delete the key and superColumn combination
39,391
public void deleteRow ( K key ) { createMutator ( ) . delete ( key , getColumnFamily ( ) , null , null ) ; }
Immediately delete the row
39,392
public < T > CFMappingDef < T > getCfMapDef ( String colFamName , boolean throwException ) { @ SuppressWarnings ( "unchecked" ) CFMappingDef < T > cfMapDef = ( CFMappingDef < T > ) cfMapByColFamName . get ( colFamName ) ; if ( null == cfMapDef && throwException ) { throw new HectorObjectMapperException ( "could not find property definitions for column family, " + colFamName + ", in class cache. This indicates the EntityManager was not initialized properly. If not using EntityManager the cache must be explicity initialized" ) ; } return cfMapDef ; }
Retrieve class mapping meta - data by ColumnFamily name .
39,393
public < T > CFMappingDef < T > initializeCacheForClass ( Class < T > clazz ) { CFMappingDef < T > cfMapDef = initializeColumnFamilyMapDef ( clazz ) ; try { initializePropertiesMapDef ( cfMapDef ) ; } catch ( IntrospectionException e ) { throw new HectorObjectMapperException ( e ) ; } catch ( InstantiationException e ) { throw new HectorObjectMapperException ( e ) ; } catch ( IllegalAccessException e ) { throw new HectorObjectMapperException ( e ) ; } checkMappingAndSetDefaults ( cfMapDef ) ; if ( ! cfMapDef . isDerivedEntity ( ) ) { cfMapByColFamName . put ( cfMapDef . getEffectiveColFamName ( ) , cfMapDef ) ; } cfMapByClazz . put ( cfMapDef . getRealClass ( ) , cfMapDef ) ; return cfMapDef ; }
For each class that should be managed this method must be called to parse its annotations and derive its meta - data .
39,394
public Method findAnnotatedMethod ( Class < ? > clazz , Class < ? extends Annotation > anno ) { for ( Method meth : clazz . getMethods ( ) ) { if ( meth . isAnnotationPresent ( anno ) ) { return meth ; } } return null ; }
Find method annotated with the given annotation .
39,395
public void clear ( ) { Mutator < K > mutator = HFactory . createMutator ( this . keyspace , this . keySerializer , new BatchSizeHint ( 1 , this . mutateInterval ) ) ; SliceCounterQuery < K , N > query = HFactory . createCounterSliceQuery ( this . keyspace , this . keySerializer , this . nameSerializer ) . setColumnFamily ( this . cf ) . setKey ( this . rowKey ) ; SliceCounterIterator < K , N > iterator = new SliceCounterIterator < K , N > ( query , null , ( N ) null , false , this . count ) ; while ( iterator . hasNext ( ) ) { HCounterColumn < N > column = iterator . next ( ) ; mutator . incrementCounter ( this . rowKey , this . cf , column . getName ( ) , column . getValue ( ) * - 1 ) ; } mutator . execute ( ) ; }
Clear the counter columns .
39,396
public static Cluster createCluster ( String clusterName , CassandraHostConfigurator cassandraHostConfigurator , Map < String , String > credentials ) { synchronized ( clusters ) { Cluster cluster = clusters . get ( clusterName ) ; if ( cluster == null ) { cluster = new ThriftCluster ( clusterName , cassandraHostConfigurator , credentials ) ; clusters . put ( clusterName , cluster ) ; cluster . onStartup ( ) ; } return cluster ; } }
Method looks in the cache for the cluster by name . If none exists a new ThriftCluster instance is created and added to the map of known clusters
39,397
public static void shutdownCluster ( Cluster cluster ) { synchronized ( clusters ) { String clusterName = cluster . getName ( ) ; if ( clusters . get ( clusterName ) != null ) { cluster . getConnectionManager ( ) . shutdown ( ) ; clusters . remove ( clusterName ) ; } } }
Shutdown this cluster removing it from the Map . This operation is extremely expensive and should not be done lightly .
39,398
public static Keyspace createKeyspace ( String keyspace , Cluster cluster ) { return createKeyspace ( keyspace , cluster , createDefaultConsistencyLevelPolicy ( ) , FailoverPolicy . ON_FAIL_TRY_ALL_AVAILABLE ) ; }
Creates a Keyspace with the default consistency level policy .
39,399
public static < K , N , V > Mutator < K > createMutator ( Keyspace keyspace , Serializer < K > keySerializer ) { return new MutatorImpl < K > ( keyspace , keySerializer ) ; }
Creates a mutator for updating records in a keyspace .