2015-11-29 21:02:55 +00:00
package net.minecraftforge.debug ;
import gnu.trove.set.TIntSet ;
import gnu.trove.set.hash.TIntHashSet ;
2015-12-30 04:15:03 +00:00
import java.util.Random ;
2015-11-29 21:02:55 +00:00
import net.minecraft.client.Minecraft ;
2016-03-09 22:11:56 +00:00
import net.minecraft.client.renderer.GlStateManager ;
import net.minecraft.client.renderer.Tessellator ;
import net.minecraft.client.renderer.VertexBuffer ;
2015-11-29 21:02:55 +00:00
import net.minecraft.client.renderer.texture.TextureAtlasSprite ;
import net.minecraft.client.renderer.texture.TextureMap ;
2016-03-09 22:11:56 +00:00
import net.minecraft.client.renderer.vertex.DefaultVertexFormats ;
2015-11-29 21:02:55 +00:00
import net.minecraft.potion.Potion ;
import net.minecraft.potion.PotionEffect ;
import net.minecraft.util.ResourceLocation ;
import net.minecraftforge.fml.common.Mod ;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent ;
2016-03-09 22:11:56 +00:00
import net.minecraftforge.fml.common.registry.GameData ;
2015-11-29 21:02:55 +00:00
2016-11-22 20:12:13 +00:00
@Mod ( modid = PotionRegistryDebug . MODID , name = " ForgePotionRegistry " , version = " 1.0 " , acceptableRemoteVersions = " * " )
2015-11-29 21:02:55 +00:00
public class PotionRegistryDebug {
2016-08-12 22:10:47 +00:00
public static final String MODID = " forgepotionregistry " ;
2015-11-29 21:02:55 +00:00
@Mod.EventHandler
public void preInit ( FMLPreInitializationEvent event ) {
2016-03-09 22:11:56 +00:00
Potion forge = new PotionForge ( new ResourceLocation ( " forge " , " forge " ) , false , 0xff00ff ) ; // test automatic id distribution
Potion forgy = new PotionForge ( new ResourceLocation ( " forge " , " forgy " ) , true , 0x00ff00 ) ; // test that ids above 127 work
GameData . getPotionRegistry ( ) . register ( - 1 , new ResourceLocation ( " forge " , " forge " ) , forge ) ; //TODo: Generic this out in GameRegistry, 'RegistryEntry' base type?
GameData . getPotionRegistry ( ) . register ( 200 , new ResourceLocation ( " forge " , " forgy " ) , forgy ) ;
2015-11-29 21:02:55 +00:00
Random rand = new Random ( ) ;
TIntSet taken = new TIntHashSet ( 100 ) ;
int ra = rand . nextInt ( 100 ) + 100 ;
taken . add ( ra ) ;
// a new potion with a random id so that forge has to remap it
2016-03-09 22:11:56 +00:00
//new PotionForge(ra, new ResourceLocation("forge", "realRandomPotion"), false, 0x0000ff);
2015-11-29 21:02:55 +00:00
for ( int i = 0 ; i < 20 ; i + + ) {
int r = rand . nextInt ( 200 ) + 35 ;
while ( taken . contains ( r ) )
r = rand . nextInt ( 200 ) + 35 ;
//r = 32+i;
taken . add ( r ) ;
// this potions will most likely not have the same IDs between server and client.
// The forge handshake on connect should fix this.
2016-03-09 22:11:56 +00:00
//new PotionForge(new ResourceLocation("forge", "randomPotion" + r), false, 0xff00ff);
2015-11-29 21:02:55 +00:00
}
}
protected class PotionForge extends Potion {
protected PotionForge ( ResourceLocation location , boolean badEffect , int potionColor ) {
2016-03-09 22:11:56 +00:00
super ( badEffect , potionColor ) ;
2015-11-29 21:02:55 +00:00
setPotionName ( " potion. " + location . getResourcePath ( ) ) ;
}
@Override
public void renderInventoryEffect ( int x , int y , PotionEffect effect , Minecraft mc ) {
2016-03-13 01:40:03 +00:00
Potion potion = effect . getPotion ( ) ;
2015-11-29 21:02:55 +00:00
2016-05-18 12:11:56 +00:00
mc . getTextureManager ( ) . bindTexture ( TextureMap . LOCATION_BLOCKS_TEXTURE ) ;
2015-11-29 21:02:55 +00:00
TextureAtlasSprite sprite = mc . getTextureMapBlocks ( ) . getAtlasSprite ( " minecraft:blocks/fire_layer_0 " ) ;
x + = 6 ;
y + = 7 ;
int width = 18 ;
int height = width ;
2016-03-09 22:11:56 +00:00
float r = ( float ) ( potion . getLiquidColor ( ) > > 24 & 255 ) / 255 . 0F ;
float g = ( float ) ( potion . getLiquidColor ( ) > > 16 & 255 ) / 255 . 0F ;
float b = ( float ) ( potion . getLiquidColor ( ) > > 8 & 255 ) / 255 . 0F ;
float a = ( float ) ( potion . getLiquidColor ( ) & 255 ) / 255 . 0F ;
2015-11-29 21:02:55 +00:00
Tessellator tessellator = Tessellator . getInstance ( ) ;
2016-03-13 01:40:03 +00:00
VertexBuffer buf = tessellator . getBuffer ( ) ;
2016-03-09 22:11:56 +00:00
buf . begin ( 7 , DefaultVertexFormats . POSITION_TEX ) ;
GlStateManager . color ( r , g , b , a ) ;
2016-03-13 01:40:03 +00:00
buf . pos ( ( double ) x , ( double ) ( y + height ) , 0 . 0D ) . tex ( sprite . getMinU ( ) , sprite . getMaxV ( ) ) . endVertex ( ) ;
buf . pos ( ( double ) ( x + width ) , ( double ) ( y + height ) , 0 . 0D ) . tex ( sprite . getMaxU ( ) , sprite . getMaxV ( ) ) . endVertex ( ) ;
buf . pos ( ( double ) ( x + width ) , ( double ) y , 0 . 0D ) . tex ( sprite . getMaxU ( ) , sprite . getMinV ( ) ) . endVertex ( ) ;
buf . pos ( ( double ) x , ( double ) y , 0 . 0D ) . tex ( sprite . getMinU ( ) , sprite . getMinV ( ) ) . endVertex ( ) ;
2016-03-09 22:11:56 +00:00
tessellator . draw ( ) ;
2015-11-29 21:02:55 +00:00
}
2016-05-02 21:44:14 +00:00
@Override
public void renderHUDEffect ( int x , int y , PotionEffect effect , Minecraft mc , float alpha ) {
Potion potion = effect . getPotion ( ) ;
2016-05-18 12:11:56 +00:00
mc . getTextureManager ( ) . bindTexture ( TextureMap . LOCATION_BLOCKS_TEXTURE ) ;
2016-05-02 21:44:14 +00:00
TextureAtlasSprite sprite = mc . getTextureMapBlocks ( ) . getAtlasSprite ( " minecraft:blocks/tnt_side " ) ;
x + = 3 ;
y + = 3 ;
int width = 18 ;
int height = width ;
float r = ( float ) ( potion . getLiquidColor ( ) > > 24 & 255 ) / 255 . 0F ;
float g = ( float ) ( potion . getLiquidColor ( ) > > 16 & 255 ) / 255 . 0F ;
float b = ( float ) ( potion . getLiquidColor ( ) > > 8 & 255 ) / 255 . 0F ;
Tessellator tessellator = Tessellator . getInstance ( ) ;
VertexBuffer buf = tessellator . getBuffer ( ) ;
buf . begin ( 7 , DefaultVertexFormats . POSITION_TEX ) ;
GlStateManager . color ( r , g , b , alpha ) ;
buf . pos ( ( double ) x , ( double ) ( y + height ) , 0 . 0D ) . tex ( sprite . getMinU ( ) , sprite . getMaxV ( ) ) . endVertex ( ) ;
buf . pos ( ( double ) ( x + width ) , ( double ) ( y + height ) , 0 . 0D ) . tex ( sprite . getMaxU ( ) , sprite . getMaxV ( ) ) . endVertex ( ) ;
buf . pos ( ( double ) ( x + width ) , ( double ) y , 0 . 0D ) . tex ( sprite . getMaxU ( ) , sprite . getMinV ( ) ) . endVertex ( ) ;
buf . pos ( ( double ) x , ( double ) y , 0 . 0D ) . tex ( sprite . getMinU ( ) , sprite . getMinV ( ) ) . endVertex ( ) ;
tessellator . draw ( ) ;
}
2015-11-29 21:02:55 +00:00
}
}