Merge pull request #1868 from fuami/ISmartBlockModel_Damage
Add Block Breaking Animation for ISmartBlockModels
This commit is contained in:
commit
e007f7cf39
2 changed files with 291 additions and 1 deletions
|
@ -1,6 +1,31 @@
|
|||
--- ../src-base/minecraft/net/minecraft/client/renderer/BlockRendererDispatcher.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/renderer/BlockRendererDispatcher.java
|
||||
@@ -129,6 +129,12 @@
|
||||
@@ -49,6 +49,24 @@
|
||||
{
|
||||
p_175020_1_ = block.func_176221_a(p_175020_1_, p_175020_4_, p_175020_2_);
|
||||
IBakedModel ibakedmodel = this.field_175028_a.func_178125_b(p_175020_1_);
|
||||
+
|
||||
+ if(ibakedmodel instanceof net.minecraftforge.client.model.ISmartBlockModel)
|
||||
+ {
|
||||
+ IBlockState extendedState = block.getExtendedState(p_175020_1_, p_175020_4_, p_175020_2_);
|
||||
+ for ( net.minecraft.util.EnumWorldBlockLayer layer : net.minecraft.util.EnumWorldBlockLayer.values() )
|
||||
+ {
|
||||
+ if ( block.canRenderInLayer( layer ) )
|
||||
+ {
|
||||
+ net.minecraftforge.client.ForgeHooksClient.setRenderLayer(layer);
|
||||
+
|
||||
+ IBakedModel targetLayer = ((net.minecraftforge.client.model.ISmartBlockModel)ibakedmodel).handleBlockState(extendedState);
|
||||
+ IBakedModel damageModel = (new SimpleBakedModel.Builder(targetLayer, p_175020_3_)).func_177645_b();
|
||||
+ this.field_175027_c.func_178259_a(p_175020_4_, damageModel, p_175020_1_, p_175020_2_, Tessellator.func_178181_a().func_178180_c());
|
||||
+ }
|
||||
+ }
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
IBakedModel ibakedmodel1 = (new SimpleBakedModel.Builder(ibakedmodel, p_175020_3_)).func_177645_b();
|
||||
this.field_175027_c.func_178259_a(p_175020_4_, ibakedmodel1, p_175020_1_, p_175020_2_, Tessellator.func_178181_a().func_178180_c());
|
||||
}
|
||||
@@ -129,6 +147,12 @@
|
||||
ibakedmodel = ((WeightedBakedModel)ibakedmodel).func_177564_a(MathHelper.func_180186_a(p_175022_3_));
|
||||
}
|
||||
|
||||
|
|
265
src/test/java/net/minecraftforge/debug/LayerBreakingTest.java
Normal file
265
src/test/java/net/minecraftforge/debug/LayerBreakingTest.java
Normal file
|
@ -0,0 +1,265 @@
|
|||
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.model.IFlexibleBakedModel;
|
||||
import net.minecraftforge.client.model.IModelPart;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.ISmartBlockModel;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
@SuppressWarnings( "deprecation" )
|
||||
@Mod( modid = "LayerBreakingTest", name = "LayerBreakingTest", version = "0.0.0" )
|
||||
public class LayerBreakingTest
|
||||
{
|
||||
|
||||
public static final boolean ENABLE = true;
|
||||
public static TestBlock testBlock;
|
||||
|
||||
class TestBakedModel implements IFlexibleBakedModel
|
||||
{
|
||||
|
||||
TextureAtlasSprite texture;
|
||||
List<BakedQuad> list = new ArrayList<BakedQuad>();
|
||||
|
||||
private int[] vertexToInts(
|
||||
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 };
|
||||
}
|
||||
|
||||
public TestBakedModel(
|
||||
TextureAtlasSprite sprite,
|
||||
boolean top )
|
||||
{
|
||||
texture = sprite;
|
||||
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 ) );
|
||||
}
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getTexture()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(
|
||||
EnumFacing side )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class TestBlock extends Block
|
||||
{
|
||||
|
||||
protected TestBlock()
|
||||
{
|
||||
super( Material.glass );
|
||||
setHardness( 7 );
|
||||
setCreativeTab( CreativeTabs.tabBlock );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFullCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInLayer(
|
||||
EnumWorldBlockLayer layer )
|
||||
{
|
||||
return layer == EnumWorldBlockLayer.SOLID || layer == EnumWorldBlockLayer.TRANSLUCENT;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class SmartModel implements IBakedModel, ISmartBlockModel
|
||||
{
|
||||
|
||||
IFlexibleBakedModel solid;
|
||||
IFlexibleBakedModel translucent;
|
||||
|
||||
private class DefState implements IModelState
|
||||
{
|
||||
|
||||
@Override
|
||||
public TRSRTransformation apply(
|
||||
IModelPart part )
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public List getFaceQuads(
|
||||
EnumFacing p_177551_1_ )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getGeneralQuads()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getTexture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleBlockState(
|
||||
IBlockState state )
|
||||
{
|
||||
if ( solid == null )
|
||||
{
|
||||
TextureAtlasSprite a = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState( Blocks.stained_glass.getStateFromMeta( 3 ) ).getTexture();
|
||||
TextureAtlasSprite b = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState( Blocks.cobblestone.getDefaultState() ).getTexture();
|
||||
|
||||
translucent = new TestBakedModel( a, true );
|
||||
solid = new TestBakedModel( b, false );
|
||||
}
|
||||
|
||||
if ( net.minecraftforge.client.MinecraftForgeClient.getRenderLayer() == EnumWorldBlockLayer.SOLID )
|
||||
{
|
||||
return solid;
|
||||
}
|
||||
else
|
||||
{
|
||||
return translucent;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent(
|
||||
ModelBakeEvent event )
|
||||
{
|
||||
event.modelRegistry.putObject( new ModelResourceLocation( "LayerBreakingTest:LayerBreakingTest" ), new SmartModel() );
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(
|
||||
FMLInitializationEvent event )
|
||||
{
|
||||
if ( ENABLE && event.getSide() == Side.CLIENT )
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register( this );
|
||||
GameRegistry.registerBlock( testBlock = new TestBlock(), "LayerBreakingTest" );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue