Cables work

This commit is contained in:
Sebastian Hartte
2020-07-02 10:16:03 +02:00
parent c7b1ab756b
commit 75234415ac
10 changed files with 198 additions and 210 deletions
@@ -24,6 +24,7 @@ import net.fabricmc.api.Environment;
import appeng.bootstrap.BlockRenderingCustomizer;
import appeng.bootstrap.IBlockRendering;
import appeng.bootstrap.IItemRendering;
import net.minecraft.client.render.RenderLayer;
/**
* Customizes the rendering behavior for cable busses, which are the biggest
@@ -36,6 +37,7 @@ public class CableBusRendering extends BlockRenderingCustomizer {
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
// FIXME This is straight up impossible in Vanilla, and questionable if it's actually needed.
// FIXME rendering.renderType(rt -> true);
rendering.renderType(RenderLayer.getCutout());
rendering.blockColor(new CableBusColor());
rendering.modelCustomizer((loc, model) -> model);
@@ -2,8 +2,10 @@ package appeng.client;
import appeng.api.parts.CableRenderMode;
import appeng.bootstrap.ModelsReloadCallback;
import appeng.bootstrap.components.IClientSetupComponent;
import appeng.bootstrap.components.IItemColorRegistrationComponent;
import appeng.bootstrap.components.IModelBakeComponent;
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
import appeng.client.render.cablebus.CableBusModelLoader;
import appeng.client.render.effects.*;
import appeng.client.render.tesr.SkyChestTESR;
@@ -66,6 +68,8 @@ public final class AppEngClient extends AppEngBase {
ModelsReloadCallback.EVENT.register(this::onModelsReloaded);
callDeferredBootstrapComponents(IClientSetupComponent.class,
IClientSetupComponent::setup);
registerModelProviders();
registerParticleRenderers();
registerEntityRenderers();
@@ -25,7 +25,9 @@ import java.util.EnumSet;
import java.util.List;
import java.util.function.Function;
import net.minecraft.client.render.model.BakedQuad;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.texture.Sprite;
@@ -39,13 +41,15 @@ import appeng.core.AppEng;
/**
* A helper class that builds quads for cable connections.
*/
@Environment(EnvType.CLIENT)
class CableBuilder {
// Textures for the cable core types, one per type/color pair
private final EnumMap<CableCoreType, EnumMap<AEColor, Sprite>> coreTextures;
// Textures for rendering the actual connection cubes, one per type/color pair
private final EnumMap<AECableType, EnumMap<AEColor, Sprite>> connectionTextures;
// FIXME
public final EnumMap<AECableType, EnumMap<AEColor, Sprite>> connectionTextures;
private final SmartCableTextures smartCableTextures;
@@ -108,25 +112,25 @@ class CableBuilder {
*
* The type of cable core is automatically deduced from the given cable type.
*/
public void addCableCore(AECableType cableType, AEColor color, List<BakedQuad> quadsOut) {
public void addCableCore(AECableType cableType, AEColor color, QuadEmitter emitter) {
switch (cableType) {
case GLASS:
this.addCableCore(CableCoreType.GLASS, color, quadsOut);
this.addCableCore(CableCoreType.GLASS, color, emitter);
break;
case COVERED:
case SMART:
this.addCableCore(CableCoreType.COVERED, color, quadsOut);
this.addCableCore(CableCoreType.COVERED, color, emitter);
break;
case DENSE_COVERED:
case DENSE_SMART:
this.addCableCore(CableCoreType.DENSE, color, quadsOut);
this.addCableCore(CableCoreType.DENSE, color, emitter);
break;
default:
}
}
public void addCableCore(CableCoreType coreType, AEColor color, List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
public void addCableCore(CableCoreType coreType, AEColor color, QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.coreTextures.get(coreType).get(color);
cubeBuilder.setTexture(texture);
@@ -145,8 +149,8 @@ class CableBuilder {
}
public void addGlassConnection(Direction facing, AEColor cableColor, AECableType connectionType,
boolean cableBusAdjacent, List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
boolean cableBusAdjacent, QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
@@ -184,8 +188,8 @@ class CableBuilder {
}
}
public void addStraightGlassConnection(Direction facing, AEColor cableColor, List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
public void addStraightGlassConnection(Direction facing, AEColor cableColor, QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
// We render all faces except the connection caps. We can do this because the
// glass cable is the smallest one
@@ -212,14 +216,14 @@ class CableBuilder {
}
public void addConstrainedGlassConnection(Direction facing, AEColor cableColor, int distanceFromEdge,
List<BakedQuad> quadsOut) {
QuadEmitter emitter) {
// Glass connections reach only 6 voxels from the edge
if (distanceFromEdge >= 6) {
return;
}
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.GLASS).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -247,9 +251,9 @@ class CableBuilder {
}
public void addCoveredConnection(Direction facing, AEColor cableColor, AECableType connectionType,
boolean cableBusAdjacent, List<BakedQuad> quadsOut) {
boolean cableBusAdjacent, QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
@@ -265,8 +269,8 @@ class CableBuilder {
addCoveredCableSizedCube(facing, cubeBuilder);
}
public void addStraightCoveredConnection(Direction facing, AEColor cableColor, List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
public void addStraightCoveredConnection(Direction facing, AEColor cableColor, QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.COVERED).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -303,14 +307,14 @@ class CableBuilder {
}
public void addConstrainedCoveredConnection(Direction facing, AEColor cableColor, int distanceFromEdge,
List<BakedQuad> quadsOut) {
QuadEmitter emitter) {
// The core of a covered cable reaches up to 5 voxels from the block edge, so
// drawing a connection can only occur from there onwards
if (distanceFromEdge >= 5) {
return;
}
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.COVERED).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -319,13 +323,13 @@ class CableBuilder {
}
public void addSmartConnection(Direction facing, AEColor cableColor, AECableType connectionType,
boolean cableBusAdjacent, int channels, List<BakedQuad> quadsOut) {
boolean cableBusAdjacent, int channels, QuadEmitter emitter) {
if (connectionType == AECableType.COVERED || connectionType == AECableType.GLASS) {
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, emitter);
return;
}
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
@@ -371,8 +375,8 @@ class CableBuilder {
}
public void addStraightSmartConnection(Direction facing, AEColor cableColor, int channels,
List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.SMART).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -397,7 +401,7 @@ class CableBuilder {
}
public void addConstrainedSmartConnection(Direction facing, AEColor cableColor, int distanceFromEdge, int channels,
List<BakedQuad> quadsOut) {
QuadEmitter emitter) {
// Same as with covered cables, the smart cable's core extends up to 5 voxels
// away from the edge.
// Drawing a connection to any point before that point is fruitless
@@ -405,7 +409,7 @@ class CableBuilder {
return;
}
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.SMART).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -428,16 +432,16 @@ class CableBuilder {
}
public void addDenseCoveredConnection(Direction facing, AEColor cableColor, AECableType connectionType,
boolean cableBusAdjacent, List<BakedQuad> quadsOut) {
boolean cableBusAdjacent, QuadEmitter emitter) {
// Dense cables only render their connections as dense if the adjacent blocks
// actually wants that
if (connectionType == AECableType.COVERED || connectionType == AECableType.SMART
|| connectionType == AECableType.GLASS) {
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, emitter);
return;
}
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
@@ -453,21 +457,21 @@ class CableBuilder {
}
public void addDenseSmartConnection(Direction facing, AEColor cableColor, AECableType connectionType,
boolean cableBusAdjacent, int channels, List<BakedQuad> quadsOut) {
boolean cableBusAdjacent, int channels, QuadEmitter emitter) {
// Dense cables only render their connections as dense if the adjacent blocks
// actually wants that
if (connectionType == AECableType.SMART) {
this.addSmartConnection(facing, cableColor, connectionType, cableBusAdjacent, channels, quadsOut);
this.addSmartConnection(facing, cableColor, connectionType, cableBusAdjacent, channels, emitter);
return;
} else if (connectionType == AECableType.COVERED || connectionType == AECableType.GLASS) {
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, emitter);
return;
} else if (connectionType == AECableType.DENSE_COVERED) {
this.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
this.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, emitter);
return;
}
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
@@ -499,8 +503,8 @@ class CableBuilder {
cubeBuilder.setTexture(texture);
}
public void addStraightDenseCoveredConnection(Direction facing, AEColor cableColor, List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
public void addStraightDenseCoveredConnection(Direction facing, AEColor cableColor, QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.DENSE_COVERED).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -511,8 +515,8 @@ class CableBuilder {
}
public void addStraightDenseSmartConnection(Direction facing, AEColor cableColor, int channels,
List<BakedQuad> quadsOut) {
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
QuadEmitter emitter) {
CubeBuilder cubeBuilder = new CubeBuilder(emitter);
Sprite texture = this.connectionTextures.get(AECableType.DENSE_SMART).get(cableColor);
cubeBuilder.setTexture(texture);
@@ -21,7 +21,12 @@ package appeng.client.render.cablebus;
import appeng.api.parts.IPartModel;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
@@ -48,8 +53,11 @@ import java.util.*;
import java.util.Map.Entry;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
public class CableBusBakedModel implements BakedModel, FabricBakedModel {
private static final Renderer RENDERER = RendererAccess.INSTANCE.getRenderer();
// FIXME: This entire cache seems dumb as shit
private static final Map<CableBusRenderState, Mesh> CABLE_MODEL_CACHE = new HashMap<>();
@@ -94,46 +102,39 @@ public class CableBusBakedModel implements BakedModel, FabricBakedModel {
return;
}
RenderLayer layer = RenderLayer.getCutout(); // FIXME: Fabric can only render within one layer (?)
// First, handle the cable at the center of the cable bus
final Mesh cableModel = CABLE_MODEL_CACHE.computeIfAbsent(renderState, this::buildCableModel);
if (cableModel != null) {
context.meshConsumer().accept(cableModel);
}
// The core parts of the cable will only be rendered in the CUTOUT layer.
// Facades will add them selves to what ever the block would be rendered with,
// except when transparent facades are enabled, they are forced to TRANSPARENT.
if (layer == RenderLayer.getCutout()) {
// First, handle the cable at the center of the cable bus
final Mesh cableModel = CABLE_MODEL_CACHE.computeIfAbsent(renderState, this::buildCableModel);
if (cableModel != null) {
context.meshConsumer().accept(cableModel);
// Then handle attachments
for (Direction facing : Direction.values()) {
final IPartModel partModel = renderState.getAttachments().get(facing);
if (partModel == null) {
continue;
}
// Then handle attachments
for (Direction facing : Direction.values()) {
final IPartModel partModel = renderState.getAttachments().get(facing);
if (partModel == null) {
continue;
Object partModelData = renderState.getPartModelData().get(facing);
for (Identifier model : partModel.getModels()) {
BakedModel bakedModel = this.partModels.get(model);
if (bakedModel == null) {
throw new IllegalStateException("Trying to use an unregistered part model: " + model);
}
Object partModelData = renderState.getPartModelData().get(facing);
for (Identifier model : partModel.getModels()) {
BakedModel bakedModel = this.partModels.get(model);
if (bakedModel == null) {
throw new IllegalStateException("Trying to use an unregistered part model: " + model);
}
context.pushTransform(QuadRotator.get(facing, Direction.UP));
if (bakedModel instanceof FabricBakedModel) {
((FabricBakedModel) bakedModel).emitBlockQuads(blockView, state, pos, randomSupplier, context);
} else {
context.fallbackConsumer().accept(bakedModel);
}
context.popTransform();
context.pushTransform(QuadRotator.get(facing, Direction.UP));
if (bakedModel instanceof FabricBakedModel) {
((FabricBakedModel) bakedModel).emitBlockQuads(blockView, state, pos, randomSupplier, context);
} else {
context.fallbackConsumer().accept(bakedModel);
}
context.popTransform();
}
}
this.facadeBuilder.buildFacadeQuads(layer, renderState, randomSupplier, context, this.partModels::get);
// FIXME this.facadeBuilder.buildFacadeQuads(layer, renderState, randomSupplier, context, this.partModels::get);
}
// Determines whether a cable is connected to exactly two sides that are
@@ -172,101 +173,101 @@ public class CableBusBakedModel implements BakedModel, FabricBakedModel {
AEColor cableColor = renderState.getCableColor();
EnumMap<Direction, AECableType> connectionTypes = renderState.getConnectionTypes();
MeshBuilder builder = IndigoRenderer.INSTANCE.meshBuilder();
MeshBuilder builder = RENDERER.meshBuilder();
QuadEmitter emitter = builder.getEmitter();
// FIXME
// FIXME // If the connection is straight, no busses are attached, and no covered core
// FIXME // has been forced (in case of glass
// FIXME // cables), then render the cable as a simplified straight line.
// FIXME boolean noAttachments = !renderState.getAttachments().values().stream()
// FIXME .anyMatch(IPartModel::requireCableConnection);
// FIXME if (noAttachments && isStraightLine(cableType, connectionTypes)) {
// FIXME Direction facing = connectionTypes.keySet().iterator().next();
// FIXME
// FIXME switch (cableType) {
// FIXME case GLASS:
// FIXME this.cableBuilder.addStraightGlassConnection(facing, cableColor, emitter);
// FIXME break;
// FIXME case COVERED:
// FIXME this.cableBuilder.addStraightCoveredConnection(facing, cableColor, emitter);
// FIXME break;
// FIXME case SMART:
// FIXME this.cableBuilder.addStraightSmartConnection(facing, cableColor,
// FIXME renderState.getChannelsOnSide().get(facing), emitter);
// FIXME break;
// FIXME case DENSE_COVERED:
// FIXME this.cableBuilder.addStraightDenseCoveredConnection(facing, cableColor, emitter);
// FIXME break;
// FIXME case DENSE_SMART:
// FIXME this.cableBuilder.addStraightDenseSmartConnection(facing, cableColor,
// FIXME renderState.getChannelsOnSide().get(facing), emitter);
// FIXME break;
// FIXME default:
// FIXME break;
// FIXME }
// FIXME
// FIXME return null; // Don't render the other form of connection
// FIXME }
// FIXME
// FIXME this.cableBuilder.addCableCore(renderState.getCoreType(), cableColor, emitter);
// FIXME
// FIXME // Render all internal connections to attachments
// FIXME EnumMap<Direction, Integer> attachmentConnections = renderState.getAttachmentConnections();
// FIXME for (Direction facing : attachmentConnections.keySet()) {
// FIXME int distance = attachmentConnections.get(facing);
// FIXME int channels = renderState.getChannelsOnSide().get(facing);
// FIXME
// FIXME switch (cableType) {
// FIXME case GLASS:
// FIXME this.cableBuilder.addConstrainedGlassConnection(facing, cableColor, distance, emitter);
// FIXME break;
// FIXME case COVERED:
// FIXME this.cableBuilder.addConstrainedCoveredConnection(facing, cableColor, distance, emitter);
// FIXME break;
// FIXME case SMART:
// FIXME this.cableBuilder.addConstrainedSmartConnection(facing, cableColor, distance, channels, emitter);
// FIXME break;
// FIXME case DENSE_COVERED:
// FIXME case DENSE_SMART:
// FIXME // Dense cables do not render connections to parts since none can be attached
// FIXME break;
// FIXME default:
// FIXME break;
// FIXME }
// FIXME }
// FIXME
// FIXME // Render all outgoing connections using the appropriate type
// FIXME for (final Entry<Direction, AECableType> connection : connectionTypes.entrySet()) {
// FIXME final Direction facing = connection.getKey();
// FIXME final AECableType connectionType = connection.getValue();
// FIXME final boolean cableBusAdjacent = renderState.getCableBusAdjacent().contains(facing);
// FIXME final int channels = renderState.getChannelsOnSide().get(facing);
// FIXME
// FIXME switch (cableType) {
// FIXME case GLASS:
// FIXME this.cableBuilder.addGlassConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME emitter);
// FIXME break;
// FIXME case COVERED:
// FIXME this.cableBuilder.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME emitter);
// FIXME break;
// FIXME case SMART:
// FIXME this.cableBuilder.addSmartConnection(facing, cableColor, connectionType, cableBusAdjacent, channels,
// FIXME emitter);
// FIXME break;
// FIXME case DENSE_COVERED:
// FIXME this.cableBuilder.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME emitter);
// FIXME break;
// FIXME case DENSE_SMART:
// FIXME this.cableBuilder.addDenseSmartConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME channels, emitter);
// FIXME break;
// FIXME default:
// FIXME break;
// FIXME }
// FIXME }
// If the connection is straight, no busses are attached, and no covered core
// has been forced (in case of glass
// cables), then render the cable as a simplified straight line.
boolean noAttachments = !renderState.getAttachments().values().stream()
.anyMatch(IPartModel::requireCableConnection);
if (noAttachments && isStraightLine(cableType, connectionTypes)) {
Direction facing = connectionTypes.keySet().iterator().next();
switch (cableType) {
case GLASS:
this.cableBuilder.addStraightGlassConnection(facing, cableColor, emitter);
break;
case COVERED:
this.cableBuilder.addStraightCoveredConnection(facing, cableColor, emitter);
break;
case SMART:
this.cableBuilder.addStraightSmartConnection(facing, cableColor,
renderState.getChannelsOnSide().get(facing), emitter);
break;
case DENSE_COVERED:
this.cableBuilder.addStraightDenseCoveredConnection(facing, cableColor, emitter);
break;
case DENSE_SMART:
this.cableBuilder.addStraightDenseSmartConnection(facing, cableColor,
renderState.getChannelsOnSide().get(facing), emitter);
break;
default:
break;
}
return builder.build(); // Don't render the other form of connection
}
this.cableBuilder.addCableCore(renderState.getCoreType(), cableColor, emitter);
// Render all internal connections to attachments
EnumMap<Direction, Integer> attachmentConnections = renderState.getAttachmentConnections();
for (Direction facing : attachmentConnections.keySet()) {
int distance = attachmentConnections.get(facing);
int channels = renderState.getChannelsOnSide().get(facing);
switch (cableType) {
case GLASS:
this.cableBuilder.addConstrainedGlassConnection(facing, cableColor, distance, emitter);
break;
case COVERED:
this.cableBuilder.addConstrainedCoveredConnection(facing, cableColor, distance, emitter);
break;
case SMART:
this.cableBuilder.addConstrainedSmartConnection(facing, cableColor, distance, channels, emitter);
break;
case DENSE_COVERED:
case DENSE_SMART:
// Dense cables do not render connections to parts since none can be attached
break;
default:
break;
}
}
// Render all outgoing connections using the appropriate type
for (final Entry<Direction, AECableType> connection : connectionTypes.entrySet()) {
final Direction facing = connection.getKey();
final AECableType connectionType = connection.getValue();
final boolean cableBusAdjacent = renderState.getCableBusAdjacent().contains(facing);
final int channels = renderState.getChannelsOnSide().get(facing);
switch (cableType) {
case GLASS:
this.cableBuilder.addGlassConnection(facing, cableColor, connectionType, cableBusAdjacent,
emitter);
break;
case COVERED:
this.cableBuilder.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
emitter);
break;
case SMART:
this.cableBuilder.addSmartConnection(facing, cableColor, connectionType, cableBusAdjacent, channels,
emitter);
break;
case DENSE_COVERED:
this.cableBuilder.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
emitter);
break;
case DENSE_SMART:
this.cableBuilder.addDenseSmartConnection(facing, cableColor, connectionType, cableBusAdjacent,
channels, emitter);
break;
default:
break;
}
}
return builder.build();
}
@@ -54,8 +54,7 @@ public class CableBusModel implements UnbakedModel {
@Override
public Collection<Identifier> getModelDependencies() {
return Collections.emptyList();
return partModels.getModels();
}
@Nullable
@@ -19,19 +19,14 @@
package appeng.client.render.cablebus;
import java.util.*;
import java.util.stream.Collectors;
import com.google.common.base.Preconditions;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.impl.client.indigo.renderer.IndigoRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.math.Direction;
@@ -41,8 +36,6 @@ import net.minecraft.util.math.Direction;
@Environment(EnvType.CLIENT)
public class CubeBuilder {
private final List<BakedQuad> output;
private final EnumMap<Direction, Sprite> textures = new EnumMap<>(Direction.class);
private EnumSet<Direction> drawFaces = EnumSet.allOf(Direction.class);
@@ -57,25 +50,12 @@ public class CubeBuilder {
private boolean renderFullBright;
private final MeshBuilder meshBuilder;
private final QuadEmitter emitter;
private int vertexIndex = 0;
public CubeBuilder(List<BakedQuad> output) {
this.output = output;
meshBuilder = IndigoRenderer.INSTANCE.meshBuilder();
emitter = meshBuilder.getEmitter();
emitter.emit();
meshBuilder.build();
ModelHelper.toQuadLists(meshBuilder.build());
}
public CubeBuilder() {
this(new ArrayList<>(6));
public CubeBuilder(QuadEmitter emitter) {
this.emitter = emitter;
}
public void addCube(float x1, float y1, float z1, float x2, float y2, float z2) {
@@ -171,10 +151,8 @@ public class CubeBuilder {
emitter.lightmap(lightmap, lightmap, lightmap, lightmap);
}
// FIXME: this is unnecessarily inefficient
emitter.emit();
List<BakedQuad>[] quads = ModelHelper.toQuadLists(meshBuilder.build());
this.output.addAll(Arrays.stream(quads).flatMap(Collection::stream).collect(Collectors.toList()));
this.vertexIndex = 0;
}
private UvVector getDefaultUv(Direction face, Sprite texture, float x1, float y1, float z1, float x2,
@@ -382,10 +360,10 @@ public class CubeBuilder {
private void putVertex(Direction face, float x, float y, float z, float u, float v) {
emitter.pos(vertexIndex, x, y, z);
emitter.pos(vertexIndex, face.getOffsetX(), face.getOffsetY(), face.getOffsetZ());
emitter.normal(vertexIndex, face.getOffsetX(), face.getOffsetY(), face.getOffsetZ());
// Color format is RGBA
emitter.spriteColor(vertexIndex, this.color);
emitter.spriteColor(vertexIndex, 0, this.color);
emitter.sprite(vertexIndex, 0, u, v);
@@ -458,7 +436,4 @@ public class CubeBuilder {
this.useStandardUV = true;
}
public List<BakedQuad> getOutput() {
return this.output;
}
}
+13 -7
View File
@@ -8,6 +8,7 @@ import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.parts.CableRenderMode;
import appeng.bootstrap.IBootstrapComponent;
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
import appeng.client.render.effects.ParticleTypes;
import appeng.core.features.registries.cell.BasicCellHandler;
@@ -18,7 +19,6 @@ import appeng.core.stats.AeStats;
import appeng.core.sync.BasePacket;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.network.TargetPoint;
import appeng.hooks.TickHandler;
import appeng.hooks.ToolItemHook;
import appeng.me.cache.*;
import appeng.mixins.CriteriaRegisterMixin;
@@ -27,13 +27,14 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.function.Consumer;
public abstract class AppEngBase implements AppEng {
protected AdvancementTriggers advancementTriggers;
@@ -57,7 +58,7 @@ public abstract class AppEngBase implements AppEng {
ToolItemHook.install();
Api.INSTANCE = new Api();
registerTileEntities();
registerBlockEntities();
registerParticleTypes();
registerRecipeTypes();
@@ -100,10 +101,9 @@ public abstract class AppEngBase implements AppEng {
Registry.register(Registry.PARTICLE_TYPE, AppEng.makeId("vibrant_fx"), ParticleTypes.VIBRANT);
}
private void registerTileEntities() {
final ApiDefinitions definitions = Api.INSTANCE.definitions();
definitions.getRegistry().getBootstrapComponents(ITileEntityRegistrationComponent.class)
.forEachRemaining(ITileEntityRegistrationComponent::register);
private void registerBlockEntities() {
callDeferredBootstrapComponents(ITileEntityRegistrationComponent.class,
ITileEntityRegistrationComponent::register);
}
private static <T extends Recipe<?>> RecipeType<T> registerRecipeType(String id) {
@@ -158,6 +158,12 @@ public abstract class AppEngBase implements AppEng {
this.renderModeBased = player;
}
protected final <T extends IBootstrapComponent> void callDeferredBootstrapComponents(Class<T> componentClass, Consumer<T> invoker) {
final ApiDefinitions definitions = Api.INSTANCE.definitions();
definitions.getRegistry().getBootstrapComponents(componentClass)
.forEachRemaining(invoker);
}
protected CableRenderMode renderModeForPlayer(final PlayerEntity player) {
if (player != null) {
for (int x = 0; x < PlayerInventory.getHotbarSize(); x++) {
@@ -1,7 +1,6 @@
package appeng.server;
import appeng.api.parts.CableRenderMode;
import appeng.block.AEBaseBlock;
import appeng.client.ActionKey;
import appeng.client.EffectType;
import appeng.core.AppEngBase;
@@ -10,7 +9,6 @@ import appeng.core.worlddata.WorldData;
import appeng.hooks.TickHandler;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.server.PlayerStream;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
@@ -18,7 +16,6 @@ import net.minecraft.util.hit.HitResult;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Random;
import java.util.stream.Stream;
@@ -32,6 +32,7 @@ import appeng.core.AELog;
import appeng.core.features.IStackSrc;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.IPriorityHost;
import appeng.hooks.TickHandler;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.SettingsFrom;
@@ -422,9 +423,8 @@ public class AEBaseBlockEntity extends BlockEntity implements IOrientable, IComm
if (this.world != null) {
this.world.markDirty(this.pos, this);
if (!this.markDirtyQueued) {
// FIXME FABRIC TickHandler.INSTANCE.addCallable(null, this::markDirtyAtEndOfTick);
TickHandler.INSTANCE.addCallable(null, this::markDirtyAtEndOfTick);
this.markDirtyQueued = true;
throw new IllegalStateException();
}
}
}
+2 -2
View File
@@ -48,6 +48,7 @@ import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.stats.AeStats;
import appeng.fluids.util.AEFluidStack;
import appeng.hooks.TickHandler;
import appeng.me.GridAccessException;
import appeng.me.GridNode;
import appeng.util.helpers.ItemComparisonHelper;
@@ -1091,8 +1092,7 @@ public class Platform {
public static void notifyBlocksOfNeighbors(final World world, final BlockPos pos) {
if (!world.isClient) {
throw new IllegalStateException();
// FIXME FABRIC TickHandler.INSTANCE.addCallable(world, new BlockUpdate(pos));
TickHandler.INSTANCE.addCallable(world, new BlockUpdate(pos));
}
}