Working on Spatial Stuff.
This commit is contained in:
@@ -10,6 +10,7 @@ import appeng.client.render.SimpleModelLoader;
|
||||
import appeng.client.render.cablebus.CableBusModelLoader;
|
||||
import appeng.client.render.effects.*;
|
||||
import appeng.client.render.model.SkyCompassModel;
|
||||
import appeng.client.render.spatial.SpatialPylonModel;
|
||||
import appeng.client.render.tesr.InscriberTESR;
|
||||
import appeng.client.render.tesr.SkyChestTESR;
|
||||
import appeng.container.implementations.*;
|
||||
@@ -245,7 +246,7 @@ public final class AppEngClient extends AppEngBase {
|
||||
// FIXME FABRIC addBuiltInModel("biometric_card", BiometricCardModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("drive", DriveModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("color_applicator", ColorApplicatorModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("spatial_pylon", SpatialPylonModel::new);
|
||||
addBuiltInModel("block/spatial_pylon", SpatialPylonModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("paint_splotches", PaintSplotchesModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("quantum_bridge_formed", QnbFormedModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("p2p_tunnel_frequency", P2PTunnelFrequencyModel::new);
|
||||
|
||||
@@ -45,26 +45,26 @@ public class SpatialIOPortScreen extends AEBaseScreen<SpatialIOPortContainer> {
|
||||
|
||||
@Override
|
||||
public void drawFG(MatrixStack matrices, final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.textRenderer.draw(matrices, GuiText.StoredPower.text() + ": "
|
||||
+ Platform.formatPowerLong(this.handler.getCurrentPower(), false), 13, 21, 4210752);
|
||||
this.textRenderer.draw(matrices, GuiText.StoredPower.withSuffix(": "
|
||||
+ Platform.formatPowerLong(this.handler.getCurrentPower(), false)), 13, 21, 4210752);
|
||||
this.textRenderer.draw(matrices,
|
||||
GuiText.MaxPower.text() + ": " + Platform.formatPowerLong(this.handler.getMaxPower(), false), 13,
|
||||
GuiText.MaxPower.withSuffix(": " + Platform.formatPowerLong(this.handler.getMaxPower(), false)), 13,
|
||||
31, 4210752);
|
||||
this.textRenderer.draw(matrices, GuiText.RequiredPower.text() + ": "
|
||||
+ Platform.formatPowerLong(this.handler.getRequiredPower(), false), 13, 73, 4210752);
|
||||
this.textRenderer.draw(matrices, GuiText.RequiredPower.withSuffix(": "
|
||||
+ Platform.formatPowerLong(this.handler.getRequiredPower(), false)), 13, 73, 4210752);
|
||||
this.textRenderer.draw(matrices,
|
||||
GuiText.Efficiency.text() + ": " + (((float) this.handler.getEfficency()) / 100) + '%', 13, 83,
|
||||
GuiText.Efficiency.withSuffix(": " + (((float) this.handler.getEfficency()) / 100) + '%'), 13, 83,
|
||||
4210752);
|
||||
|
||||
this.textRenderer.draw(matrices, this.getGuiDisplayName(GuiText.SpatialIOPort.text()), 8, 6, 4210752);
|
||||
this.textRenderer.draw(matrices, GuiText.inventory.text(), 8, this.backgroundHeight - 96, 4210752);
|
||||
|
||||
if (this.handler.xSize != 0 && this.handler.ySize != 0 && this.handler.zSize != 0) {
|
||||
final String text = GuiText.SCSSize.text() + ": " + this.handler.xSize + "x" + this.handler.ySize
|
||||
+ "x" + this.handler.zSize;
|
||||
final Text text = GuiText.SCSSize.withSuffix(": " + this.handler.xSize + "x" + this.handler.ySize
|
||||
+ "x" + this.handler.zSize);
|
||||
this.textRenderer.draw(matrices, text, 13, 93, 4210752);
|
||||
} else {
|
||||
this.textRenderer.draw(matrices, GuiText.SCSSize.text() + ": " + GuiText.SCSInvalid.text(), 13, 93, 4210752);
|
||||
this.textRenderer.draw(matrices, GuiText.SCSSize.withSuffix(": ").append(GuiText.SCSInvalid.text()), 13, 93, 4210752);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -17,6 +18,11 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public interface BasicUnbakedModel extends UnbakedModel {
|
||||
|
||||
@Override
|
||||
default Collection<Identifier> getModelDependencies() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
default Stream<SpriteIdentifier> getAdditionalTextures() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* 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.spatial;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.tile.spatial.SpatialPylonBlockEntity;
|
||||
|
||||
/**
|
||||
* The baked model that will be used for rendering the spatial pylon.
|
||||
*/
|
||||
class SpatialPylonBakedModel implements BakedModel, FabricBakedModel {
|
||||
|
||||
private final Map<SpatialPylonTextureType, Sprite> textures;
|
||||
|
||||
SpatialPylonBakedModel(Map<SpatialPylonTextureType, Sprite> textures) {
|
||||
this.textures = ImmutableMap.copyOf(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaAdapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
int flags = getFlags(blockView, pos);
|
||||
|
||||
CubeBuilder builder = new CubeBuilder(context.getEmitter());
|
||||
|
||||
if (flags != 0) {
|
||||
Direction ori = null;
|
||||
int displayAxis = flags & SpatialPylonBlockEntity.DISPLAY_Z;
|
||||
if (displayAxis == SpatialPylonBlockEntity.DISPLAY_X) {
|
||||
ori = Direction.EAST;
|
||||
|
||||
if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MAX) {
|
||||
builder.setUvRotation(Direction.SOUTH, 1);
|
||||
builder.setUvRotation(Direction.NORTH, 1);
|
||||
builder.setUvRotation(Direction.UP, 2);
|
||||
builder.setUvRotation(Direction.DOWN, 2);
|
||||
} else if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MIN) {
|
||||
builder.setUvRotation(Direction.SOUTH, 2);
|
||||
builder.setUvRotation(Direction.NORTH, 2);
|
||||
builder.setUvRotation(Direction.UP, 1);
|
||||
builder.setUvRotation(Direction.DOWN, 1);
|
||||
} else {
|
||||
builder.setUvRotation(Direction.SOUTH, 1);
|
||||
builder.setUvRotation(Direction.NORTH, 1);
|
||||
builder.setUvRotation(Direction.UP, 1);
|
||||
builder.setUvRotation(Direction.DOWN, 1);
|
||||
}
|
||||
}
|
||||
|
||||
else if (displayAxis == SpatialPylonBlockEntity.DISPLAY_Y) {
|
||||
ori = Direction.UP;
|
||||
if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MAX) {
|
||||
builder.setUvRotation(Direction.NORTH, 3);
|
||||
builder.setUvRotation(Direction.SOUTH, 3);
|
||||
builder.setUvRotation(Direction.EAST, 3);
|
||||
builder.setUvRotation(Direction.WEST, 3);
|
||||
}
|
||||
}
|
||||
|
||||
else if (displayAxis == SpatialPylonBlockEntity.DISPLAY_Z) {
|
||||
ori = Direction.NORTH;
|
||||
if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MAX) {
|
||||
builder.setUvRotation(Direction.EAST, 2);
|
||||
builder.setUvRotation(Direction.WEST, 1);
|
||||
} else if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MIN) {
|
||||
builder.setUvRotation(Direction.EAST, 1);
|
||||
builder.setUvRotation(Direction.WEST, 2);
|
||||
builder.setUvRotation(Direction.UP, 3);
|
||||
builder.setUvRotation(Direction.DOWN, 3);
|
||||
} else {
|
||||
builder.setUvRotation(Direction.EAST, 1);
|
||||
builder.setUvRotation(Direction.WEST, 2);
|
||||
}
|
||||
}
|
||||
|
||||
builder.setTextures(this.textures.get(getTextureTypeFromSideOutside(flags, ori, Direction.UP)),
|
||||
this.textures.get(getTextureTypeFromSideOutside(flags, ori, Direction.DOWN)),
|
||||
this.textures.get(getTextureTypeFromSideOutside(flags, ori, Direction.NORTH)),
|
||||
this.textures.get(getTextureTypeFromSideOutside(flags, ori, Direction.SOUTH)),
|
||||
this.textures.get(getTextureTypeFromSideOutside(flags, ori, Direction.EAST)),
|
||||
this.textures.get(getTextureTypeFromSideOutside(flags, ori, Direction.WEST)));
|
||||
builder.addCube(0, 0, 0, 16, 16, 16);
|
||||
|
||||
if ((flags
|
||||
& SpatialPylonBlockEntity.DISPLAY_POWERED_ENABLED) == SpatialPylonBlockEntity.DISPLAY_POWERED_ENABLED) {
|
||||
builder.setRenderFullBright(true);
|
||||
}
|
||||
|
||||
builder.setTextures(this.textures.get(getTextureTypeFromSideInside(flags, ori, Direction.UP)),
|
||||
this.textures.get(getTextureTypeFromSideInside(flags, ori, Direction.DOWN)),
|
||||
this.textures.get(getTextureTypeFromSideInside(flags, ori, Direction.NORTH)),
|
||||
this.textures.get(getTextureTypeFromSideInside(flags, ori, Direction.SOUTH)),
|
||||
this.textures.get(getTextureTypeFromSideInside(flags, ori, Direction.EAST)),
|
||||
this.textures.get(getTextureTypeFromSideInside(flags, ori, Direction.WEST)));
|
||||
builder.addCube(0, 0, 0, 16, 16, 16);
|
||||
} else {
|
||||
builder.setTexture(this.textures.get(SpatialPylonTextureType.BASE));
|
||||
builder.addCube(0, 0, 0, 16, 16, 16);
|
||||
|
||||
builder.setTexture(this.textures.get(SpatialPylonTextureType.DIM));
|
||||
builder.addCube(0, 0, 0, 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
// Not intended to be used as an item model.
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand) {
|
||||
// Can only sensibly render using the new API
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private int getFlags(BlockRenderView blockRenderView, BlockPos pos) {
|
||||
if (!(blockRenderView instanceof RenderAttachedBlockView)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Object attachment = ((RenderAttachedBlockView) blockRenderView).getBlockEntityRenderAttachment(pos);
|
||||
if (!(attachment instanceof Integer)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (Integer) attachment;
|
||||
}
|
||||
|
||||
private static SpatialPylonTextureType getTextureTypeFromSideOutside(int flags, Direction ori, Direction dir) {
|
||||
if (ori == dir || ori.getOpposite() == dir) {
|
||||
return SpatialPylonTextureType.BASE;
|
||||
}
|
||||
|
||||
if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_MIDDLE) {
|
||||
return SpatialPylonTextureType.BASE_SPANNED;
|
||||
} else if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MIN) {
|
||||
return SpatialPylonTextureType.BASE_END;
|
||||
} else if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MAX) {
|
||||
return SpatialPylonTextureType.BASE_END;
|
||||
}
|
||||
|
||||
return SpatialPylonTextureType.BASE;
|
||||
}
|
||||
|
||||
private static SpatialPylonTextureType getTextureTypeFromSideInside(int flags, Direction ori, Direction dir) {
|
||||
final boolean good = (flags & SpatialPylonBlockEntity.DISPLAY_ENABLED) == SpatialPylonBlockEntity.DISPLAY_ENABLED;
|
||||
|
||||
if (ori == dir || ori.getOpposite() == dir) {
|
||||
return good ? SpatialPylonTextureType.DIM : SpatialPylonTextureType.RED;
|
||||
}
|
||||
|
||||
if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_MIDDLE) {
|
||||
return good ? SpatialPylonTextureType.DIM_SPANNED : SpatialPylonTextureType.RED_SPANNED;
|
||||
} else if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MIN) {
|
||||
return good ? SpatialPylonTextureType.DIM_END : SpatialPylonTextureType.RED_END;
|
||||
} else if ((flags & SpatialPylonBlockEntity.DISPLAY_MIDDLE) == SpatialPylonBlockEntity.DISPLAY_END_MAX) {
|
||||
return good ? SpatialPylonTextureType.DIM_END : SpatialPylonTextureType.RED_END;
|
||||
}
|
||||
|
||||
return SpatialPylonTextureType.BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.textures.get(SpatialPylonTextureType.DIM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return ModelTransformation.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.spatial;
|
||||
|
||||
import appeng.client.render.BasicUnbakedModel;
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SpatialPylonModel implements BasicUnbakedModel {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
|
||||
Map<SpatialPylonTextureType, Sprite> textures = new EnumMap<>(SpatialPylonTextureType.class);
|
||||
|
||||
for (SpatialPylonTextureType type : SpatialPylonTextureType.values()) {
|
||||
textures.put(type, textureGetter.apply(getTexturePath(type)));
|
||||
}
|
||||
|
||||
return new SpatialPylonBakedModel(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<SpriteIdentifier> getAdditionalTextures() {
|
||||
return Arrays.stream(SpatialPylonTextureType.values()).map(SpatialPylonModel::getTexturePath);
|
||||
}
|
||||
|
||||
private static SpriteIdentifier getTexturePath(SpatialPylonTextureType type) {
|
||||
return new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/spatial_pylon/" + type.name().toLowerCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.spatial;
|
||||
|
||||
enum SpatialPylonTextureType {
|
||||
BASE, BASE_END, BASE_SPANNED, DIM, DIM_END, DIM_SPANNED, RED, RED_END, RED_SPANNED
|
||||
}
|
||||
Reference in New Issue
Block a user