Cleanup code format in LayerBreakingTest.

This commit is contained in:
Lex Manos 2015-06-16 16:01:09 -07:00
parent 114ac38910
commit d0902c096e

View file

@ -11,6 +11,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -35,45 +36,33 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@SuppressWarnings( "deprecation" ) @SuppressWarnings( "deprecation" )
@Mod( modid = "LayerBreakingTest", name = "LayerBreakingTest", version = "0.0.0" ) @Mod( modid = "LayerBreakingTest", name = "LayerBreakingTest", version = "0.0.0" )
public class LayerBreakingTest public class LayerBreakingTest
{ {
public static final boolean ENABLE = true; public static final boolean ENABLE = true;
public static TestBlock testBlock; public static TestBlock testBlock;
class TestBakedModel implements IFlexibleBakedModel class TestBakedModel implements IFlexibleBakedModel
{ {
TextureAtlasSprite texture; TextureAtlasSprite texture;
List<BakedQuad> list = new ArrayList<BakedQuad>(); List<BakedQuad> list = new ArrayList<BakedQuad>();
private int[] vertexToInts( private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, int u, int v)
float x,
float y,
float z,
int color,
TextureAtlasSprite texture,
int u,
int v )
{ {
return new int[] { Float.floatToRawIntBits( x ), Float.floatToRawIntBits( y ), Float.floatToRawIntBits( z ), color, Float.floatToRawIntBits( texture.getInterpolatedU( u ) ), Float.floatToRawIntBits( texture.getInterpolatedV( v ) ), 0 }; return new int[] { Float.floatToRawIntBits(x), Float.floatToRawIntBits(y), Float.floatToRawIntBits(z), color, Float.floatToRawIntBits(texture.getInterpolatedU(u)), Float.floatToRawIntBits(texture.getInterpolatedV(v)), 0 };
} }
public TestBakedModel( public TestBakedModel(TextureAtlasSprite sprite, boolean top)
TextureAtlasSprite sprite,
boolean top )
{ {
texture = sprite; texture = sprite;
if ( top ) if (top)
{ {
list.add( new BakedQuad( Ints.concat( vertexToInts( 0.5f, 1.0f, 0, -1, texture, 8, 0 ), vertexToInts( 0.5f, 1.0f, 1, -1, texture, 8, 16 ), vertexToInts( 1, 1.0f, 1, -1, texture, 16, 16 ), vertexToInts( 1, 1.0f, 0, -1, texture, 16, 0 ) ), -1, EnumFacing.UP ) ); list.add(new BakedQuad(Ints.concat(vertexToInts(0.5f, 1.0f, 0, -1, texture, 8, 0), vertexToInts(0.5f, 1.0f, 1, -1, texture, 8, 16), vertexToInts(1, 1.0f, 1, -1, texture, 16, 16), vertexToInts(1, 1.0f, 0, -1, texture, 16, 0)), -1, EnumFacing.UP));
} }
else else
{ {
list.add( new BakedQuad( Ints.concat( vertexToInts( 0, 1.0f, 0, -1, texture, 0, 0 ), vertexToInts( 0, 1.0f, 1, -1, texture, 0, 16 ), vertexToInts( 0.5f, 1.0f, 1, -1, texture, 8, 16 ), vertexToInts( 0.5f, 1.0f, 0, -1, texture, 8, 0 ) ), -1, EnumFacing.DOWN ) ); list.add(new BakedQuad(Ints.concat(vertexToInts(0, 1.0f, 0, -1, texture, 0, 0), vertexToInts(0, 1.0f, 1, -1, texture, 0, 16), vertexToInts(0.5f, 1.0f, 1, -1, texture, 8, 16), vertexToInts(0.5f, 1.0f, 0, -1, texture, 8, 0)), -1, EnumFacing.DOWN));
} }
} }
@ -108,8 +97,7 @@ public class LayerBreakingTest
} }
@Override @Override
public List<BakedQuad> getFaceQuads( public List<BakedQuad> getFaceQuads(EnumFacing side)
EnumFacing side )
{ {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -125,17 +113,15 @@ public class LayerBreakingTest
{ {
return null; return null;
} }
}; };
class TestBlock extends Block class TestBlock extends Block
{ {
protected TestBlock() protected TestBlock()
{ {
super( Material.glass ); super(Material.glass);
setHardness( 7 ); setHardness(7);
setCreativeTab( CreativeTabs.tabBlock ); setCreativeTab(CreativeTabs.tabBlock);
} }
@Override @Override
@ -150,35 +136,28 @@ public class LayerBreakingTest
} }
@Override @Override
public boolean canRenderInLayer( public boolean canRenderInLayer(EnumWorldBlockLayer layer)
EnumWorldBlockLayer layer )
{ {
return layer == EnumWorldBlockLayer.SOLID || layer == EnumWorldBlockLayer.TRANSLUCENT; return layer == EnumWorldBlockLayer.SOLID || layer == EnumWorldBlockLayer.TRANSLUCENT;
} }
}; };
class SmartModel implements IBakedModel, ISmartBlockModel class SmartModel implements IBakedModel, ISmartBlockModel
{ {
IFlexibleBakedModel solid; IFlexibleBakedModel solid;
IFlexibleBakedModel translucent; IFlexibleBakedModel translucent;
private class DefState implements IModelState private class DefState implements IModelState
{ {
@Override @Override
public TRSRTransformation apply( public TRSRTransformation apply(IModelPart part)
IModelPart part )
{ {
return TRSRTransformation.identity(); return TRSRTransformation.identity();
} }
}; };
@Override @Override
public List getFaceQuads( public List getFaceQuads(EnumFacing p_177551_1_)
EnumFacing p_177551_1_ )
{ {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -220,19 +199,16 @@ public class LayerBreakingTest
} }
@Override @Override
public IBakedModel handleBlockState( public IBakedModel handleBlockState(IBlockState state)
IBlockState state )
{ {
if ( solid == null ) if (solid == null)
{ {
TextureAtlasSprite a = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState( Blocks.stained_glass.getStateFromMeta( 3 ) ).getTexture(); BlockModelShapes models = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
TextureAtlasSprite b = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState( Blocks.cobblestone.getDefaultState() ).getTexture(); translucent = new TestBakedModel(models.getModelForState(Blocks.stained_glass.getStateFromMeta(3)).getTexture(), true);
solid = new TestBakedModel(models.getModelForState(Blocks.cobblestone.getDefaultState()).getTexture(), false);
translucent = new TestBakedModel( a, true );
solid = new TestBakedModel( b, false );
} }
if ( net.minecraftforge.client.MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.SOLID ) if (net.minecraftforge.client.MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.SOLID)
{ {
return solid; return solid;
} }
@ -241,25 +217,21 @@ public class LayerBreakingTest
return translucent; return translucent;
} }
} }
}; };
@SubscribeEvent @SubscribeEvent
public void onModelBakeEvent( public void onModelBakeEvent(ModelBakeEvent event)
ModelBakeEvent event )
{ {
event.modelRegistry.putObject( new ModelResourceLocation( "LayerBreakingTest:LayerBreakingTest" ), new SmartModel() ); event.modelRegistry.putObject(new ModelResourceLocation("layerbreakingtest:layer_breaking_test"), new SmartModel());
} }
@EventHandler @EventHandler
public void init( public void init(FMLInitializationEvent event)
FMLInitializationEvent event )
{ {
if ( ENABLE && event.getSide() == Side.CLIENT ) if (ENABLE && event.getSide() == Side.CLIENT)
{ {
MinecraftForge.EVENT_BUS.register( this ); MinecraftForge.EVENT_BUS.register(this);
GameRegistry.registerBlock( testBlock = new TestBlock(), "LayerBreakingTest" ); GameRegistry.registerBlock(testBlock = new TestBlock(), "layer_breaking_test");
} }
} }
} }