Working on drive design.

Several particle crash fixes.
This commit is contained in:
Sebastian Hartte
2020-06-15 22:20:29 +02:00
parent 2356a38898
commit d50dcc31fa
33 changed files with 748 additions and 760 deletions
@@ -56,7 +56,7 @@ public class LightningFX extends SpriteTexturedParticle
private final double[] verticesWithUV = new double[3];
private boolean hasData = false;
public LightningFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b )
private LightningFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b )
{
this( w, x, y, z, r, g, b, 6 );
this.regen();
@@ -117,7 +117,6 @@ public class LightningFX extends SpriteTexturedParticle
@Override
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
Vec3d vec3d = renderInfo.getProjectedView();
float centerX = (float)(MathHelper.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX());
float centerY = (float)(MathHelper.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY());
@@ -74,6 +74,11 @@ public class AutoRotatingBakedModel implements IBakedModel
private List<BakedQuad> getRotatedModel(BlockState state, Direction side, Random rand, AEModelData modelData)
{
FacingToRotation f2r = FacingToRotation.get( modelData.getForward(), modelData.getUp() );
if (f2r.isRedundant()) {
return AutoRotatingBakedModel.this.parent.getQuads( state, side, rand, modelData );
}
List<BakedQuad> original = AutoRotatingBakedModel.this.parent.getQuads( state, f2r.resultingRotate( side ), rand, modelData );
List<BakedQuad> rotated = new ArrayList<>( original.size() );
for( BakedQuad quad : original )
@@ -19,14 +19,17 @@
package appeng.client.render.model;
import appeng.block.storage.DriveSlotState;
import appeng.api.definitions.IItems;
import appeng.block.storage.DriveSlotCellType;
import appeng.block.storage.DriveSlotsState;
import appeng.client.render.DelegateBakedModel;
import appeng.tile.storage.TileDrive;
import appeng.core.Api;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.Matrix4f;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
@@ -41,13 +44,11 @@ import java.util.Random;
public class DriveBakedModel extends DelegateBakedModel
{
private final IBakedModel bakedBase;
private final Map<DriveSlotState, IBakedModel> bakedCells;
private final Map<DriveSlotCellType, IBakedModel> bakedCells;
public DriveBakedModel( IBakedModel bakedBase, Map<DriveSlotState, IBakedModel> bakedCells )
public DriveBakedModel( IBakedModel bakedBase, Map<DriveSlotCellType, IBakedModel> bakedCells )
{
super(bakedBase);
this.bakedBase = bakedBase;
this.bakedCells = bakedCells;
}
@@ -55,7 +56,7 @@ public class DriveBakedModel extends DelegateBakedModel
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
List<BakedQuad> result = new ArrayList<>(this.bakedBase.getQuads(state, side, rand, extraData));
List<BakedQuad> result = new ArrayList<>(super.getQuads(state, side, rand, extraData));
if (!(extraData instanceof DriveModelData)) {
return result;
@@ -70,29 +71,20 @@ public class DriveBakedModel extends DelegateBakedModel
{
for( int col = 0; col < 2; col++ )
{
DriveSlotState slotState = slotsState.getState( row * 2 + col );
IBakedModel bakedCell = this.bakedCells.get( slotState );
Matrix4f transform = new Matrix4f();
transform.setIdentity();
// Position this drive model copy at the correct slot. The transform is based on the
// cell-model being in slot 0,0 at the top left of the drive.
float xOffset = -col * 7 / 16.0f;
float yOffset = -row * 3 / 16.0f;
transform.setTranslation( xOffset, yOffset, 0 );
MatrixVertexTransformer transformer = new MatrixVertexTransformer( transform );
for( BakedQuad bakedQuad : bakedCell.getQuads( state, null, rand, extraData ) )
{
BakedQuadBuilder builder = new BakedQuadBuilder();
transformer.setParent( builder );
transformer.setVertexFormat( builder.getVertexFormat() );
bakedQuad.pipe( transformer );
result.add( builder.build() );
}
int slot = row * 2 + col;
// Add the drive chassis
Item cell = slotsState.getCell(slot);
IBakedModel cellChassisModel = getCellChassisModel(cell);
addModel(state, rand, extraData, result, cellChassisModel, transform);
}
}
}
@@ -100,4 +92,40 @@ public class DriveBakedModel extends DelegateBakedModel
return result;
}
@Override
public boolean isAmbientOcclusion() {
// We have faces inside the chassis that are facing east, but should not receive
// ambient occlusion from the east-side, but sadly this cannot be fine-tuned on a
// face-by-face basis.
return false;
}
// Determine which drive chassis to show based on the used cell
private IBakedModel getCellChassisModel(Item cell) {
IItems items = Api.INSTANCE.definitions().items();
if (cell == null) {
return bakedCells.get(DriveSlotCellType.EMPTY);
} else if (items.fluidCell1k().item() == cell
|| items.fluidCell4k().item() == cell
|| items.fluidCell16k().item() == cell
|| items.fluidCell64k().item() == cell) {
return bakedCells.get(DriveSlotCellType.FLUID);
} else {
// Fall back to an item model
return bakedCells.get(DriveSlotCellType.ITEM);
}
}
private static void addModel(@Nullable BlockState state, @Nonnull Random rand, @Nonnull IModelData extraData, List<BakedQuad> result, IBakedModel bakedCell, Matrix4f transform) {
MatrixVertexTransformer transformer = new MatrixVertexTransformer( transform );
for( BakedQuad bakedQuad : bakedCell.getQuads( state, null, rand, extraData ) )
{
BakedQuadBuilder builder = new BakedQuadBuilder();
transformer.setParent( builder );
transformer.setVertexFormat( builder.getVertexFormat() );
bakedQuad.pipe( transformer );
result.add( builder.build() );
}
}
}
@@ -19,6 +19,7 @@
package appeng.client.render.model;
import appeng.block.storage.DriveSlotCellType;
import appeng.block.storage.DriveSlotState;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -36,14 +37,13 @@ import java.util.function.Function;
public class DriveModel implements IModelGeometry<DriveModel>
{
private static final ResourceLocation MODEL_BASE = new ResourceLocation( "appliedenergistics2:block/drive_base" );
private static final ResourceLocation MODEL_BASE = new ResourceLocation( "appliedenergistics2:block/drive/drive_base" );
private static final Map<DriveSlotState, ResourceLocation> MODELS_CELLS = ImmutableMap.of(
DriveSlotState.EMPTY, new ResourceLocation( "appliedenergistics2:block/drive_cell_empty" ),
DriveSlotState.OFFLINE, new ResourceLocation( "appliedenergistics2:block/drive_cell_off" ),
DriveSlotState.ONLINE, new ResourceLocation( "appliedenergistics2:block/drive_cell_on" ),
DriveSlotState.TYPES_FULL, new ResourceLocation( "appliedenergistics2:block/drive_cell_types_full" ),
DriveSlotState.FULL, new ResourceLocation( "appliedenergistics2:block/drive_cell_full" ) );
private static final Map<DriveSlotCellType, ResourceLocation> MODELS_CELLS = ImmutableMap.of(
DriveSlotCellType.EMPTY, new ResourceLocation( "appliedenergistics2:block/drive/drive_cell_empty" ),
DriveSlotCellType.ITEM, new ResourceLocation( "appliedenergistics2:block/drive/drive_cell_items" ),
DriveSlotCellType.FLUID, new ResourceLocation( "appliedenergistics2:block/drive/drive_cell_fluids" )
);
public static final Set<ResourceLocation> DEPENDENCIES = ImmutableSet.<ResourceLocation>builder()
.addAll(MODELS_CELLS.values())
@@ -52,13 +52,13 @@ public class DriveModel implements IModelGeometry<DriveModel>
@Override
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) {
EnumMap<DriveSlotState, IBakedModel> cellModels = new EnumMap<>( DriveSlotState.class );
EnumMap<DriveSlotCellType, IBakedModel> cellModels = new EnumMap<>( DriveSlotCellType.class );
// Load the base model and the model for each cell state.
for( DriveSlotState slotState : MODELS_CELLS.keySet() )
for( DriveSlotCellType cellType : MODELS_CELLS.keySet() )
{
IBakedModel cellModel = bakery.getBakedModel( MODELS_CELLS.get( slotState ), modelTransform, spriteGetter );
cellModels.put( slotState, cellModel );
IBakedModel cellModel = bakery.getBakedModel( MODELS_CELLS.get( cellType ), modelTransform, spriteGetter );
cellModels.put( cellType, cellModel );
}
IBakedModel baseModel = bakery.getBakedModel( MODEL_BASE, modelTransform, spriteGetter );
@@ -0,0 +1,158 @@
package appeng.client.render.tesr;
import appeng.block.storage.DriveSlotState;
import appeng.client.render.FacingToRotation;
import appeng.client.render.cablebus.CubeBuilder;
import appeng.tile.storage.TileDrive;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import javafx.scene.DepthTest;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.lwjgl.system.MathUtil;
import java.util.EnumMap;
import java.util.EnumSet;
/**
* Renders the drive cell status indicators.
*/
@OnlyIn(Dist.CLIENT)
public class DriveLedTileEntityRenderer extends TileEntityRenderer<TileDrive> {
private static final EnumMap<DriveSlotState, Vector3f> STATE_COLORS;
// Color used for the cell indicator for blinking during recent activity
private static final Vector3f BLINK_COLOR = new Vector3f(1, 0.5f, 0.5f);
static {
STATE_COLORS = new EnumMap<>(DriveSlotState.class);
STATE_COLORS.put(DriveSlotState.OFFLINE, new Vector3f(0, 0, 0));
STATE_COLORS.put(DriveSlotState.ONLINE, new Vector3f(0, 1, 0));
STATE_COLORS.put(DriveSlotState.TYPES_FULL, new Vector3f(0, 0.667f, 0));
STATE_COLORS.put(DriveSlotState.FULL, new Vector3f(1, 0, 0));
}
private static final float L = 14/16.f; // left (x-axis)
private static final float R = 13/16.f; // right (x-axis)
private static final float T = 14/16.f; // top (x-axis)
private static final float B = 12.999f/16.f; // bottom (x-axis)
private static final float FR = 0.4f/16.f; // front (z-axis)
private static final float BA = 1/16.f; // back (z-axis)
// Vertex data for the LED cuboid (has no back)
// Directions are when looking from the front onto the LED
private static final float[] LED_QUADS = {
// Front Face
R, T, FR,
L, T, FR,
L, B, FR,
R, B, FR,
// Left Face
L, T, FR,
L, T, BA,
L, B, BA,
L, B, FR,
// Right Face
R, T, BA,
R, T, FR,
R, B, FR,
R, B, BA,
// Top Face
R, T, BA,
L, T, BA,
L, T, FR,
R, T, FR,
// Bottom Face
R, B, FR,
L, B, FR,
L, B, BA,
R, B, BA,
};
private static final RenderType STATE = RenderType.makeType("ae_drive_leds", DefaultVertexFormats.POSITION_COLOR, 7, 32565, false, true, RenderType.State.getBuilder()
.build(false));
public DriveLedTileEntityRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
}
@Override
public void render(TileDrive drive, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int combinedLightIn, int combinedOverlayIn) {
if (drive.getCellCount() != 10) {
throw new IllegalStateException("Expected drive to have 10 slots");
}
ms.push();
ms.translate(0.5, 0.5, 0.5);
FacingToRotation.get(drive.getForward(), drive.getUp()).push(ms);
ms.translate(-0.5, -0.5, -0.5);
RenderState.TransparencyState TRANSLUCENT_TRANSPARENCY = ObfuscationReflectionHelper.getPrivateValue(RenderState.class, null, "field_228515_g_");
RenderType rt =RenderType.makeType("ae_drive_leds", DefaultVertexFormats.POSITION_COLOR, 7, 32565, false, true, RenderType.State.getBuilder()
.transparency(TRANSLUCENT_TRANSPARENCY)
.build(false));
IVertexBuilder buffer = buffers.getBuffer(STATE);
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 2; col++) {
int slot = row * 2 + col;
Vector3f color = getColorForSlot(drive, slot, partialTicks);
if (color == null) {
continue;
}
ms.push();
// Position this drive model copy at the correct slot. The transform is based on the
// cell-model being in slot 0,0 at the top left of the drive.
float xOffset = -col * 7 / 16.0f;
float yOffset = -row * 3 / 16.0f;
ms.translate(xOffset, yOffset, 0);
for (int i = 0; i < LED_QUADS.length; i += 3) {
float x = LED_QUADS[i];
float y = LED_QUADS[i+1];
float z = LED_QUADS[i+2];
buffer.pos(ms.getLast().getMatrix(), x, y, z).color(color.getX(), color.getY(), color.getZ(), 1.f).endVertex();
}
ms.pop();
}
}
ms.pop();
}
private Vector3f getColorForSlot(TileDrive drive, int slot, float partialTicks) {
DriveSlotState state = DriveSlotState.fromCellStatus(drive.getCellStatus(slot));
if (state == DriveSlotState.EMPTY) {
return null;
}
Vector3f col = STATE_COLORS.get(state);
if (drive.isCellBlinking(slot)) {
// 200 ms interval (100ms to get to red, then 100ms back)
long t = System.currentTimeMillis() % 200;
float f = (t - 100) / 200.0f + 0.5f;
f = easeInOutCubic(f);
col = col.copy();
col.lerp(BLINK_COLOR, f);
}
return col;
}
private static float easeInOutCubic(float x) {
return x < 0.5f ? 4 * x * x * x : 1 - (float) Math.pow(-2 * x + 2, 3) / 2;
}
}