Orientation Fixes when Placing Blocks with Tile Entities
Sky Compass Rendering (no rotation yet)
This commit is contained in:
@@ -201,11 +201,11 @@ public class AutoRotatingModel implements IBakedModel
|
||||
for( int e = 0; e < count; e++ )
|
||||
{
|
||||
VertexFormatElement element = format.getElement( e );
|
||||
if( element.getUsage() == VertexFormatElement.EnumUsage.POSITION )
|
||||
if( element.getUsage() == VertexFormatElement.Usage.POSITION )
|
||||
{
|
||||
this.parent.put( e, this.transform( this.quadData[e][v] ) );
|
||||
}
|
||||
else if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL )
|
||||
else if( element.getUsage() == VertexFormatElement.Usage.NORMAL )
|
||||
{
|
||||
this.parent.put( e, this.transformNormal( this.quadData[e][v] ) );
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.google.common.base.Strings;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
@@ -47,7 +46,6 @@ import appeng.decorative.solid.BlockQuartzGlass;
|
||||
import appeng.decorative.solid.GlassState;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraftforge.client.model.ModelDataManager;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Vector4f;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Applies an arbitrary transformation matrix to the vertices of a quad.
|
||||
@@ -46,18 +47,19 @@ final class MatrixVertexTransformer extends QuadGatheringTransformer
|
||||
protected void processQuad()
|
||||
{
|
||||
VertexFormat format = this.parent.getVertexFormat();
|
||||
int count = format.getElementCount();
|
||||
List<VertexFormatElement> elements = format.getElements();
|
||||
int count = elements.size();
|
||||
|
||||
for( int v = 0; v < 4; v++ )
|
||||
{
|
||||
for( int e = 0; e < count; e++ )
|
||||
{
|
||||
VertexFormatElement element = format.getElement( e );
|
||||
if( element.getUsage() == VertexFormatElement.EnumUsage.POSITION )
|
||||
VertexFormatElement element = elements.get( e );
|
||||
if( element.getUsage() == VertexFormatElement.Usage.POSITION )
|
||||
{
|
||||
this.parent.put( e, this.transform( this.quadData[e][v], element.getElementCount() ) );
|
||||
}
|
||||
else if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL )
|
||||
else if( element.getUsage() == VertexFormatElement.Usage.NORMAL )
|
||||
{
|
||||
this.parent.put( e, this.transformNormal( this.quadData[e][v] ) );
|
||||
}
|
||||
@@ -98,38 +100,38 @@ final class MatrixVertexTransformer extends QuadGatheringTransformer
|
||||
switch( fs.length )
|
||||
{
|
||||
case 3:
|
||||
javax.vecmath.Vector3f vec = new javax.vecmath.Vector3f( fs[0], fs[1], fs[2] );
|
||||
vec.x -= 0.5f;
|
||||
vec.y -= 0.5f;
|
||||
vec.z -= 0.5f;
|
||||
this.transform.transform( vec );
|
||||
vec.x += 0.5f;
|
||||
vec.y += 0.5f;
|
||||
vec.z += 0.5f;
|
||||
Vector4f vec = new Vector4f( fs[0], fs[1], fs[2], 1 );
|
||||
vec.setX(vec.getX() - 0.5f);
|
||||
vec.setY(vec.getY() - 0.5f);
|
||||
vec.setZ(vec.getZ() - 0.5f);
|
||||
vec.transform(this.transform); // FIXME: Check this, we're using a Vec4, input is Vec3
|
||||
vec.setX(vec.getX() + 0.5f);
|
||||
vec.setY(vec.getY() + 0.5f);
|
||||
vec.setZ(vec.getZ() + 0.5f);
|
||||
return new float[] {
|
||||
vec.x,
|
||||
vec.y,
|
||||
vec.z
|
||||
vec.getX(),
|
||||
vec.getY(),
|
||||
vec.getZ()
|
||||
};
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
|
||||
// Otherwise all translation is lost
|
||||
if( elemCount == 3 )
|
||||
{
|
||||
vecc.w = 1;
|
||||
vecc.setW(1);
|
||||
}
|
||||
vecc.x -= 0.5f;
|
||||
vecc.y -= 0.5f;
|
||||
vecc.z -= 0.5f;
|
||||
this.transform.transform( vecc );
|
||||
vecc.x += 0.5f;
|
||||
vecc.y += 0.5f;
|
||||
vecc.z += 0.5f;
|
||||
vecc.setX(vecc.getX() - 0.5f);
|
||||
vecc.setY(vecc.getY() - 0.5f);
|
||||
vecc.setZ(vecc.getZ() - 0.5f);
|
||||
vecc.transform(this.transform);
|
||||
vecc.setX(vecc.getX() + 0.5f);
|
||||
vecc.setY(vecc.getY() + 0.5f);
|
||||
vecc.setZ(vecc.getZ() + 0.5f);
|
||||
return new float[] {
|
||||
vecc.x,
|
||||
vecc.y,
|
||||
vecc.z,
|
||||
vecc.w
|
||||
vecc.getX(),
|
||||
vecc.getY(),
|
||||
vecc.getZ(),
|
||||
vecc.getW()
|
||||
};
|
||||
|
||||
default:
|
||||
@@ -145,23 +147,23 @@ final class MatrixVertexTransformer extends QuadGatheringTransformer
|
||||
{
|
||||
case 3:
|
||||
normal = new Vector4f( fs[0], fs[1], fs[2], 0 );
|
||||
this.transform.transform( normal );
|
||||
normal.transform(this.transform);
|
||||
normal.normalize();
|
||||
return new float[] {
|
||||
normal.x,
|
||||
normal.y,
|
||||
normal.z
|
||||
normal.getX(),
|
||||
normal.getY(),
|
||||
normal.getZ()
|
||||
};
|
||||
|
||||
case 4:
|
||||
normal = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
|
||||
this.transform.transform( normal );
|
||||
normal.transform(this.transform);
|
||||
normal.normalize();
|
||||
return new float[] {
|
||||
normal.x,
|
||||
normal.y,
|
||||
normal.z,
|
||||
normal.w
|
||||
normal.getX(),
|
||||
normal.getY(),
|
||||
normal.getZ(),
|
||||
normal.getW()
|
||||
};
|
||||
|
||||
default:
|
||||
|
||||
@@ -22,13 +22,14 @@ package appeng.client.render.model;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.AxisAngle4f;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.entity.PlayerEntitySP;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Quaternion;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
@@ -40,20 +41,21 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
|
||||
import appeng.block.misc.BlockSkyCompass;
|
||||
import appeng.hooks.CompassManager;
|
||||
import appeng.hooks.CompassResult;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* This baked model combines the quads of a compass base and the quads of a compass pointer, which will be rotated
|
||||
* around the Y-axis to get the compass to point in the right direction.
|
||||
*/
|
||||
public class SkyCompassBakedModel implements IBakedModel
|
||||
public class SkyCompassBakedModel implements IDynamicBakedModel
|
||||
{
|
||||
// Rotation is expressed as radians
|
||||
public static final ModelProperty<Float> ROTATION = new ModelProperty<>();
|
||||
|
||||
private final IBakedModel base;
|
||||
|
||||
@@ -68,19 +70,15 @@ public class SkyCompassBakedModel implements IBakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( @Nullable BlockState state, @Nullable Direction side, long rand )
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData )
|
||||
{
|
||||
float rotation = 0;
|
||||
// Get rotation from the special block state
|
||||
if( state instanceof IExtendedBlockState )
|
||||
{
|
||||
Float rotationOpt = ( (IExtendedBlockState) state ).getValue( BlockSkyCompass.ROTATION );
|
||||
if( rotationOpt != null )
|
||||
{
|
||||
rotation = rotationOpt;
|
||||
}
|
||||
Float rotationFromData = extraData.getData(ROTATION);
|
||||
if (rotationFromData != null) {
|
||||
rotation = rotationFromData;
|
||||
}
|
||||
else if( state == null )
|
||||
else
|
||||
{
|
||||
// This is used to render a compass pointing in a specific direction when being held in hand
|
||||
rotation = this.fallbackRotation;
|
||||
@@ -88,8 +86,7 @@ public class SkyCompassBakedModel implements IBakedModel
|
||||
|
||||
// Pre-compute the quad count to avoid list resizes
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
|
||||
quads.addAll( this.base.getQuads( state, side, rand ) );
|
||||
quads.addAll( this.base.getQuads( state, side, rand, extraData ) );
|
||||
|
||||
// We'll add the pointer as "sideless"
|
||||
if( side == null )
|
||||
@@ -97,17 +94,18 @@ public class SkyCompassBakedModel implements IBakedModel
|
||||
// Set up the rotation around the Y-axis for the pointer
|
||||
Matrix4f matrix = new Matrix4f();
|
||||
matrix.setIdentity();
|
||||
matrix.setRotation( new AxisAngle4f( 0, 1, 0, rotation ) );
|
||||
matrix.mul( new Quaternion( 0, rotation, 0, false ) );
|
||||
|
||||
MatrixVertexTransformer transformer = new MatrixVertexTransformer( matrix );
|
||||
for( BakedQuad bakedQuad : this.pointer.getQuads( state, side, rand ) )
|
||||
for( BakedQuad bakedQuad : this.pointer.getQuads( state, side, rand, extraData ) )
|
||||
{
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder( bakedQuad.getFormat() );
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||
|
||||
transformer.setParent( builder );
|
||||
transformer.setVertexFormat( builder.getVertexFormat() );
|
||||
bakedQuad.pipe( transformer );
|
||||
builder.setQuadOrientation( null ); // After rotation, facing a specific side cannot be guaranteed
|
||||
// FIXME: This entire code is no longer truly valid...
|
||||
// FIXME builder.setQuadOrientation( null ); // After rotation, facing a specific side cannot be guaranteed
|
||||
// anymore
|
||||
BakedQuad q = builder.build();
|
||||
quads.add( q );
|
||||
@@ -129,6 +127,11 @@ public class SkyCompassBakedModel implements IBakedModel
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_230044_c_() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
@@ -155,13 +158,12 @@ public class SkyCompassBakedModel implements IBakedModel
|
||||
* animate using the
|
||||
* spinning animation.
|
||||
*/
|
||||
return new ItemOverrideList( Collections.emptyList() )
|
||||
return new ItemOverrideList()
|
||||
{
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState( IBakedModel originalModel, ItemStack stack, World world, LivingEntity entity )
|
||||
{
|
||||
if( world != null && entity instanceof PlayerEntitySP )
|
||||
public IBakedModel getModelWithOverrides(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable LivingEntity entity) {
|
||||
// FIXME: This check prevents compasses being held by OTHERS from getting the rotation, BUT do we actually still need this???
|
||||
if (world != null && entity instanceof ClientPlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) entity;
|
||||
|
||||
@@ -186,38 +188,38 @@ public class SkyCompassBakedModel implements IBakedModel
|
||||
{
|
||||
|
||||
// Only query for a meteor position if we know our own position
|
||||
if( pos != null )
|
||||
{
|
||||
CompassResult cr = CompassManager.INSTANCE.getCompassDirection( 0, pos.getX(), pos.getY(), pos.getZ() );
|
||||
|
||||
// Prefetch meteor positions from the server for adjacent blocks so they are available more quickly when
|
||||
// we're moving
|
||||
if( prefetch )
|
||||
{
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
for( int j = 0; j < 3; j++ )
|
||||
{
|
||||
CompassManager.INSTANCE.getCompassDirection( 0, pos.getX() + i - 1, pos.getY(), pos.getZ() + j - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( cr.isValidResult() )
|
||||
{
|
||||
if( cr.isSpin() )
|
||||
{
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
// .5 seconds per full rotation
|
||||
timeMillis %= 500;
|
||||
return timeMillis / 500.f * (float) Math.PI * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (float) cr.getRad();
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME if( pos != null )
|
||||
// FIXME {
|
||||
// FIXME CompassResult cr = CompassManager.INSTANCE.getCompassDirection( 0, pos.getX(), pos.getY(), pos.getZ() );
|
||||
// FIXME
|
||||
// FIXME // Prefetch meteor positions from the server for adjacent blocks so they are available more quickly when
|
||||
// FIXME // we're moving
|
||||
// FIXME if( prefetch )
|
||||
// FIXME {
|
||||
// FIXME for( int i = 0; i < 3; i++ )
|
||||
// FIXME {
|
||||
// FIXME for( int j = 0; j < 3; j++ )
|
||||
// FIXME {
|
||||
// FIXME CompassManager.INSTANCE.getCompassDirection( 0, pos.getX() + i - 1, pos.getY(), pos.getZ() + j - 1 );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME
|
||||
// FIXME if( cr.isValidResult() )
|
||||
// FIXME {
|
||||
// FIXME if( cr.isSpin() )
|
||||
// FIXME {
|
||||
// FIXME long timeMillis = System.currentTimeMillis();
|
||||
// FIXME // .5 seconds per full rotation
|
||||
// FIXME timeMillis %= 500;
|
||||
// FIXME return timeMillis / 500.f * (float) Math.PI * 2;
|
||||
// FIXME }
|
||||
// FIXME else
|
||||
// FIXME {
|
||||
// FIXME return (float) cr.getRad();
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
// 3 seconds per full rotation
|
||||
|
||||
@@ -19,69 +19,44 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
|
||||
/**
|
||||
* The parent model for the compass baked model. Declares the dependencies for the base and pointer submodels mostly.
|
||||
*/
|
||||
public class SkyCompassModel implements IModel
|
||||
public class SkyCompassModel implements IModelGeometry<SkyCompassModel>
|
||||
{
|
||||
|
||||
private static final ResourceLocation MODEL_BASE = new ResourceLocation( "appliedenergistics2:block/sky_compass_base" );
|
||||
|
||||
private static final ResourceLocation MODEL_POINTER = new ResourceLocation( "appliedenergistics2:block/sky_compass_pointer" );
|
||||
|
||||
private static final List<ResourceLocation> DEPENDENCIES = ImmutableList.of( MODEL_BASE, MODEL_POINTER );
|
||||
public static final List<ResourceLocation> DEPENDENCIES = ImmutableList.of( MODEL_BASE, MODEL_POINTER );
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return DEPENDENCIES;
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) {
|
||||
IBakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
IBakedModel pointerModel = bakery.getBakedModel(MODEL_POINTER, modelTransform, spriteGetter);
|
||||
|
||||
return new SkyCompassBakedModel( baseModel, pointerModel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||
{
|
||||
IModel baseModel, pointerModel;
|
||||
try
|
||||
{
|
||||
baseModel = ModelLoaderRegistry.getModel( MODEL_BASE );
|
||||
pointerModel = ModelLoaderRegistry.getModel( MODEL_POINTER );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
|
||||
IBakedModel bakedBase = baseModel.bake( state, format, bakedTextureGetter );
|
||||
IBakedModel bakedPointer = pointerModel.bake( state, format, bakedTextureGetter );
|
||||
return new SkyCompassBakedModel( bakedBase, bakedPointer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Allows the built-in sky compass model the be loaded from JSON.
|
||||
*/
|
||||
public class SkyCompassModelLoader implements IModelLoader<SkyCompassModel> {
|
||||
|
||||
public static final SkyCompassModelLoader INSTANCE = new SkyCompassModelLoader();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkyCompassModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
|
||||
return new SkyCompassModel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,17 +19,23 @@
|
||||
package appeng.client.render.tesr;
|
||||
|
||||
|
||||
import appeng.client.render.model.SkyCompassModel;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.client.model.animation.FastTESR;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -41,56 +47,52 @@ import appeng.tile.misc.TileSkyCompass;
|
||||
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public class SkyCompassTESR extends FastTESR<TileSkyCompass>
|
||||
public class SkyCompassTESR extends TileEntityRenderer<TileSkyCompass>
|
||||
{
|
||||
|
||||
private static BlockRendererDispatcher blockRenderer;
|
||||
|
||||
@Override
|
||||
public void renderTileEntityFast( TileSkyCompass te, double x, double y, double z, float partialTicks, int destroyStage, float var10, BufferBuilder buffer )
|
||||
{
|
||||
public SkyCompassTESR(TileEntityRendererDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
if( !te.hasWorld() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void render(TileSkyCompass te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int combinedLightIn, int combinedOverlayIn) {
|
||||
|
||||
if( blockRenderer == null )
|
||||
{
|
||||
blockRenderer = Minecraft.getInstance().getBlockRendererDispatcher();
|
||||
}
|
||||
|
||||
BlockPos pos = te.getPos();
|
||||
IBlockReader world = MinecraftForgeClient.getRegionRenderCache( te.getWorld(), pos );
|
||||
BlockState state = world.getBlockState( pos );
|
||||
if( state.getPropertyKeys().contains( Properties.StaticProperty ) )
|
||||
{
|
||||
state = state.with( Properties.StaticProperty, false );
|
||||
}
|
||||
IVertexBuilder buffer = buffers.getBuffer(Atlases.getTranslucentBlockType());
|
||||
|
||||
if( state instanceof IExtendedBlockState )
|
||||
{
|
||||
IExtendedBlockState exState = (IExtendedBlockState) state.getBlock().getExtendedState( state, world, pos );
|
||||
BlockState blockState = te.getBlockState();
|
||||
IBakedModel model = blockRenderer.getBlockModelShapes().getModel( blockState );
|
||||
|
||||
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState( exState.getClean() );
|
||||
exState = exState.with( BlockSkyCompass.ROTATION, getRotation( te ) );
|
||||
ModelDataMap modelData = new ModelDataMap.Builder()
|
||||
.withInitial(SkyCompassBakedModel.ROTATION, getRotation(te))
|
||||
.build();
|
||||
|
||||
// Flip forward/up for rendering, the base model is facing up without any rotation
|
||||
Direction forward = exState.getValue( AEBaseTileBlock.FORWARD );
|
||||
Direction up = exState.getValue( AEBaseTileBlock.UP );
|
||||
// This ensures the needle isn't flipped by the model rotator. Since the model is symmetrical, this should
|
||||
// not affect the appearance
|
||||
if( forward == Direction.UP || forward == Direction.DOWN )
|
||||
{
|
||||
up = Direction.NORTH;
|
||||
}
|
||||
exState = exState.with( AEBaseTileBlock.FORWARD, up )
|
||||
.with( AEBaseTileBlock.UP, forward );
|
||||
ms.push();
|
||||
// FIXME: Rotation was previously handled by an auto rotating model I think, but
|
||||
// FIXME: Should be handled using matrices instead
|
||||
// // Flip forward/up for rendering, the base model is facing up without any rotation
|
||||
// Direction forward = exState.getValue( AEBaseTileBlock.FORWARD );
|
||||
// Direction up = exState.getValue( AEBaseTileBlock.UP );
|
||||
// // This ensures the needle isn't flipped by the model rotator. Since the model is symmetrical, this should
|
||||
// // not affect the appearance
|
||||
// if( forward == Direction.UP || forward == Direction.DOWN )
|
||||
// {
|
||||
// up = Direction.NORTH;
|
||||
// }
|
||||
// exState = exState.with( AEBaseTileBlock.FORWARD, up )
|
||||
// .with( AEBaseTileBlock.UP, forward );
|
||||
//
|
||||
// buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
||||
|
||||
buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
||||
blockRenderer.getBlockModelRenderer().renderModel( ms.getLast(), buffer, null, model, 1, 1, 1, combinedLightIn, combinedOverlayIn, modelData );
|
||||
ms.pop();
|
||||
|
||||
blockRenderer.getBlockModelRenderer().renderModel( world, model, exState, pos, buffer, false );
|
||||
}
|
||||
}
|
||||
|
||||
private static float getRotation( TileSkyCompass skyCompass )
|
||||
|
||||
Reference in New Issue
Block a user