pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,7 +18,6 @@
package appeng.client.render.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -26,8 +25,6 @@ import java.util.Random;
import javax.annotation.Nullable;
import appeng.hooks.CompassManager;
import appeng.hooks.CompassResult;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.renderer.Matrix4f;
@@ -44,188 +41,172 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.data.IDynamicBakedModel;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelProperty;
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
import appeng.hooks.CompassManager;
import appeng.hooks.CompassResult;
/**
* 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.
* 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 IDynamicBakedModel
{
// Rotation is expressed as radians
public static final ModelProperty<Float> ROTATION = new ModelProperty<>();
public class SkyCompassBakedModel implements IDynamicBakedModel {
// Rotation is expressed as radians
public static final ModelProperty<Float> ROTATION = new ModelProperty<>();
private final IBakedModel base;
private final IBakedModel base;
private final IBakedModel pointer;
private final IBakedModel pointer;
private float fallbackRotation = 0;
private float fallbackRotation = 0;
public SkyCompassBakedModel( IBakedModel base, IBakedModel pointer )
{
this.base = base;
this.pointer = pointer;
}
public SkyCompassBakedModel(IBakedModel base, IBakedModel pointer) {
this.base = base;
this.pointer = pointer;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData )
{
float rotation = 0;
// Get rotation from the special block state
Float rotationFromData = extraData.getData(ROTATION);
if (rotationFromData != null) {
rotation = rotationFromData;
}
else
{
// This is used to render a compass pointing in a specific direction when being held in hand
rotation = this.fallbackRotation;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand,
IModelData extraData) {
float rotation = 0;
// Get rotation from the special block state
Float rotationFromData = extraData.getData(ROTATION);
if (rotationFromData != null) {
rotation = rotationFromData;
} else {
// This is used to render a compass pointing in a specific direction when being
// held in hand
rotation = this.fallbackRotation;
}
// Pre-compute the quad count to avoid list resizes
List<BakedQuad> quads = new ArrayList<>();
quads.addAll( this.base.getQuads( state, side, rand, extraData ) );
// Pre-compute the quad count to avoid list resizes
List<BakedQuad> quads = new ArrayList<>();
quads.addAll(this.base.getQuads(state, side, rand, extraData));
// We'll add the pointer as "sideless"
if( side == null )
{
// Set up the rotation around the Y-axis for the pointer
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
matrix.mul( new Quaternion( 0, rotation, 0, false ) );
// We'll add the pointer as "sideless"
if (side == null) {
// Set up the rotation around the Y-axis for the pointer
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
matrix.mul(new Quaternion(0, rotation, 0, false));
MatrixVertexTransformer transformer = new MatrixVertexTransformer( matrix );
for( BakedQuad bakedQuad : this.pointer.getQuads( state, side, rand, extraData ) )
{
BakedQuadBuilder builder = new BakedQuadBuilder();
MatrixVertexTransformer transformer = new MatrixVertexTransformer(matrix);
for (BakedQuad bakedQuad : this.pointer.getQuads(state, side, rand, extraData)) {
BakedQuadBuilder builder = new BakedQuadBuilder();
transformer.setParent( builder );
transformer.setVertexFormat( builder.getVertexFormat() );
bakedQuad.pipe( transformer );
// 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 );
}
}
transformer.setParent(builder);
transformer.setVertexFormat(builder.getVertexFormat());
bakedQuad.pipe(transformer);
// 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);
}
}
return quads;
}
return quads;
}
@Override
public boolean isAmbientOcclusion()
{
return this.base.isAmbientOcclusion();
}
@Override
public boolean isAmbientOcclusion() {
return this.base.isAmbientOcclusion();
}
@Override
public boolean isGui3d()
{
return true;
}
@Override
public boolean isGui3d() {
return true;
}
@Override
public boolean func_230044_c_() {
return false;
}
@Override
public boolean func_230044_c_() {
return false;
}
@Override
public boolean isBuiltInRenderer()
{
return false;
}
@Override
public boolean isBuiltInRenderer() {
return false;
}
@Override
public TextureAtlasSprite getParticleTexture()
{
return this.base.getParticleTexture();
}
@Override
public TextureAtlasSprite getParticleTexture() {
return this.base.getParticleTexture();
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return this.base.getItemCameraTransforms();
}
@Override
public ItemCameraTransforms getItemCameraTransforms() {
return this.base.getItemCameraTransforms();
}
@Override
public ItemOverrideList getOverrides()
{
/*
* This handles setting the rotation of the compass when being held in hand. If it's not held in hand, it'll
* animate using the
* spinning animation.
*/
return new ItemOverrideList()
{
@Override
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;
@Override
public ItemOverrideList getOverrides() {
/*
* This handles setting the rotation of the compass when being held in hand. If
* it's not held in hand, it'll animate using the spinning animation.
*/
return new ItemOverrideList() {
@Override
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;
float offRads = (float) ( player.rotationYaw / 180.0f * (float) Math.PI + Math.PI );
float offRads = (float) (player.rotationYaw / 180.0f * (float) Math.PI + Math.PI);
SkyCompassBakedModel.this.fallbackRotation = offRads + getAnimatedRotation( player.getPosition(), true );
}
else
{
SkyCompassBakedModel.this.fallbackRotation = getAnimatedRotation( null, false );
}
SkyCompassBakedModel.this.fallbackRotation = offRads
+ getAnimatedRotation(player.getPosition(), true);
} else {
SkyCompassBakedModel.this.fallbackRotation = getAnimatedRotation(null, false);
}
return originalModel;
}
};
}
return originalModel;
}
};
}
/**
* Gets the effective, animated rotation for the compass given the current position of the compass.
*/
public static float getAnimatedRotation( @Nullable BlockPos pos, boolean prefetch )
{
/**
* Gets the effective, animated rotation for the compass given the current
* position of the compass.
*/
public static float getAnimatedRotation(@Nullable BlockPos pos, boolean prefetch) {
// 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() );
// 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 );
}
}
}
// 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();
}
}
}
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();
}
}
}
long timeMillis = System.currentTimeMillis();
// 3 seconds per full rotation
timeMillis %= 3000;
return timeMillis / 3000.f * (float) Math.PI * 2;
}
long timeMillis = System.currentTimeMillis();
// 3 seconds per full rotation
timeMillis %= 3000;
return timeMillis / 3000.f * (float) Math.PI * 2;
}
}