Moving to source sets
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import appeng.api.implementations.tiles.IColorableTile;
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
/**
|
||||
* Automatically exposes the color of a colorable tile using tint indices 0-2
|
||||
*/
|
||||
public class ColorableTileBlockColor implements BlockColorProvider {
|
||||
|
||||
public static final ColorableTileBlockColor INSTANCE = new ColorableTileBlockColor();
|
||||
|
||||
@Override
|
||||
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int tintIndex) {
|
||||
AEColor color = AEColor.TRANSPARENT; // Default to a neutral color
|
||||
|
||||
if (worldIn != null && pos != null) {
|
||||
BlockEntity te = worldIn.getBlockEntity(pos);
|
||||
if (te instanceof IColorableTile) {
|
||||
color = ((IColorableTile) te).getColor();
|
||||
}
|
||||
}
|
||||
|
||||
return color.getVariantByTintIndex(tintIndex);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, 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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
public abstract class DelegateBakedModel implements BakedModel {
|
||||
private final BakedModel baseModel;
|
||||
|
||||
protected DelegateBakedModel(BakedModel base) {
|
||||
this.baseModel = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
return baseModel.getQuads(state, side, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return baseModel.isSideLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return baseModel.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(ModelTransformation.Mode cameraTransformType, MatrixStack mat) {
|
||||
baseModel.handlePerspective(cameraTransformType, mat);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.baseModel.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return this.baseModel.getTransformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.baseModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return this.baseModel.hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return this.baseModel.isBuiltin();
|
||||
}
|
||||
|
||||
public BakedModel getBaseModel() {
|
||||
return this.baseModel;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, 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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
/**
|
||||
* @author DrummerMC
|
||||
* @version rv6 - 2018-01-22
|
||||
* @since rv6 2018-01-22
|
||||
*/
|
||||
public class DummyFluidBakedModel implements BakedModel {
|
||||
private final ImmutableList<BakedQuad> quads;
|
||||
|
||||
public DummyFluidBakedModel(ImmutableList<BakedQuad> quads) {
|
||||
this.quads = quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
return this.quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ItemLayerModel;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
|
||||
import appeng.fluids.items.FluidDummyItem;
|
||||
|
||||
/**
|
||||
* This baked model class is used as a dispatcher to redirect the renderer to
|
||||
* the *real* model that should be used based on the item stack. A custom Item
|
||||
* Override List is used to accomplish this.
|
||||
*/
|
||||
public class DummyFluidDispatcherBakedModel extends DelegateBakedModel {
|
||||
private final Function<SpriteIdentifier, Sprite> bakedTextureGetter;
|
||||
|
||||
public DummyFluidDispatcherBakedModel(BakedModel baseModel,
|
||||
Function<SpriteIdentifier, Sprite> bakedTextureGetter) {
|
||||
super(baseModel);
|
||||
this.bakedTextureGetter = bakedTextureGetter;
|
||||
}
|
||||
|
||||
// This is never used. See the item override list below.
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return this.getBaseModel().hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return getBaseModel().isSideLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return new ModelOverrideList() {
|
||||
@Override
|
||||
public BakedModel getModelWithOverrides(BakedModel originalModel, ItemStack stack, World world,
|
||||
LivingEntity entity) {
|
||||
if (!(stack.getItem() instanceof FluidDummyItem)) {
|
||||
return originalModel;
|
||||
}
|
||||
|
||||
FluidDummyItem itemFacade = (FluidDummyItem) stack.getItem();
|
||||
|
||||
FluidVolume fluidStack = itemFacade.getFluidStack(stack);
|
||||
if (fluidStack.isEmpty()) {
|
||||
fluidStack = new FluidVolume(Fluids.WATER, FluidAttributes.BUCKET_VOLUME);
|
||||
}
|
||||
|
||||
FluidAttributes attributes = fluidStack.getFluidKey().getAttributes();
|
||||
Identifier stillTexture = attributes.getStillTexture(fluidStack);
|
||||
SpriteIdentifier stillMaterial = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, stillTexture);
|
||||
Sprite sprite = DummyFluidDispatcherBakedModel.this.bakedTextureGetter.apply(stillMaterial);
|
||||
if (sprite == null) {
|
||||
return new DummyFluidBakedModel(ImmutableList.of());
|
||||
}
|
||||
|
||||
return new DummyFluidBakedModel(
|
||||
ItemLayerModel.getQuadsForSprite(0, sprite, AffineTransformation.identity()));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* The model class for facades. Since facades wrap existing models, they don't
|
||||
* declare any dependencies here other than the cable anchor.
|
||||
*/
|
||||
public class DummyFluidItemModel implements IModelGeometry<DummyFluidItemModel> {
|
||||
// We use this to get the default item transforms and make our lives easier
|
||||
private static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID,
|
||||
"item/dummy_fluid_item_base");
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
BakedModel bakedBaseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
|
||||
return new DummyFluidDispatcherBakedModel(bakedBaseModel, spriteGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
|
||||
import appeng.client.render.cablebus.FacadeBuilder;
|
||||
|
||||
/**
|
||||
* This model used the provided FacadeBuilder to "slice" the item quads for the
|
||||
* facade provided.
|
||||
*
|
||||
* @author covers1624
|
||||
*/
|
||||
public class FacadeBakedItemModel extends ForwardingBakedModel implements FabricBakedModel {
|
||||
|
||||
private final ItemStack textureStack;
|
||||
private final FacadeBuilder facadeBuilder;
|
||||
private List<BakedQuad> quads = null;
|
||||
|
||||
protected FacadeBakedItemModel(BakedModel base, ItemStack textureStack, FacadeBuilder facadeBuilder) {
|
||||
this.wrapped = base;
|
||||
this.textureStack = textureStack;
|
||||
this.facadeBuilder = facadeBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
super.emitItemQuads(stack, randomSupplier, context);
|
||||
|
||||
if (quads == null) {
|
||||
quads = new ArrayList<>();
|
||||
quads.addAll(this.facadeBuilder.buildFacadeItemQuads(this.textureStack, Direction.NORTH));
|
||||
quads = Collections.unmodifiableList(quads);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
||||
import appeng.client.render.cablebus.FacadeBuilder;
|
||||
import appeng.items.parts.FacadeItem;
|
||||
|
||||
/**
|
||||
* This baked model class is used as a dispatcher to redirect the renderer to
|
||||
* the *real* model that should be used based on the item stack. A custom Item
|
||||
* Override List is used to accomplish this.
|
||||
*/
|
||||
public class FacadeDispatcherBakedModel extends DelegateBakedModel {
|
||||
private final FacadeBuilder facadeBuilder;
|
||||
private final Int2ObjectMap<FacadeBakedItemModel> cache = new Int2ObjectArrayMap<>();
|
||||
|
||||
public FacadeDispatcherBakedModel(BakedModel baseModel, FacadeBuilder facadeBuilder) {
|
||||
super(baseModel);
|
||||
this.facadeBuilder = facadeBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return new ModelOverrideList() {
|
||||
@Override
|
||||
public BakedModel getModelWithOverrides(BakedModel originalModel, ItemStack stack, World world,
|
||||
LivingEntity entity) {
|
||||
if (!(stack.getItem() instanceof FacadeItem)) {
|
||||
return originalModel;
|
||||
}
|
||||
|
||||
FacadeItem itemFacade = (FacadeItem) stack.getItem();
|
||||
|
||||
ItemStack textureItem = itemFacade.getTextureItem(stack);
|
||||
|
||||
int hash = Objects.hash(textureItem.getItem().getRegistryName(), textureItem.getTag());
|
||||
FacadeBakedItemModel model = FacadeDispatcherBakedModel.this.cache.get(hash);
|
||||
if (model == null) {
|
||||
model = new FacadeBakedItemModel(FacadeDispatcherBakedModel.this.getBaseModel(), textureItem,
|
||||
FacadeDispatcherBakedModel.this.facadeBuilder);
|
||||
FacadeDispatcherBakedModel.this.cache.put(hash, model);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.*;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.client.render.cablebus.FacadeBuilder;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* The model class for facades. Since facades wrap existing models, they don't
|
||||
* declare any dependencies here other than the cable anchor.
|
||||
*/
|
||||
public class FacadeItemModel implements IModelGeometry<FacadeItemModel> {
|
||||
|
||||
// We use this to get the default item transforms and make our lives easier
|
||||
private static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID, "item/facade_base");
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
BakedModel bakedBaseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
FacadeBuilder facadeBuilder = new FacadeBuilder();
|
||||
|
||||
return new FacadeDispatcherBakedModel(bakedBaseModel, facadeBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return modelGetter.apply(MODEL_BASE).getTextures(modelGetter, missingTextureErrors);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.client.util.math.Vector4f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
/**
|
||||
* TODO: Removed useless stuff.
|
||||
*/
|
||||
public enum FacingToRotation implements StringIdentifiable {
|
||||
|
||||
// DUNSWE
|
||||
// @formatter:off
|
||||
DOWN_DOWN(new Vector3f(0, 0, 0)), // NOOP
|
||||
DOWN_UP(new Vector3f(0, 0, 0)), // NOOP
|
||||
DOWN_NORTH(new Vector3f(-90, 0, 0)), DOWN_SOUTH(new Vector3f(-90, 0, 180)), DOWN_WEST(new Vector3f(-90, 0, 90)),
|
||||
DOWN_EAST(new Vector3f(-90, 0, -90)), UP_DOWN(new Vector3f(0, 0, 0)), // NOOP
|
||||
UP_UP(new Vector3f(0, 0, 0)), // NOOP
|
||||
UP_NORTH(new Vector3f(90, 0, 180)), UP_SOUTH(new Vector3f(90, 0, 0)), UP_WEST(new Vector3f(90, 0, 90)),
|
||||
UP_EAST(new Vector3f(90, 0, -90)), NORTH_DOWN(new Vector3f(0, 0, 180)), NORTH_UP(new Vector3f(0, 0, 0)),
|
||||
NORTH_NORTH(new Vector3f(0, 0, 0)), // NOOP
|
||||
NORTH_SOUTH(new Vector3f(0, 0, 0)), // NOOP
|
||||
NORTH_WEST(new Vector3f(0, 0, 90)), NORTH_EAST(new Vector3f(0, 0, -90)), SOUTH_DOWN(new Vector3f(0, 180, 180)),
|
||||
SOUTH_UP(new Vector3f(0, 180, 0)), SOUTH_NORTH(new Vector3f(0, 0, 0)), // NOOP
|
||||
SOUTH_SOUTH(new Vector3f(0, 0, 0)), // NOOP
|
||||
SOUTH_WEST(new Vector3f(0, 180, -90)), SOUTH_EAST(new Vector3f(0, 180, 90)), WEST_DOWN(new Vector3f(0, 90, 180)),
|
||||
WEST_UP(new Vector3f(0, 90, 0)), WEST_NORTH(new Vector3f(0, 90, -90)), WEST_SOUTH(new Vector3f(0, 90, 90)),
|
||||
WEST_WEST(new Vector3f(0, 0, 0)), // NOOP
|
||||
WEST_EAST(new Vector3f(0, 0, 0)), // NOOP
|
||||
EAST_DOWN(new Vector3f(0, -90, 180)), EAST_UP(new Vector3f(0, -90, 0)), EAST_NORTH(new Vector3f(0, -90, 90)),
|
||||
EAST_SOUTH(new Vector3f(0, -90, -90)), EAST_WEST(new Vector3f(0, 0, 0)), // NOOP
|
||||
EAST_EAST(new Vector3f(0, 0, 0)); // NOOP
|
||||
// @formatter:on
|
||||
|
||||
private final Vector3f rot;
|
||||
private final Quaternion xRot;
|
||||
private final Quaternion yRot;
|
||||
private final Quaternion zRot;
|
||||
private final Matrix4f mat;
|
||||
|
||||
private FacingToRotation(Vector3f rot) {
|
||||
this.rot = rot;
|
||||
this.mat = new Matrix4f();
|
||||
this.mat.loadIdentity();
|
||||
this.mat.multiply(xRot = Vector3f.POSITIVE_X.getDegreesQuaternion(rot.getX()));
|
||||
this.mat.multiply(yRot = Vector3f.POSITIVE_Y.getDegreesQuaternion(rot.getY()));
|
||||
this.mat.multiply(zRot = Vector3f.POSITIVE_Z.getDegreesQuaternion(rot.getZ()));
|
||||
}
|
||||
|
||||
public boolean isRedundant() {
|
||||
return rot.getX() == 0 && rot.getY() == 0 && rot.getZ() == 0;
|
||||
}
|
||||
|
||||
public Vector3f getRot() {
|
||||
return this.rot;
|
||||
}
|
||||
|
||||
public Matrix4f getMat() {
|
||||
return new Matrix4f(this.mat);
|
||||
}
|
||||
|
||||
public void push(MatrixStack mStack) {
|
||||
mStack.multiply(xRot);
|
||||
mStack.multiply(yRot);
|
||||
mStack.multiply(zRot);
|
||||
}
|
||||
|
||||
public Direction rotate(Direction facing) {
|
||||
Vec3i dir = facing.getVector();
|
||||
Vector4f vec = new Vector4f(dir.getX(), dir.getY(), dir.getZ(), 1);
|
||||
vec.transform(mat);
|
||||
return Direction.getFacing(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
public Direction resultingRotate(Direction facing) {
|
||||
for (Direction face : Direction.values()) {
|
||||
if (this.rotate(face) == facing) {
|
||||
return face;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FacingToRotation get(Direction forward, Direction up) {
|
||||
return values()[forward.ordinal() * 6 + up.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package appeng.client.render;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
/**
|
||||
* A quaint model loader that does not accept any additional parameters in JSON.
|
||||
*/
|
||||
public class SimpleModelLoader<T extends IModelGeometry<T>> implements IModelLoader<T> {
|
||||
|
||||
private final Supplier<T> factory;
|
||||
|
||||
public SimpleModelLoader(Supplier<T> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
|
||||
return factory.get();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraftforge.client.IRenderHandler;
|
||||
import net.minecraftforge.client.SkyRenderHandler;
|
||||
|
||||
//TODO https://github.com/MinecraftForge/MinecraftForge/pull/6537
|
||||
public class SpatialSkyRender implements SkyRenderHandler {
|
||||
|
||||
private static final SpatialSkyRender INSTANCE = new SpatialSkyRender();
|
||||
|
||||
private final Random random = new Random();
|
||||
private final int dspList;
|
||||
private long cycle = 0;
|
||||
|
||||
public SpatialSkyRender() {
|
||||
this.dspList = GL11.glGenLists(1);
|
||||
}
|
||||
|
||||
public static IRenderHandler getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private static final Quaternion[] SKYBOX_SIDE_ROTATIONS = { Quaternion.ONE, new Quaternion(90.0F, 0.0F, 0.0F, true),
|
||||
new Quaternion(-90.0F, 0.0F, 0.0F, true), new Quaternion(180.0F, 0.0F, 0.0F, true),
|
||||
new Quaternion(0.0F, 0.0F, 90.0F, true), new Quaternion(0.0F, 0.0F, -90.0F, true), };
|
||||
|
||||
@Override
|
||||
public void render(int ticks, float partialTicks, MatrixStack matrixStack, ClientWorld world, MinecraftClient mc) {
|
||||
final long now = System.currentTimeMillis();
|
||||
if (now - this.cycle > 2000) {
|
||||
this.cycle = now;
|
||||
GL11.glNewList(this.dspList, GL11.GL_COMPILE);
|
||||
this.renderTwinkles();
|
||||
GL11.glEndList();
|
||||
}
|
||||
|
||||
float fade = now - this.cycle;
|
||||
fade /= 1000;
|
||||
fade = 0.15f * (1.0f - Math.abs((fade - 1.0f) * (fade - 1.0f)));
|
||||
|
||||
RenderSystem.disableFog();
|
||||
RenderSystem.disableAlphaTest();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.color4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
final Tessellator tessellator = Tessellator.getInstance();
|
||||
final BufferBuilder VertexBuffer = tessellator.getBuffer();
|
||||
|
||||
// This renders a skybox around the player at a far, fixed distance from them.
|
||||
// The skybox is pitch black and untextured
|
||||
for (Quaternion rotation : SKYBOX_SIDE_ROTATIONS) {
|
||||
matrixStack.push();
|
||||
matrixStack.multiply(rotation);
|
||||
|
||||
RenderSystem.disableTexture();
|
||||
VertexBuffer.begin(GL11.GL_QUADS, VertexFormats.POSITION);
|
||||
VertexBuffer.pos(-100.0D, -100.0D, -100.0D).endVertex();
|
||||
VertexBuffer.pos(-100.0D, -100.0D, 100.0D).endVertex();
|
||||
VertexBuffer.pos(100.0D, -100.0D, 100.0D).endVertex();
|
||||
VertexBuffer.pos(100.0D, -100.0D, -100.0D).endVertex();
|
||||
tessellator.draw();
|
||||
RenderSystem.enableTexture();
|
||||
matrixStack.pop();
|
||||
}
|
||||
|
||||
RenderSystem.depthMask(true);
|
||||
|
||||
if (fade > 0.0f) {
|
||||
RenderSystem.disableFog();
|
||||
RenderSystem.disableAlphaTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
RenderSystem.color4f(fade, fade, fade, 1.0f);
|
||||
GL11.glCallList(this.dspList);
|
||||
}
|
||||
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableAlphaTest();
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.enableFog();
|
||||
|
||||
RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
private void renderTwinkles() {
|
||||
final Tessellator tessellator = Tessellator.getInstance();
|
||||
final BufferBuilder vb = tessellator.getBuffer();
|
||||
vb.begin(GL11.GL_QUADS, VertexFormats.POSITION);
|
||||
|
||||
for (int i = 0; i < 50; ++i) {
|
||||
double iX = this.random.nextFloat() * 2.0F - 1.0F;
|
||||
double iY = this.random.nextFloat() * 2.0F - 1.0F;
|
||||
double iZ = this.random.nextFloat() * 2.0F - 1.0F;
|
||||
final double d3 = 0.05F + this.random.nextFloat() * 0.1F;
|
||||
double dist = iX * iX + iY * iY + iZ * iZ;
|
||||
|
||||
if (dist < 1.0D && dist > 0.01D) {
|
||||
dist = 1.0D / Math.sqrt(dist);
|
||||
iX *= dist;
|
||||
iY *= dist;
|
||||
iZ *= dist;
|
||||
final double x = iX * 100.0D;
|
||||
final double y = iY * 100.0D;
|
||||
final double z = iZ * 100.0D;
|
||||
final double d8 = Math.atan2(iX, iZ);
|
||||
final double d9 = Math.sin(d8);
|
||||
final double d10 = Math.cos(d8);
|
||||
final double d11 = Math.atan2(Math.sqrt(iX * iX + iZ * iZ), iY);
|
||||
final double d12 = Math.sin(d11);
|
||||
final double d13 = Math.cos(d11);
|
||||
final double d14 = this.random.nextDouble() * Math.PI * 2.0D;
|
||||
final double d15 = Math.sin(d14);
|
||||
final double d16 = Math.cos(d14);
|
||||
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
final double d17 = 0.0D;
|
||||
final double d18 = ((j & 2) - 1) * d3;
|
||||
final double d19 = ((j + 1 & 2) - 1) * d3;
|
||||
final double d20 = d18 * d16 - d19 * d15;
|
||||
final double d21 = d19 * d16 + d18 * d15;
|
||||
final double d22 = d20 * d12 + d17 * d13;
|
||||
final double d23 = d17 * d12 - d20 * d13;
|
||||
final double d24 = d23 * d9 - d21 * d10;
|
||||
final double d25 = d21 * d9 + d23 * d10;
|
||||
vb.pos(x + d24, y + d22, z + d25).endVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.util.ISlimReadableNumberConverter;
|
||||
import appeng.util.IWideReadableNumberConverter;
|
||||
import appeng.util.ReadableNumberConverter;
|
||||
|
||||
/**
|
||||
* @author AlgorithmX2
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv0
|
||||
*/
|
||||
public class StackSizeRenderer {
|
||||
private static final ISlimReadableNumberConverter SLIM_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
private static final IWideReadableNumberConverter WIDE_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
|
||||
public void renderStackSize(FontRenderer fontRenderer, IAEItemStack aeStack, int xPos, int yPos) {
|
||||
if (aeStack != null) {
|
||||
if (aeStack.getStackSize() == 0 && aeStack.isCraftable()) {
|
||||
final String craftLabelText = AEConfig.instance().isUseLargeFonts() ? GuiText.LargeFontCraft.getLocal()
|
||||
: GuiText.SmallFontCraft.getLocal();
|
||||
|
||||
renderSizeLabel(fontRenderer, xPos, yPos, craftLabelText);
|
||||
}
|
||||
|
||||
if (aeStack.getStackSize() > 0) {
|
||||
final String stackSize = this.getToBeRenderedStackSize(aeStack.getStackSize());
|
||||
|
||||
renderSizeLabel(fontRenderer, xPos, yPos, stackSize);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderSizeLabel(FontRenderer fontRenderer, float xPos, float yPos, String text) {
|
||||
|
||||
final float scaleFactor = AEConfig.instance().isUseLargeFonts() ? 0.85f : 0.5f;
|
||||
final float inverseScaleFactor = 1.0f / scaleFactor;
|
||||
final int offset = AEConfig.instance().isUseLargeFonts() ? 0 : -1;
|
||||
|
||||
AffineTransformation tm = new AffineTransformation(new Vector3f(0, 0, 300), // Taken from
|
||||
// ItemRenderer.renderItemOverlayIntoGUI
|
||||
null, new Vector3f(scaleFactor, scaleFactor, scaleFactor), null);
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
final int X = (int) ((xPos + offset + 16.0f - fontRenderer.getStringWidth(text) * scaleFactor)
|
||||
* inverseScaleFactor);
|
||||
final int Y = (int) ((yPos + offset + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor);
|
||||
VertexConsumerProvider.Impl buffer = VertexConsumerProvider.getImpl(Tessellator.getInstance().getBuffer());
|
||||
fontRenderer.renderString(text, X, Y, 16777215, true, tm.getMatrix(), buffer, false, 0, 15728880);
|
||||
buffer.finish();
|
||||
RenderSystem.enableBlend();
|
||||
}
|
||||
|
||||
private String getToBeRenderedStackSize(final long originalSize) {
|
||||
if (AEConfig.instance().isUseLargeFonts()) {
|
||||
return SLIM_CONVERTER.toSlimReadableForm(originalSize);
|
||||
} else {
|
||||
return WIDE_CONVERTER.toWideReadableForm(originalSize);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+5
-9
@@ -18,28 +18,24 @@
|
||||
|
||||
package appeng.client.render;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
/**
|
||||
* Returns the shades of a single AE color for tint indices 0, 1, and 2.
|
||||
*/
|
||||
public class StaticBlockColor implements BlockColorProvider {
|
||||
public class StaticItemColor implements ItemColorProvider {
|
||||
|
||||
private final AEColor color;
|
||||
|
||||
public StaticBlockColor(AEColor color) {
|
||||
public StaticItemColor(AEColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int tintIndex) {
|
||||
public int getColor(ItemStack stack, int tintIndex) {
|
||||
return this.color.getVariantByTintIndex(tintIndex);
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.IWideReadableNumberConverter;
|
||||
import appeng.util.ReadableNumberConverter;
|
||||
|
||||
/**
|
||||
* Helper methods for rendering TESRs.
|
||||
*/
|
||||
public class TesrRenderHelper {
|
||||
|
||||
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
|
||||
/**
|
||||
* Rotate the current coordinate system so it is on the face of the given block
|
||||
* side. This can be used to render on the given face as if it was a 2D canvas.
|
||||
*/
|
||||
public static void rotateToFace(MatrixStack mStack, Direction face, byte spin) {
|
||||
switch (face) {
|
||||
case UP:
|
||||
mStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(270));
|
||||
mStack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(-spin * 90.0F));
|
||||
break;
|
||||
|
||||
case DOWN:
|
||||
mStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90.0F));
|
||||
mStack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(spin * -90.0F));
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90.0F));
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-90.0F));
|
||||
break;
|
||||
|
||||
case NORTH:
|
||||
mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180.0F));
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO, A different approach will have to be used for this from TESRs, -covers,
|
||||
// i have ideas.
|
||||
/**
|
||||
* Render an item in 2D.
|
||||
*/
|
||||
public static void renderItem2d(MatrixStack matrixStack, VertexConsumerProvider buffers, ItemStack itemStack,
|
||||
float scale, int combinedLightIn, int combinedOverlayIn) {
|
||||
if (!itemStack.isEmpty()) {
|
||||
matrixStack.push();
|
||||
// Push it out of the block face a bit to avoid z-fighting
|
||||
matrixStack.translate(0, 0, 0.01f);
|
||||
// The Z-scaling by 0.0002 causes the model to be visually "flattened"
|
||||
// This cannot replace a proper projection, but it's cheap and gives the desired
|
||||
// effect at least from head-on
|
||||
matrixStack.scale(scale, scale, 0.0002f);
|
||||
|
||||
MinecraftClient.getInstance().getItemRenderer().renderItem(itemStack, ModelTransformation.Mode.GUI,
|
||||
combinedLightIn, OverlayTexture.NO_OVERLAY, matrixStack, buffers);
|
||||
|
||||
matrixStack.pop();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an item in 2D and the given text below it.
|
||||
*
|
||||
* @param matrixStack
|
||||
* @param buffers
|
||||
* @param spacing Specifies how far apart the item and the item stack
|
||||
* amount are rendered.
|
||||
* @param combinedLightIn
|
||||
* @param combinedOverlayIn
|
||||
*/
|
||||
public static void renderItem2dWithAmount(MatrixStack matrixStack, VertexConsumerProvider buffers,
|
||||
IAEItemStack itemStack, float itemScale, float spacing, int combinedLightIn, int combinedOverlayIn) {
|
||||
final ItemStack renderStack = itemStack.asItemStackRepresentation();
|
||||
|
||||
TesrRenderHelper.renderItem2d(matrixStack, buffers, renderStack, itemScale, combinedLightIn, combinedOverlayIn);
|
||||
|
||||
final long stackSize = itemStack.getStackSize();
|
||||
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm(stackSize);
|
||||
|
||||
// Render the item count
|
||||
final FontRenderer fr = MinecraftClient.getInstance().fontRenderer;
|
||||
final int width = fr.getStringWidth(renderedStackSize);
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0.0f, spacing, 0.02f);
|
||||
matrixStack.scale(1.0f / 62.0f, -1.0f / 62.0f, 1.0f / 62.0f);
|
||||
matrixStack.scale(0.5f, 0.5f, 0);
|
||||
matrixStack.translate(-0.5f * width, 0.0f, 0.5f);
|
||||
fr.renderString(renderedStackSize, 0, 0, -1, false, matrixStack.peek().getMatrix(), buffers, false, 0,
|
||||
15728880);
|
||||
matrixStack.pop();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,727 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* A helper class that builds quads for cable connections.
|
||||
*/
|
||||
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;
|
||||
|
||||
private final SmartCableTextures smartCableTextures;
|
||||
|
||||
CableBuilder(Function<SpriteIdentifier, Sprite> bakedTextureGetter) {
|
||||
this.coreTextures = new EnumMap<>(CableCoreType.class);
|
||||
|
||||
for (CableCoreType type : CableCoreType.values()) {
|
||||
EnumMap<AEColor, Sprite> colorTextures = new EnumMap<>(AEColor.class);
|
||||
|
||||
for (AEColor color : AEColor.values()) {
|
||||
colorTextures.put(color, bakedTextureGetter.apply(type.getTexture(color)));
|
||||
}
|
||||
|
||||
this.coreTextures.put(type, colorTextures);
|
||||
}
|
||||
|
||||
this.connectionTextures = new EnumMap<>(AECableType.class);
|
||||
|
||||
for (AECableType type : AECableType.VALIDCABLES) {
|
||||
EnumMap<AEColor, Sprite> colorTextures = new EnumMap<>(AEColor.class);
|
||||
|
||||
for (AEColor color : AEColor.values()) {
|
||||
colorTextures.put(color, bakedTextureGetter.apply(getConnectionTexture(type, color)));
|
||||
}
|
||||
|
||||
this.connectionTextures.put(type, colorTextures);
|
||||
}
|
||||
|
||||
this.smartCableTextures = new SmartCableTextures(bakedTextureGetter);
|
||||
}
|
||||
|
||||
static SpriteIdentifier getConnectionTexture(AECableType cableType, AEColor color) {
|
||||
String textureFolder;
|
||||
switch (cableType) {
|
||||
case GLASS:
|
||||
textureFolder = "parts/cable/glass/";
|
||||
break;
|
||||
case COVERED:
|
||||
textureFolder = "parts/cable/covered/";
|
||||
break;
|
||||
case SMART:
|
||||
textureFolder = "parts/cable/smart/";
|
||||
break;
|
||||
case DENSE_COVERED:
|
||||
textureFolder = "parts/cable/dense_covered/";
|
||||
break;
|
||||
case DENSE_SMART:
|
||||
textureFolder = "parts/cable/dense_smart/";
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Cable type " + cableType + " does not support connections.");
|
||||
}
|
||||
|
||||
return new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, textureFolder + color.name().toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the core of a cable to the given list of quads.
|
||||
*
|
||||
* The type of cable core is automatically deduced from the given cable type.
|
||||
*/
|
||||
public void addCableCore(AECableType cableType, AEColor color, List<BakedQuad> quadsOut) {
|
||||
switch (cableType) {
|
||||
case GLASS:
|
||||
this.addCableCore(CableCoreType.GLASS, color, quadsOut);
|
||||
break;
|
||||
case COVERED:
|
||||
case SMART:
|
||||
this.addCableCore(CableCoreType.COVERED, color, quadsOut);
|
||||
break;
|
||||
case DENSE_COVERED:
|
||||
case DENSE_SMART:
|
||||
this.addCableCore(CableCoreType.DENSE, color, quadsOut);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public void addCableCore(CableCoreType coreType, AEColor color, List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.coreTextures.get(coreType).get(color);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
switch (coreType) {
|
||||
case GLASS:
|
||||
cubeBuilder.addCube(6, 6, 6, 10, 10, 10);
|
||||
break;
|
||||
case COVERED:
|
||||
cubeBuilder.addCube(5, 5, 5, 11, 11, 11);
|
||||
break;
|
||||
case DENSE:
|
||||
cubeBuilder.addCube(3, 3, 3, 13, 13, 13);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addGlassConnection(Direction facing, AEColor cableColor, AECableType connectionType,
|
||||
boolean cableBusAdjacent, List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
// We render all faces except the one on the connection side
|
||||
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
|
||||
|
||||
// For to-machine connections, use a thicker end-cap for the connection
|
||||
if (connectionType != AECableType.GLASS && !cableBusAdjacent) {
|
||||
Sprite texture = this.connectionTextures.get(AECableType.COVERED).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
this.addBigCoveredCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.GLASS).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
cubeBuilder.addCube(6, 0, 6, 10, 6, 10);
|
||||
break;
|
||||
case EAST:
|
||||
cubeBuilder.addCube(10, 6, 6, 16, 10, 10);
|
||||
break;
|
||||
case NORTH:
|
||||
cubeBuilder.addCube(6, 6, 0, 10, 10, 6);
|
||||
break;
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(6, 6, 10, 10, 10, 16);
|
||||
break;
|
||||
case UP:
|
||||
cubeBuilder.addCube(6, 10, 6, 10, 16, 10);
|
||||
break;
|
||||
case WEST:
|
||||
cubeBuilder.addCube(0, 6, 6, 6, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addStraightGlassConnection(Direction facing, AEColor cableColor, List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
// We render all faces except the connection caps. We can do this because the
|
||||
// glass cable is the smallest one
|
||||
// and its ends will always be covered by something
|
||||
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing, facing.getOpposite())));
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.GLASS).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
case UP:
|
||||
cubeBuilder.addCube(6, 0, 6, 10, 16, 10);
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(6, 6, 0, 10, 10, 16);
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
cubeBuilder.addCube(0, 6, 6, 16, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addConstrainedGlassConnection(Direction facing, AEColor cableColor, int distanceFromEdge,
|
||||
List<BakedQuad> quadsOut) {
|
||||
|
||||
// Glass connections reach only 6 voxels from the edge
|
||||
if (distanceFromEdge >= 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.GLASS).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
cubeBuilder.addCube(6, distanceFromEdge, 6, 10, 6, 10);
|
||||
break;
|
||||
case EAST:
|
||||
cubeBuilder.addCube(10, 6, 6, 16 - distanceFromEdge, 10, 10);
|
||||
break;
|
||||
case NORTH:
|
||||
cubeBuilder.addCube(6, 6, distanceFromEdge, 10, 10, 6);
|
||||
break;
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(6, 6, 10, 10, 10, 16 - distanceFromEdge);
|
||||
break;
|
||||
case UP:
|
||||
cubeBuilder.addCube(6, 10, 6, 10, 16 - distanceFromEdge, 10);
|
||||
break;
|
||||
case WEST:
|
||||
cubeBuilder.addCube(distanceFromEdge, 6, 6, 6, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addCoveredConnection(Direction facing, AEColor cableColor, AECableType connectionType,
|
||||
boolean cableBusAdjacent, List<BakedQuad> quadsOut) {
|
||||
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
// We render all faces except the one on the connection side
|
||||
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.COVERED).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
// Draw a covered connection, if anything but glass is requested
|
||||
if (connectionType != AECableType.GLASS && !cableBusAdjacent) {
|
||||
this.addBigCoveredCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
addCoveredCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
public void addStraightCoveredConnection(Direction facing, AEColor cableColor, List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.COVERED).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
setStraightCableUVs(cubeBuilder, facing, 5, 11);
|
||||
|
||||
addStraightCoveredCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
private static void setStraightCableUVs(CubeBuilder cubeBuilder, Direction facing, int x, int y) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
case UP:
|
||||
cubeBuilder.setCustomUv(Direction.NORTH, x, 0, y, x);
|
||||
cubeBuilder.setCustomUv(Direction.EAST, x, 0, y, x);
|
||||
cubeBuilder.setCustomUv(Direction.SOUTH, x, 0, y, x);
|
||||
cubeBuilder.setCustomUv(Direction.WEST, x, 0, y, x);
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
cubeBuilder.setCustomUv(Direction.UP, 0, x, x, y);
|
||||
cubeBuilder.setCustomUv(Direction.DOWN, 0, x, x, y);
|
||||
cubeBuilder.setCustomUv(Direction.NORTH, 0, x, x, y);
|
||||
cubeBuilder.setCustomUv(Direction.SOUTH, 0, x, x, y);
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
cubeBuilder.setCustomUv(Direction.UP, x, 0, y, x);
|
||||
cubeBuilder.setCustomUv(Direction.DOWN, x, 0, y, x);
|
||||
cubeBuilder.setCustomUv(Direction.EAST, 0, x, x, y);
|
||||
cubeBuilder.setCustomUv(Direction.WEST, 0, x, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addConstrainedCoveredConnection(Direction facing, AEColor cableColor, int distanceFromEdge,
|
||||
List<BakedQuad> quadsOut) {
|
||||
// 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);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.COVERED).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
addCoveredCableSizedCube(facing, distanceFromEdge, cubeBuilder);
|
||||
}
|
||||
|
||||
public void addSmartConnection(Direction facing, AEColor cableColor, AECableType connectionType,
|
||||
boolean cableBusAdjacent, int channels, List<BakedQuad> quadsOut) {
|
||||
if (connectionType == AECableType.COVERED || connectionType == AECableType.GLASS) {
|
||||
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
|
||||
return;
|
||||
}
|
||||
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
// We render all faces except the one on the connection side
|
||||
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.SMART).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
Sprite oddChannel = this.smartCableTextures.getOddTextureForChannels(channels);
|
||||
Sprite evenChannel = this.smartCableTextures.getEvenTextureForChannels(channels);
|
||||
|
||||
// For to-machine connections, use a thicker end-cap for the connection
|
||||
if (connectionType != AECableType.GLASS && !cableBusAdjacent) {
|
||||
this.addBigCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Render the channel indicators brightly lit at night
|
||||
cubeBuilder.setRenderFullBright(true);
|
||||
|
||||
cubeBuilder.setTexture(oddChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.blackVariant);
|
||||
this.addBigCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
cubeBuilder.setTexture(evenChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.whiteVariant);
|
||||
this.addBigCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Reset back to normal rendering for the rest
|
||||
cubeBuilder.setRenderFullBright(false);
|
||||
cubeBuilder.setTexture(texture);
|
||||
}
|
||||
|
||||
addCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Render the channel indicators brightly lit at night
|
||||
cubeBuilder.setRenderFullBright(true);
|
||||
|
||||
cubeBuilder.setTexture(oddChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.blackVariant);
|
||||
addCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
cubeBuilder.setTexture(evenChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.whiteVariant);
|
||||
addCoveredCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
public void addStraightSmartConnection(Direction facing, AEColor cableColor, int channels,
|
||||
List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.SMART).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
setStraightCableUVs(cubeBuilder, facing, 5, 11);
|
||||
|
||||
addStraightCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
Sprite oddChannel = this.smartCableTextures.getOddTextureForChannels(channels);
|
||||
Sprite evenChannel = this.smartCableTextures.getEvenTextureForChannels(channels);
|
||||
|
||||
// Render the channel indicators brightly lit at night
|
||||
cubeBuilder.setRenderFullBright(true);
|
||||
|
||||
cubeBuilder.setTexture(oddChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.blackVariant);
|
||||
addStraightCoveredCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
cubeBuilder.setTexture(evenChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.whiteVariant);
|
||||
addStraightCoveredCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
public void addConstrainedSmartConnection(Direction facing, AEColor cableColor, int distanceFromEdge, int channels,
|
||||
List<BakedQuad> quadsOut) {
|
||||
// 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
|
||||
if (distanceFromEdge >= 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.SMART).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
addCoveredCableSizedCube(facing, distanceFromEdge, cubeBuilder);
|
||||
|
||||
Sprite oddChannel = this.smartCableTextures.getOddTextureForChannels(channels);
|
||||
Sprite evenChannel = this.smartCableTextures.getEvenTextureForChannels(channels);
|
||||
|
||||
// Render the channel indicators brightly lit at night
|
||||
cubeBuilder.setRenderFullBright(true);
|
||||
|
||||
cubeBuilder.setTexture(oddChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.blackVariant);
|
||||
addCoveredCableSizedCube(facing, distanceFromEdge, cubeBuilder);
|
||||
|
||||
cubeBuilder.setTexture(evenChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.whiteVariant);
|
||||
addCoveredCableSizedCube(facing, distanceFromEdge, cubeBuilder);
|
||||
}
|
||||
|
||||
public void addDenseCoveredConnection(Direction facing, AEColor cableColor, AECableType connectionType,
|
||||
boolean cableBusAdjacent, List<BakedQuad> quadsOut) {
|
||||
// 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);
|
||||
return;
|
||||
}
|
||||
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
// We render all faces except the one on the connection side
|
||||
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.DENSE_COVERED).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
addDenseCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Reset back to normal rendering for the rest
|
||||
cubeBuilder.setRenderFullBright(false);
|
||||
cubeBuilder.setTexture(texture);
|
||||
}
|
||||
|
||||
public void addDenseSmartConnection(Direction facing, AEColor cableColor, AECableType connectionType,
|
||||
boolean cableBusAdjacent, int channels, List<BakedQuad> quadsOut) {
|
||||
// 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);
|
||||
return;
|
||||
} else if (connectionType == AECableType.COVERED || connectionType == AECableType.GLASS) {
|
||||
this.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
|
||||
return;
|
||||
} else if (connectionType == AECableType.DENSE_COVERED) {
|
||||
this.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent, quadsOut);
|
||||
return;
|
||||
}
|
||||
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
// We render all faces except the one on the connection side
|
||||
cubeBuilder.setDrawFaces(EnumSet.complementOf(EnumSet.of(facing)));
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.DENSE_SMART).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
addDenseCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Dense cables show used channels in groups of 4, rounded up
|
||||
channels = (channels + 3) / 4;
|
||||
|
||||
Sprite oddChannel = this.smartCableTextures.getOddTextureForChannels(channels);
|
||||
Sprite evenChannel = this.smartCableTextures.getEvenTextureForChannels(channels);
|
||||
|
||||
// Render the channel indicators brightly lit at night
|
||||
cubeBuilder.setRenderFullBright(true);
|
||||
|
||||
cubeBuilder.setTexture(oddChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.blackVariant);
|
||||
addDenseCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
cubeBuilder.setTexture(evenChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.whiteVariant);
|
||||
addDenseCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Reset back to normal rendering for the rest
|
||||
cubeBuilder.setRenderFullBright(false);
|
||||
cubeBuilder.setTexture(texture);
|
||||
}
|
||||
|
||||
public void addStraightDenseCoveredConnection(Direction facing, AEColor cableColor, List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.DENSE_COVERED).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
setStraightCableUVs(cubeBuilder, facing, 5, 11);
|
||||
|
||||
addStraightDenseCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
public void addStraightDenseSmartConnection(Direction facing, AEColor cableColor, int channels,
|
||||
List<BakedQuad> quadsOut) {
|
||||
CubeBuilder cubeBuilder = new CubeBuilder(quadsOut);
|
||||
|
||||
Sprite texture = this.connectionTextures.get(AECableType.DENSE_SMART).get(cableColor);
|
||||
cubeBuilder.setTexture(texture);
|
||||
|
||||
setStraightCableUVs(cubeBuilder, facing, 5, 11);
|
||||
|
||||
addStraightDenseCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
// Dense cables show used channels in groups of 4, rounded up
|
||||
channels = (channels + 3) / 4;
|
||||
|
||||
Sprite oddChannel = this.smartCableTextures.getOddTextureForChannels(channels);
|
||||
Sprite evenChannel = this.smartCableTextures.getEvenTextureForChannels(channels);
|
||||
|
||||
// Render the channel indicators brightly lit at night
|
||||
cubeBuilder.setRenderFullBright(true);
|
||||
|
||||
cubeBuilder.setTexture(oddChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.blackVariant);
|
||||
addStraightDenseCableSizedCube(facing, cubeBuilder);
|
||||
|
||||
cubeBuilder.setTexture(evenChannel);
|
||||
cubeBuilder.setColorRGB(cableColor.whiteVariant);
|
||||
addStraightDenseCableSizedCube(facing, cubeBuilder);
|
||||
}
|
||||
|
||||
private static void addDenseCableSizedCube(Direction facing, CubeBuilder cubeBuilder) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
cubeBuilder.addCube(4, 0, 4, 12, 5, 12);
|
||||
break;
|
||||
case EAST:
|
||||
cubeBuilder.addCube(11, 4, 4, 16, 12, 12);
|
||||
break;
|
||||
case NORTH:
|
||||
cubeBuilder.addCube(4, 4, 0, 12, 12, 5);
|
||||
break;
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(4, 4, 11, 12, 12, 16);
|
||||
break;
|
||||
case UP:
|
||||
cubeBuilder.addCube(4, 11, 4, 12, 16, 12);
|
||||
break;
|
||||
case WEST:
|
||||
cubeBuilder.addCube(0, 4, 4, 5, 12, 12);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a cube to the given cube builder that has the size of a dense cable
|
||||
// connection and spans the entire block
|
||||
// for the given direction
|
||||
private static void addStraightDenseCableSizedCube(Direction facing, CubeBuilder cubeBuilder) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
case UP:
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 3);
|
||||
cubeBuilder.addCube(3, 0, 3, 13, 16, 13);
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 0);
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
cubeBuilder.setUvRotation(Direction.SOUTH, 3);
|
||||
cubeBuilder.setUvRotation(Direction.NORTH, 3);
|
||||
cubeBuilder.addCube(0, 3, 3, 16, 13, 13);
|
||||
cubeBuilder.setUvRotation(Direction.SOUTH, 0);
|
||||
cubeBuilder.setUvRotation(Direction.NORTH, 0);
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 3);
|
||||
cubeBuilder.setUvRotation(Direction.WEST, 3);
|
||||
cubeBuilder.addCube(3, 3, 0, 13, 13, 16);
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 0);
|
||||
cubeBuilder.setUvRotation(Direction.WEST, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a cube to the given cube builder that has the size of a covered cable
|
||||
// connection from the core of the cable
|
||||
// to the given face
|
||||
private static void addCoveredCableSizedCube(Direction facing, CubeBuilder cubeBuilder) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
cubeBuilder.addCube(6, 0, 6, 10, 5, 10);
|
||||
break;
|
||||
case EAST:
|
||||
cubeBuilder.addCube(11, 6, 6, 16, 10, 10);
|
||||
break;
|
||||
case NORTH:
|
||||
cubeBuilder.addCube(6, 6, 0, 10, 10, 5);
|
||||
break;
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(6, 6, 11, 10, 10, 16);
|
||||
break;
|
||||
case UP:
|
||||
cubeBuilder.addCube(6, 11, 6, 10, 16, 10);
|
||||
break;
|
||||
case WEST:
|
||||
cubeBuilder.addCube(0, 6, 6, 5, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a cube to the given cube builder that has the size of a covered cable
|
||||
// connection and spans the entire block
|
||||
// for the given direction
|
||||
private static void addStraightCoveredCableSizedCube(Direction facing, CubeBuilder cubeBuilder) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
case UP:
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 3);
|
||||
cubeBuilder.addCube(5, 0, 5, 11, 16, 11);
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 0);
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
cubeBuilder.setUvRotation(Direction.SOUTH, 3);
|
||||
cubeBuilder.setUvRotation(Direction.NORTH, 3);
|
||||
cubeBuilder.addCube(0, 5, 5, 16, 11, 11);
|
||||
cubeBuilder.setUvRotation(Direction.SOUTH, 0);
|
||||
cubeBuilder.setUvRotation(Direction.NORTH, 0);
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 3);
|
||||
cubeBuilder.setUvRotation(Direction.WEST, 3);
|
||||
cubeBuilder.addCube(5, 5, 0, 11, 11, 16);
|
||||
cubeBuilder.setUvRotation(Direction.EAST, 0);
|
||||
cubeBuilder.setUvRotation(Direction.WEST, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addCoveredCableSizedCube(Direction facing, int distanceFromEdge, CubeBuilder cubeBuilder) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
cubeBuilder.addCube(6, distanceFromEdge, 6, 10, 5, 10);
|
||||
break;
|
||||
case EAST:
|
||||
cubeBuilder.addCube(11, 6, 6, 16 - distanceFromEdge, 10, 10);
|
||||
break;
|
||||
case NORTH:
|
||||
cubeBuilder.addCube(6, 6, distanceFromEdge, 10, 10, 5);
|
||||
break;
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(6, 6, 11, 10, 10, 16 - distanceFromEdge);
|
||||
break;
|
||||
case UP:
|
||||
cubeBuilder.addCube(6, 11, 6, 10, 16 - distanceFromEdge, 10);
|
||||
break;
|
||||
case WEST:
|
||||
cubeBuilder.addCube(distanceFromEdge, 6, 6, 5, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This renders a slightly bigger covered cable connection to the specified
|
||||
* side. This is used to connect cable cores with adjacent machines that do not
|
||||
* want to be connected to using a glass cable connection. This applies to most
|
||||
* machines (interfaces, etc.)
|
||||
*/
|
||||
private void addBigCoveredCableSizedCube(Direction facing, CubeBuilder cubeBuilder) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
cubeBuilder.addCube(5, 0, 5, 11, 4, 11);
|
||||
break;
|
||||
case EAST:
|
||||
cubeBuilder.addCube(12, 5, 5, 16, 11, 11);
|
||||
break;
|
||||
case NORTH:
|
||||
cubeBuilder.addCube(5, 5, 0, 11, 11, 4);
|
||||
break;
|
||||
case SOUTH:
|
||||
cubeBuilder.addCube(5, 5, 12, 11, 11, 16);
|
||||
break;
|
||||
case UP:
|
||||
cubeBuilder.addCube(5, 12, 5, 11, 16, 11);
|
||||
break;
|
||||
case WEST:
|
||||
cubeBuilder.addCube(0, 5, 5, 4, 11, 11);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get all textures needed for building the actual cable quads
|
||||
public static List<SpriteIdentifier> getTextures() {
|
||||
List<SpriteIdentifier> locations = new ArrayList<>();
|
||||
|
||||
for (CableCoreType coreType : CableCoreType.values()) {
|
||||
for (AEColor color : AEColor.values()) {
|
||||
locations.add(coreType.getTexture(color));
|
||||
}
|
||||
}
|
||||
|
||||
for (AECableType cableType : AECableType.VALIDCABLES) {
|
||||
for (AEColor color : AEColor.values()) {
|
||||
locations.add(getConnectionTexture(cableType, color));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.addAll(locations, SmartCableTextures.SMART_CHANNELS_TEXTURES);
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
public Sprite getCoreTexture(CableCoreType coreType, AEColor color) {
|
||||
return this.coreTextures.get(coreType).get(color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
||||
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;
|
||||
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.fabricmc.fabric.impl.client.indigo.renderer.IndigoRenderer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
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.MissingSprite;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CableBusBakedModel implements BakedModel, FabricBakedModel {
|
||||
|
||||
// FIXME: This entire cache seems dumb as shit
|
||||
private static final Map<CableBusRenderState, Mesh> CABLE_MODEL_CACHE = new HashMap<>();
|
||||
|
||||
private final CableBuilder cableBuilder;
|
||||
|
||||
private final FacadeBuilder facadeBuilder;
|
||||
|
||||
private final Map<Identifier, BakedModel> partModels;
|
||||
|
||||
private final Sprite particleTexture;
|
||||
|
||||
CableBusBakedModel(CableBuilder cableBuilder, FacadeBuilder facadeBuilder,
|
||||
Map<Identifier, BakedModel> partModels, Sprite particleTexture) {
|
||||
this.cableBuilder = cableBuilder;
|
||||
this.facadeBuilder = facadeBuilder;
|
||||
this.partModels = partModels;
|
||||
this.particleTexture = particleTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
// This model will only ever be used for blocks
|
||||
}
|
||||
|
||||
private CableBusRenderState getRenderState(BlockRenderView blockView, BlockPos pos) {
|
||||
|
||||
RenderAttachedBlockView renderAttachedBlockView = (RenderAttachedBlockView) blockView;
|
||||
Object renderAttachment = renderAttachedBlockView.getBlockEntityRenderAttachment(pos);
|
||||
if (renderAttachment instanceof CableBusRenderState) {
|
||||
return (CableBusRenderState) renderAttachment;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
|
||||
CableBusRenderState renderState = getRenderState(blockView, pos);
|
||||
|
||||
if (renderState == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderLayer layer = RenderLayer.getCutout(); // FIXME: Fabric can only render within one layer (?)
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.facadeBuilder.buildFacadeQuads(layer, renderState, randomSupplier, context, this.partModels::get);
|
||||
}
|
||||
|
||||
// Determines whether a cable is connected to exactly two sides that are
|
||||
// opposite each other
|
||||
private static boolean isStraightLine(AECableType cableType, EnumMap<Direction, AECableType> sides) {
|
||||
final Iterator<Entry<Direction, AECableType>> it = sides.entrySet().iterator();
|
||||
if (!it.hasNext()) {
|
||||
return false; // No connections
|
||||
}
|
||||
|
||||
final Entry<Direction, AECableType> nextConnection = it.next();
|
||||
final Direction firstSide = nextConnection.getKey();
|
||||
final AECableType firstType = nextConnection.getValue();
|
||||
|
||||
if (!it.hasNext()) {
|
||||
return false; // Only a single connection
|
||||
}
|
||||
if (firstSide.getOpposite() != it.next().getKey()) {
|
||||
return false; // Connected to two sides that are not opposite each other
|
||||
}
|
||||
if (it.hasNext()) {
|
||||
return false; // Must not have any other connection points
|
||||
}
|
||||
|
||||
final AECableType secondType = sides.get(firstSide.getOpposite());
|
||||
|
||||
return firstType == secondType && cableType == firstType && cableType == secondType;
|
||||
}
|
||||
|
||||
private Mesh buildCableModel(CableBusRenderState renderState) {
|
||||
AECableType cableType = renderState.getCableType();
|
||||
if (cableType == AECableType.NONE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AEColor cableColor = renderState.getCableColor();
|
||||
EnumMap<Direction, AECableType> connectionTypes = renderState.getConnectionTypes();
|
||||
|
||||
MeshBuilder builder = IndigoRenderer.INSTANCE.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 }
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of texture sprites appropriate for particles (digging, etc.)
|
||||
* given the render state for a cable bus.
|
||||
*/
|
||||
public List<Sprite> getParticleTextures(CableBusRenderState renderState) {
|
||||
CableCoreType coreType = CableCoreType.fromCableType(renderState.getCableType());
|
||||
AEColor cableColor = renderState.getCableColor();
|
||||
|
||||
List<Sprite> result = new ArrayList<>();
|
||||
|
||||
if (coreType != null) {
|
||||
result.add(this.cableBuilder.getCoreTexture(coreType, cableColor));
|
||||
}
|
||||
|
||||
// If no core is present, just use the first part that comes into play
|
||||
for (Direction side : renderState.getAttachments().keySet()) {
|
||||
IPartModel partModel = renderState.getAttachments().get(side);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Sprite particleTexture = bakedModel.getSprite();
|
||||
|
||||
// If a part sub-model has no particle texture (indicated by it being the
|
||||
// missing texture),
|
||||
// don't add it, so we don't get ugly missing texture break particles.
|
||||
if (!isMissingTexture(particleTexture)) {
|
||||
result.add(particleTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isMissingTexture(Sprite particleTexture) {
|
||||
return particleTexture instanceof MissingSprite;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.particleTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return ModelTransformation.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
CABLE_MODEL_CACHE.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaAdapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction face, Random random) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import net.minecraft.client.particle.ParticleTextureSheet;
|
||||
import net.minecraft.client.particle.SpriteBillboardParticle;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
// Derived from Vanilla's BreakingParticle, but allows
|
||||
// a texture to be specified directly rather than via an itemstack
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class CableBusBreakingParticle extends SpriteBillboardParticle {
|
||||
|
||||
private final float field_217571_C;
|
||||
private final float field_217572_F;
|
||||
|
||||
public CableBusBreakingParticle(ClientWorld world, double x, double y, double z, double speedX, double speedY,
|
||||
double speedZ, Sprite sprite) {
|
||||
super(world, x, y, z, speedX, speedY, speedZ);
|
||||
this.setSprite(sprite);
|
||||
this.gravityStrength = 1.0F;
|
||||
this.scale /= 2.0F;
|
||||
this.field_217571_C = this.random.nextFloat() * 3.0F;
|
||||
this.field_217572_F = this.random.nextFloat() * 3.0F;
|
||||
}
|
||||
|
||||
public CableBusBreakingParticle(ClientWorld world, double x, double y, double z, Sprite sprite) {
|
||||
this(world, x, y, z, 0, 0, 0, sprite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
return ParticleTextureSheet.TERRAIN_SHEET;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMinU() {
|
||||
return this.sprite.getFrameU((this.field_217571_C + 1.0F) / 4.0F * 16.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMaxU() {
|
||||
return this.sprite.getFrameU(this.field_217571_C / 4.0F * 16.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMinV() {
|
||||
return this.sprite.getFrameV(this.field_217572_F / 4.0F * 16.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMaxV() {
|
||||
return this.sprite.getFrameV((this.field_217572_F + 1.0F) / 4.0F * 16.0F);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.registries.PartModels;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The built-in model for the cable bus block.
|
||||
*/
|
||||
public class CableBusModel implements UnbakedModel {
|
||||
|
||||
private final PartModels partModels;
|
||||
|
||||
public CableBusModel(PartModels partModels) {
|
||||
this.partModels = partModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Identifier> getModelDependencies() {
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
|
||||
Map<Identifier, BakedModel> partModels = this.loadPartModels(loader, rotationContainer);
|
||||
|
||||
CableBuilder cableBuilder = new CableBuilder(textureGetter);
|
||||
FacadeBuilder facadeBuilder = new FacadeBuilder();
|
||||
|
||||
// This should normally not be used, but we *have* to provide a particle texture
|
||||
// or otherwise damage models will
|
||||
// crash
|
||||
Sprite particleTexture = cableBuilder.getCoreTexture(CableCoreType.GLASS, AEColor.TRANSPARENT);
|
||||
|
||||
return new CableBusBakedModel(cableBuilder, facadeBuilder, partModels, particleTexture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier, UnbakedModel> unbakedModelGetter, Set<Pair<String, String>> unresolvedTextureReferences) {
|
||||
return Collections.unmodifiableList(CableBuilder.getTextures());
|
||||
}
|
||||
|
||||
private Map<Identifier, BakedModel> loadPartModels(ModelLoader loader,
|
||||
ModelBakeSettings rotationContainer) {
|
||||
ImmutableMap.Builder<Identifier, BakedModel> result = ImmutableMap.builder();
|
||||
|
||||
for (Identifier location : this.partModels.getModels()) {
|
||||
BakedModel bakedModel = loader.bake(location, rotationContainer);
|
||||
if (bakedModel == null) {
|
||||
AELog.warn("Failed to bake part model {}", location);
|
||||
} else {
|
||||
result.put(location, bakedModel);
|
||||
}
|
||||
}
|
||||
|
||||
return result.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.registries.PartModels;
|
||||
import net.fabricmc.fabric.api.client.model.ModelProviderContext;
|
||||
import net.fabricmc.fabric.api.client.model.ModelProviderException;
|
||||
import net.fabricmc.fabric.api.client.model.ModelResourceProvider;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class CableBusModelLoader implements ModelResourceProvider {
|
||||
|
||||
private static final Identifier CABLE_BUS_MODEL = AppEng.makeId("block/cable_bus");
|
||||
|
||||
private final PartModels partModels;
|
||||
|
||||
public CableBusModelLoader(PartModels partModels) {
|
||||
this.partModels = partModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context) throws ModelProviderException {
|
||||
if (CABLE_BUS_MODEL.equals(resourceId)) {
|
||||
CableBusBakedModel.clearCache();
|
||||
return new CableBusModel(partModels);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
/**
|
||||
* This class captures the entire rendering state needed for a cable bus and
|
||||
* transports it to the rendering thread for processing.
|
||||
*/
|
||||
public class CableBusRenderState {
|
||||
|
||||
// The cable type used for rendering the outgoing connections to other blocks
|
||||
// and attached parts
|
||||
private AECableType cableType = AECableType.NONE;
|
||||
|
||||
// The type to use for rendering the core of the cable.
|
||||
private CableCoreType coreType;
|
||||
|
||||
private AEColor cableColor = AEColor.TRANSPARENT;
|
||||
|
||||
// Describes the outgoing connections of this cable bus to other blocks, and how
|
||||
// they should be rendered
|
||||
private EnumMap<Direction, AECableType> connectionTypes = new EnumMap<>(Direction.class);
|
||||
|
||||
// Indicate on which sides signified by connectionTypes above, there is another
|
||||
// cable bus. If a side is connected,
|
||||
// but it is absent from this
|
||||
// set, then it means that there is a Grid host, but not a cable bus on that
|
||||
// side (i.e. an interface, a controller,
|
||||
// etc.)
|
||||
private EnumSet<Direction> cableBusAdjacent = EnumSet.noneOf(Direction.class);
|
||||
|
||||
// Specifies the number of channels used for the connection to a given side.
|
||||
// Only contains entries if
|
||||
// connections contains a corresponding entry.
|
||||
private EnumMap<Direction, Integer> channelsOnSide = new EnumMap<>(Direction.class);
|
||||
|
||||
private EnumMap<Direction, IPartModel> attachments = new EnumMap<>(Direction.class);
|
||||
|
||||
// For each attachment, this contains the distance from the edge until which a
|
||||
// cable connection should be drawn
|
||||
private EnumMap<Direction, Integer> attachmentConnections = new EnumMap<>(Direction.class);
|
||||
|
||||
// Contains the facade to use for each side that has a facade attached
|
||||
private EnumMap<Direction, FacadeRenderState> facades = new EnumMap<>(Direction.class);
|
||||
|
||||
// Used for Facades.
|
||||
private WeakReference<BlockRenderView> world;
|
||||
private BlockPos pos;
|
||||
|
||||
// Contains the bounding boxes of all parts on the cable bus to allow facades to
|
||||
// cut out holes for the parts. This
|
||||
// list is only populated if there are
|
||||
// facades on this cable bus
|
||||
private List<Box> boundingBoxes = new ArrayList<>();
|
||||
|
||||
// Additional model data passed to the part models
|
||||
private EnumMap<Direction, Object> partModelData = new EnumMap<>(Direction.class);
|
||||
|
||||
public CableCoreType getCoreType() {
|
||||
return this.coreType;
|
||||
}
|
||||
|
||||
public void setCoreType(CableCoreType coreType) {
|
||||
this.coreType = coreType;
|
||||
}
|
||||
|
||||
public AECableType getCableType() {
|
||||
return this.cableType;
|
||||
}
|
||||
|
||||
public void setCableType(AECableType cableType) {
|
||||
this.cableType = cableType;
|
||||
}
|
||||
|
||||
public AEColor getCableColor() {
|
||||
return this.cableColor;
|
||||
}
|
||||
|
||||
public void setCableColor(AEColor cableColor) {
|
||||
this.cableColor = cableColor;
|
||||
}
|
||||
|
||||
public EnumMap<Direction, Integer> getChannelsOnSide() {
|
||||
return this.channelsOnSide;
|
||||
}
|
||||
|
||||
public EnumMap<Direction, AECableType> getConnectionTypes() {
|
||||
return this.connectionTypes;
|
||||
}
|
||||
|
||||
public void setConnectionTypes(EnumMap<Direction, AECableType> connectionTypes) {
|
||||
this.connectionTypes = connectionTypes;
|
||||
}
|
||||
|
||||
public void setChannelsOnSide(EnumMap<Direction, Integer> channelsOnSide) {
|
||||
this.channelsOnSide = channelsOnSide;
|
||||
}
|
||||
|
||||
public EnumSet<Direction> getCableBusAdjacent() {
|
||||
return this.cableBusAdjacent;
|
||||
}
|
||||
|
||||
public void setCableBusAdjacent(EnumSet<Direction> cableBusAdjacent) {
|
||||
this.cableBusAdjacent = cableBusAdjacent;
|
||||
}
|
||||
|
||||
public EnumMap<Direction, IPartModel> getAttachments() {
|
||||
return this.attachments;
|
||||
}
|
||||
|
||||
public EnumMap<Direction, Integer> getAttachmentConnections() {
|
||||
return this.attachmentConnections;
|
||||
}
|
||||
|
||||
public EnumMap<Direction, FacadeRenderState> getFacades() {
|
||||
return this.facades;
|
||||
}
|
||||
|
||||
public BlockRenderView getWorld() {
|
||||
return this.world.get();
|
||||
}
|
||||
|
||||
public void setWorld(BlockRenderView world) {
|
||||
this.world = new WeakReference<>(world);
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
public void setPos(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public List<Box> getBoundingBoxes() {
|
||||
return this.boundingBoxes;
|
||||
}
|
||||
|
||||
public EnumMap<Direction, Object> getPartModelData() {
|
||||
return this.partModelData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.attachmentConnections == null) ? 0 : this.attachmentConnections.hashCode());
|
||||
result = prime * result + ((this.cableBusAdjacent == null) ? 0 : this.cableBusAdjacent.hashCode());
|
||||
result = prime * result + ((this.cableColor == null) ? 0 : this.cableColor.hashCode());
|
||||
result = prime * result + ((this.cableType == null) ? 0 : this.cableType.hashCode());
|
||||
result = prime * result + ((this.channelsOnSide == null) ? 0 : this.channelsOnSide.hashCode());
|
||||
result = prime * result + ((this.connectionTypes == null) ? 0 : this.connectionTypes.hashCode());
|
||||
result = prime * result + ((this.coreType == null) ? 0 : this.coreType.hashCode());
|
||||
result = prime * result + ((this.partModelData == null) ? 0 : this.partModelData.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final CableBusRenderState other = (CableBusRenderState) obj;
|
||||
|
||||
return this.cableColor == other.cableColor && this.cableType == other.cableType
|
||||
&& this.coreType == other.coreType
|
||||
&& Objects.equals(this.attachmentConnections, other.attachmentConnections)
|
||||
&& Objects.equals(this.cableBusAdjacent, other.cableBusAdjacent)
|
||||
&& Objects.equals(this.channelsOnSide, other.channelsOnSide)
|
||||
&& Objects.equals(this.connectionTypes, other.connectionTypes)
|
||||
&& Objects.equals(this.partModelData, other.partModelData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* AE can render the core of a cable (the core that connections are made to, in
|
||||
* case the cable is not a straight line) in three different ways: - Glass -
|
||||
* Covered (also used by the Smart Cable) - Dense
|
||||
*/
|
||||
public enum CableCoreType {
|
||||
GLASS("parts/cable/core/glass"), COVERED("parts/cable/core/covered"), DENSE("parts/cable/core/dense_smart");
|
||||
|
||||
private static final Map<AECableType, CableCoreType> cableMapping = generateCableMapping();
|
||||
|
||||
/**
|
||||
* Creates the mapping that assigns a cable core type to an AE cable type.
|
||||
*/
|
||||
private static Map<AECableType, CableCoreType> generateCableMapping() {
|
||||
|
||||
Map<AECableType, CableCoreType> result = new EnumMap<>(AECableType.class);
|
||||
|
||||
result.put(AECableType.GLASS, CableCoreType.GLASS);
|
||||
result.put(AECableType.COVERED, CableCoreType.COVERED);
|
||||
result.put(AECableType.SMART, CableCoreType.COVERED);
|
||||
result.put(AECableType.DENSE_COVERED, CableCoreType.DENSE);
|
||||
result.put(AECableType.DENSE_SMART, CableCoreType.DENSE);
|
||||
|
||||
return ImmutableMap.copyOf(result);
|
||||
}
|
||||
|
||||
private final String textureFolder;
|
||||
|
||||
CableCoreType(String textureFolder) {
|
||||
this.textureFolder = textureFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The type of core that should be rendered when the given cable isn't
|
||||
* straight and needs to have a core to attach connections to. Is null
|
||||
* for the NULL cable.
|
||||
*/
|
||||
public static CableCoreType fromCableType(AECableType cableType) {
|
||||
return cableMapping.get(cableType);
|
||||
}
|
||||
|
||||
public SpriteIdentifier getTexture(AEColor color) {
|
||||
return new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, this.textureFolder + "/" + color.name().toLowerCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
/*
|
||||
* 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.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;
|
||||
|
||||
/**
|
||||
* Builds the quads for a cube.
|
||||
*/
|
||||
@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);
|
||||
|
||||
private final EnumMap<Direction, Vector4f> customUv = new EnumMap<>(Direction.class);
|
||||
|
||||
private final byte[] uvRotations = new byte[Direction.values().length];
|
||||
|
||||
private int color = 0xFFFFFFFF;
|
||||
|
||||
private boolean useStandardUV = false;
|
||||
|
||||
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 void addCube(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
x1 /= 16.0f;
|
||||
y1 /= 16.0f;
|
||||
z1 /= 16.0f;
|
||||
x2 /= 16.0f;
|
||||
y2 /= 16.0f;
|
||||
z2 /= 16.0f;
|
||||
|
||||
for (Direction face : this.drawFaces) {
|
||||
this.putFace(face, x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
}
|
||||
|
||||
public void addQuad(Direction face, float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
this.putFace(face, x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
private static final class UvVector {
|
||||
float u1;
|
||||
float u2;
|
||||
float v1;
|
||||
float v2;
|
||||
}
|
||||
|
||||
private void putFace(Direction face, float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
|
||||
Sprite texture = this.textures.get(face);
|
||||
|
||||
QuadEmitter emitter = this.emitter;
|
||||
emitter.colorIndex(-1)
|
||||
.nominalFace(face);
|
||||
|
||||
UvVector uv = new UvVector();
|
||||
|
||||
// The user might have set specific UV coordinates for this face
|
||||
Vector4f customUv = this.customUv.get(face);
|
||||
if (customUv != null) {
|
||||
uv.u1 = texture.getFrameU(customUv.getX());
|
||||
uv.v1 = texture.getFrameV(customUv.getY());
|
||||
uv.u2 = texture.getFrameU(customUv.getZ());
|
||||
uv.v2 = texture.getFrameV(customUv.getW());
|
||||
} else if (this.useStandardUV) {
|
||||
uv = this.getStandardUv(face, texture, x1, y1, z1, x2, y2, z2);
|
||||
} else {
|
||||
uv = this.getDefaultUv(face, texture, x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
this.putVertexTR(face, x2, y1, z1, uv);
|
||||
this.putVertexBR(face, x2, y1, z2, uv);
|
||||
this.putVertexBL(face, x1, y1, z2, uv);
|
||||
this.putVertexTL(face, x1, y1, z1, uv);
|
||||
break;
|
||||
case UP:
|
||||
this.putVertexTL(face, x1, y2, z1, uv);
|
||||
this.putVertexBL(face, x1, y2, z2, uv);
|
||||
this.putVertexBR(face, x2, y2, z2, uv);
|
||||
this.putVertexTR(face, x2, y2, z1, uv);
|
||||
break;
|
||||
case NORTH:
|
||||
this.putVertexBR(face, x2, y2, z1, uv);
|
||||
this.putVertexTR(face, x2, y1, z1, uv);
|
||||
this.putVertexTL(face, x1, y1, z1, uv);
|
||||
this.putVertexBL(face, x1, y2, z1, uv);
|
||||
break;
|
||||
case SOUTH:
|
||||
this.putVertexBL(face, x1, y2, z2, uv);
|
||||
this.putVertexTL(face, x1, y1, z2, uv);
|
||||
this.putVertexTR(face, x2, y1, z2, uv);
|
||||
this.putVertexBR(face, x2, y2, z2, uv);
|
||||
break;
|
||||
case WEST:
|
||||
this.putVertexTL(face, x1, y1, z1, uv);
|
||||
this.putVertexTR(face, x1, y1, z2, uv);
|
||||
this.putVertexBR(face, x1, y2, z2, uv);
|
||||
this.putVertexBL(face, x1, y2, z1, uv);
|
||||
break;
|
||||
case EAST:
|
||||
this.putVertexBR(face, x2, y2, z1, uv);
|
||||
this.putVertexBL(face, x2, y2, z2, uv);
|
||||
this.putVertexTL(face, x2, y1, z2, uv);
|
||||
this.putVertexTR(face, x2, y1, z1, uv);
|
||||
break;
|
||||
}
|
||||
|
||||
if (renderFullBright) {
|
||||
// Force Brightness to 15, this is for full bright mode
|
||||
// this vertex element will only be present in that case
|
||||
int lightmap = LightmapTextureManager.pack(15, 15);
|
||||
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()));
|
||||
}
|
||||
|
||||
private UvVector getDefaultUv(Direction face, Sprite texture, float x1, float y1, float z1, float x2,
|
||||
float y2, float z2) {
|
||||
|
||||
UvVector uv = new UvVector();
|
||||
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(z1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(z2 * 16);
|
||||
break;
|
||||
case UP:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(z1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(z2 * 16);
|
||||
break;
|
||||
case NORTH:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
case SOUTH:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
case WEST:
|
||||
uv.u1 = texture.getFrameU(z1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(z2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
case EAST:
|
||||
uv.u1 = texture.getFrameU(z2 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(z1 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
}
|
||||
|
||||
return uv;
|
||||
}
|
||||
|
||||
private UvVector getStandardUv(Direction face, Sprite texture, float x1, float y1, float z1, float x2,
|
||||
float y2, float z2) {
|
||||
UvVector uv = new UvVector();
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - z1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - z2 * 16);
|
||||
break;
|
||||
case UP:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(z1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(z2 * 16);
|
||||
break;
|
||||
case NORTH:
|
||||
uv.u1 = texture.getFrameU(16 - x1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(16 - x2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
case SOUTH:
|
||||
uv.u1 = texture.getFrameU(x1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(x2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
case WEST:
|
||||
uv.u1 = texture.getFrameU(z1 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(z2 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
case EAST:
|
||||
uv.u1 = texture.getFrameU(16 - z2 * 16);
|
||||
uv.v1 = texture.getFrameV(16 - y1 * 16);
|
||||
uv.u2 = texture.getFrameU(16 - z1 * 16);
|
||||
uv.v2 = texture.getFrameV(16 - y2 * 16);
|
||||
break;
|
||||
}
|
||||
return uv;
|
||||
}
|
||||
|
||||
// uv.u1, uv.v1
|
||||
private void putVertexTL(Direction face, float x, float y, float z, UvVector uv) {
|
||||
float u, v;
|
||||
|
||||
switch (this.uvRotations[face.ordinal()]) {
|
||||
default:
|
||||
case 0:
|
||||
u = uv.u1;
|
||||
v = uv.v1;
|
||||
break;
|
||||
case 1: // 90° clockwise
|
||||
u = uv.u1;
|
||||
v = uv.v2;
|
||||
break;
|
||||
case 2: // 180° clockwise
|
||||
u = uv.u2;
|
||||
v = uv.v2;
|
||||
break;
|
||||
case 3: // 270° clockwise
|
||||
u = uv.u2;
|
||||
v = uv.v1;
|
||||
break;
|
||||
}
|
||||
|
||||
this.putVertex(face, x, y, z, u, v);
|
||||
}
|
||||
|
||||
// uv.u2, uv.v1
|
||||
private void putVertexTR(Direction face, float x, float y, float z, UvVector uv) {
|
||||
float u, v;
|
||||
|
||||
switch (this.uvRotations[face.ordinal()]) {
|
||||
default:
|
||||
case 0:
|
||||
u = uv.u2;
|
||||
v = uv.v1;
|
||||
break;
|
||||
case 1: // 90° clockwise
|
||||
u = uv.u1;
|
||||
v = uv.v1;
|
||||
break;
|
||||
case 2: // 180° clockwise
|
||||
u = uv.u1;
|
||||
v = uv.v2;
|
||||
break;
|
||||
case 3: // 270° clockwise
|
||||
u = uv.u2;
|
||||
v = uv.v2;
|
||||
break;
|
||||
}
|
||||
this.putVertex(face, x, y, z, u, v);
|
||||
}
|
||||
|
||||
// uv.u2, uv.v2
|
||||
private void putVertexBR(Direction face, float x, float y, float z, UvVector uv) {
|
||||
|
||||
float u;
|
||||
float v;
|
||||
|
||||
switch (this.uvRotations[face.ordinal()]) {
|
||||
default:
|
||||
case 0:
|
||||
u = uv.u2;
|
||||
v = uv.v2;
|
||||
break;
|
||||
case 1: // 90° clockwise
|
||||
u = uv.u2;
|
||||
v = uv.v1;
|
||||
break;
|
||||
case 2: // 180° clockwise
|
||||
u = uv.u1;
|
||||
v = uv.v1;
|
||||
break;
|
||||
case 3: // 270° clockwise
|
||||
u = uv.u1;
|
||||
v = uv.v2;
|
||||
break;
|
||||
}
|
||||
|
||||
this.putVertex(face, x, y, z, u, v);
|
||||
}
|
||||
|
||||
// uv.u1, uv.v2
|
||||
private void putVertexBL(Direction face, float x, float y, float z, UvVector uv) {
|
||||
|
||||
float u;
|
||||
float v;
|
||||
|
||||
switch (this.uvRotations[face.ordinal()]) {
|
||||
default:
|
||||
case 0:
|
||||
u = uv.u1;
|
||||
v = uv.v2;
|
||||
break;
|
||||
case 1: // 90° clockwise
|
||||
u = uv.u2;
|
||||
v = uv.v2;
|
||||
break;
|
||||
case 2: // 180° clockwise
|
||||
u = uv.u2;
|
||||
v = uv.v1;
|
||||
break;
|
||||
case 3: // 270° clockwise
|
||||
u = uv.u1;
|
||||
v = uv.v1;
|
||||
break;
|
||||
}
|
||||
|
||||
this.putVertex(face, x, y, z, u, v);
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
// Color format is RGBA
|
||||
emitter.spriteColor(vertexIndex, this.color);
|
||||
|
||||
emitter.sprite(vertexIndex, 0, u, v);
|
||||
|
||||
vertexIndex++;
|
||||
}
|
||||
|
||||
public void setTexture(Sprite texture) {
|
||||
for (Direction face : Direction.values()) {
|
||||
this.textures.put(face, texture);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextures(Sprite up, Sprite down, Sprite north,
|
||||
Sprite south, Sprite east, Sprite west) {
|
||||
this.textures.put(Direction.UP, up);
|
||||
this.textures.put(Direction.DOWN, down);
|
||||
this.textures.put(Direction.NORTH, north);
|
||||
this.textures.put(Direction.SOUTH, south);
|
||||
this.textures.put(Direction.EAST, east);
|
||||
this.textures.put(Direction.WEST, west);
|
||||
}
|
||||
|
||||
public void setTexture(Direction facing, Sprite sprite) {
|
||||
this.textures.put(facing, sprite);
|
||||
}
|
||||
|
||||
public void setDrawFaces(EnumSet<Direction> drawFaces) {
|
||||
this.drawFaces = drawFaces;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the vertex color for future vertices to the given RGB value, and forces
|
||||
* the alpha component to 255.
|
||||
*/
|
||||
public void setColorRGB(int color) {
|
||||
this.setColor(color | 0xFF000000);
|
||||
}
|
||||
|
||||
public void setColorRGB(float r, float g, float b) {
|
||||
this.setColorRGB((int) (r * 255) << 16 | (int) (g * 255) << 8 | (int) (b * 255));
|
||||
}
|
||||
|
||||
public void setRenderFullBright(boolean renderFullBright) {
|
||||
this.renderFullBright = renderFullBright;
|
||||
}
|
||||
|
||||
public void setCustomUv(Direction facing, float u1, float v1, float u2, float v2) {
|
||||
this.customUv.put(facing, new Vector4f(u1, v1, u2, v2));
|
||||
}
|
||||
|
||||
public void setUvRotation(Direction facing, int rotation) {
|
||||
if (rotation == 2) {
|
||||
rotation = 3;
|
||||
} else if (rotation == 3) {
|
||||
rotation = 2;
|
||||
}
|
||||
Preconditions.checkArgument(rotation >= 0 && rotation <= 3, "rotation");
|
||||
this.uvRotations[facing.ordinal()] = (byte) rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* CubeBuilder uses UV optimized for cables by default. This switches to
|
||||
* standard UV coordinates.
|
||||
*/
|
||||
public void useStandardUV() {
|
||||
this.useStandardUV = true;
|
||||
}
|
||||
|
||||
public List<BakedQuad> getOutput() {
|
||||
return this.output;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, 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.cablebus;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.level.ColorResolver;
|
||||
import net.minecraft.world.lighting.WorldLightManager;
|
||||
|
||||
/**
|
||||
* This is used to retrieve the ExtendedState of a block for facade rendering.
|
||||
* It fakes the block at BlockPos provided as the BlockState provided.
|
||||
*
|
||||
* @author covers1624
|
||||
*/
|
||||
public class FacadeBlockAccess implements BlockRenderView {
|
||||
|
||||
private final BlockRenderView world;
|
||||
private final BlockPos pos;
|
||||
private final Direction side;
|
||||
private final BlockState state;
|
||||
|
||||
public FacadeBlockAccess(BlockRenderView world, BlockPos pos, Direction side, BlockState state) {
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
this.side = side;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(BlockPos pos) {
|
||||
return this.world.getBlockEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
if (this.pos == pos) {
|
||||
return this.state;
|
||||
}
|
||||
return this.world.getBlockState(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockPos pos) {
|
||||
return world.getFluidState(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldLightManager getLightingProvider() {
|
||||
return world.getLightingProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockColor(BlockPos blockPosIn, ColorResolver colorResolverIn) {
|
||||
return world.getBlockColor(blockPosIn, colorResolverIn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, 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.cablebus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.util.AEAxisAlignedBB;
|
||||
import appeng.parts.misc.CableAnchorPart;
|
||||
/**
|
||||
* The FacadeBuilder builds for facades..
|
||||
*
|
||||
* @author covers1624
|
||||
*/
|
||||
public class FacadeBuilder {
|
||||
|
||||
public static final double THICK_THICKNESS = 2D / 16D;
|
||||
public static final double THIN_THICKNESS = 1D / 16D;
|
||||
|
||||
public static final Box[] THICK_FACADE_BOXES = new Box[] {
|
||||
new Box(0.0, 0.0, 0.0, 1.0, THICK_THICKNESS, 1.0),
|
||||
new Box(0.0, 1.0 - THICK_THICKNESS, 0.0, 1.0, 1.0, 1.0),
|
||||
new Box(0.0, 0.0, 0.0, 1.0, 1.0, THICK_THICKNESS),
|
||||
new Box(0.0, 0.0, 1.0 - THICK_THICKNESS, 1.0, 1.0, 1.0),
|
||||
new Box(0.0, 0.0, 0.0, THICK_THICKNESS, 1.0, 1.0),
|
||||
new Box(1.0 - THICK_THICKNESS, 0.0, 0.0, 1.0, 1.0, 1.0) };
|
||||
|
||||
public static final Box[] THIN_FACADE_BOXES = new Box[] {
|
||||
new Box(0.0, 0.0, 0.0, 1.0, THIN_THICKNESS, 1.0),
|
||||
new Box(0.0, 1.0 - THIN_THICKNESS, 0.0, 1.0, 1.0, 1.0),
|
||||
new Box(0.0, 0.0, 0.0, 1.0, 1.0, THIN_THICKNESS),
|
||||
new Box(0.0, 0.0, 1.0 - THIN_THICKNESS, 1.0, 1.0, 1.0),
|
||||
new Box(0.0, 0.0, 0.0, THIN_THICKNESS, 1.0, 1.0),
|
||||
new Box(1.0 - THIN_THICKNESS, 0.0, 0.0, 1.0, 1.0, 1.0) };
|
||||
|
||||
//FIXME private final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> BakedPipeline.builder()
|
||||
//FIXME // Clamper is responsible for clamping the vertex to the bounds specified.
|
||||
//FIXME .addElement("clamper", QuadClamper.FACTORY)
|
||||
//FIXME // Strips faces if they match a mask.
|
||||
//FIXME .addElement("face_stripper", QuadFaceStripper.FACTORY)
|
||||
//FIXME // Kicks the edge inner corners in, solves Z fighting
|
||||
//FIXME .addElement("corner_kicker", QuadCornerKicker.FACTORY)
|
||||
//FIXME // Re-Interpolates the UV's for the quad.
|
||||
//FIXME .addElement("interp", QuadReInterpolator.FACTORY)
|
||||
//FIXME // Tints the quad if we need it to. Disabled by default.
|
||||
//FIXME .addElement("tinter", QuadTinter.FACTORY, false)
|
||||
//FIXME // Overrides the quad's alpha if we are forcing transparent facades.
|
||||
//FIXME .addElement("transparent", QuadAlphaOverride.FACTORY, false, e -> e.setAlphaOverride(0x4C / 255F)).build()//
|
||||
//FIXME );
|
||||
//FIXME private final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
|
||||
|
||||
public void buildFacadeQuads(RenderLayer layer, CableBusRenderState renderState, Supplier<Random> rand,
|
||||
RenderContext context, Function<Identifier, BakedModel> modelLookup) {
|
||||
//FIXME BakedPipeline pipeline = this.pipelines.get();
|
||||
//FIXME Quad collectorQuad = this.collectors.get();
|
||||
boolean transparent = AEApi.instance().partHelper().getCableRenderMode().transparentFacades;
|
||||
Map<Direction, FacadeRenderState> facadeStates = renderState.getFacades();
|
||||
List<Box> partBoxes = renderState.getBoundingBoxes();
|
||||
Set<Direction> sidesWithParts = renderState.getAttachments().keySet();
|
||||
BlockRenderView parentWorld = renderState.getWorld();
|
||||
BlockPos pos = renderState.getPos();
|
||||
BlockColors blockColors = MinecraftClient.getInstance().getBlockColors();
|
||||
boolean thinFacades = isUseThinFacades(partBoxes);
|
||||
|
||||
for (Entry<Direction, FacadeRenderState> entry : facadeStates.entrySet()) {
|
||||
Direction side = entry.getKey();
|
||||
int sideIndex = side.ordinal();
|
||||
FacadeRenderState facadeRenderState = entry.getValue();
|
||||
boolean renderStilt = !sidesWithParts.contains(side);
|
||||
if (layer == RenderLayer.getCutout() && renderStilt) {
|
||||
context.pushTransform(QuadRotator.get(side, Direction.UP));
|
||||
for (Identifier part : CableAnchorPart.FACADE_MODELS.getModels()) {
|
||||
BakedModel partModel = modelLookup.apply(part);
|
||||
context.fallbackConsumer().accept(partModel);
|
||||
}
|
||||
context.popTransform();
|
||||
}
|
||||
// If we are forcing transparency and this isn't the Translucent layer.
|
||||
if (transparent && layer != RenderLayer.getTranslucent()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockState blockState = facadeRenderState.getSourceBlock();
|
||||
// If we aren't forcing transparency let the block decide if it should render.
|
||||
if (!transparent && layer != null) {
|
||||
// FIXME FABRIC only one layer per block
|
||||
// FIXME FABRIC if (!RenderLayers.canRenderInLayer(blockState, layer)) {
|
||||
// FIXME FABRIC continue;
|
||||
// FIXME FABRIC }
|
||||
}
|
||||
|
||||
Box fullBounds = thinFacades ? THIN_FACADE_BOXES[sideIndex] : THICK_FACADE_BOXES[sideIndex];
|
||||
Box facadeBox = fullBounds;
|
||||
// If we are a transparent facade, we need to modify out BB.
|
||||
if (facadeRenderState.isTransparent()) {
|
||||
double offset = thinFacades ? THIN_THICKNESS : THICK_THICKNESS;
|
||||
AEAxisAlignedBB tmpBB = null;
|
||||
for (Direction face : Direction.values()) {
|
||||
// Only faces that aren't on our axis
|
||||
if (face.getAxis() != side.getAxis()) {
|
||||
FacadeRenderState otherState = facadeStates.get(face);
|
||||
if (otherState != null && !otherState.isTransparent()) {
|
||||
if (tmpBB == null) {
|
||||
tmpBB = AEAxisAlignedBB.fromBounds(facadeBox);
|
||||
}
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
tmpBB.minY += offset;
|
||||
break;
|
||||
case UP:
|
||||
tmpBB.maxY -= offset;
|
||||
break;
|
||||
case NORTH:
|
||||
tmpBB.minZ += offset;
|
||||
break;
|
||||
case SOUTH:
|
||||
tmpBB.maxZ -= offset;
|
||||
break;
|
||||
case WEST:
|
||||
tmpBB.minX += offset;
|
||||
break;
|
||||
case EAST:
|
||||
tmpBB.maxX -= offset;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Switch falloff. " + String.valueOf(face));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tmpBB != null) {
|
||||
facadeBox = tmpBB.getBoundingBox();
|
||||
}
|
||||
}
|
||||
|
||||
AEAxisAlignedBB cutOutBox = getCutOutBox(facadeBox, partBoxes);
|
||||
List<Box> holeStrips = getBoxes(facadeBox, cutOutBox, side.getAxis());
|
||||
// FIXME BlockRenderView facadeAccess = new FacadeBlockAccess(parentWorld, pos, side, blockState);
|
||||
|
||||
// FIXME FABRIC BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
// FIXME FABRIC BakedModel model = dispatcher.getModel(blockState);
|
||||
// FIXME FABRIC IModelData modelData = model.getModelData(facadeAccess, pos, blockState, EmptyModelData.INSTANCE);
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC List<BakedQuad> modelQuads = new ArrayList<>();
|
||||
// FIXME FABRIC // If we are forcing transparent facades, fake the render layer, and grab all
|
||||
// FIXME FABRIC // quads.
|
||||
// FIXME FABRIC if (transparent || layer == null) {
|
||||
// FIXME FABRIC for (RenderLayer forcedLayer : RenderLayer.getBlockRenderTypes()) {
|
||||
// FIXME FABRIC // Check if the block renders on the layer we want to force.
|
||||
// FIXME FABRIC if (RenderLayers.canRenderInLayer(blockState, forcedLayer)) {
|
||||
// FIXME FABRIC // Force the layer and gather quads.
|
||||
// FIXME FABRIC ForgeHooksClient.setRenderLayer(forcedLayer);
|
||||
// FIXME FABRIC modelQuads.addAll(gatherQuads(model, blockState, rand, modelData));
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // Reset.
|
||||
// FIXME FABRIC ForgeHooksClient.setRenderLayer(layer);
|
||||
// FIXME FABRIC } else {
|
||||
// FIXME FABRIC modelQuads.addAll(gatherQuads(model, blockState, rand, modelData));
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // No quads.. Cool, next!
|
||||
// FIXME FABRIC if (modelQuads.isEmpty()) {
|
||||
// FIXME FABRIC continue;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // Grab out pipeline elements.
|
||||
// FIXME FABRIC QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
|
||||
// FIXME FABRIC QuadFaceStripper edgeStripper = pipeline.getElement("face_stripper", QuadFaceStripper.class);
|
||||
// FIXME FABRIC QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
|
||||
// FIXME FABRIC QuadCornerKicker kicker = pipeline.getElement("corner_kicker", QuadCornerKicker.class);
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // Set global element states.
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // calculate the side mask.
|
||||
// FIXME FABRIC int facadeMask = 0;
|
||||
// FIXME FABRIC for (Entry<Direction, FacadeRenderState> ent : facadeStates.entrySet()) {
|
||||
// FIXME FABRIC Direction s = ent.getKey();
|
||||
// FIXME FABRIC if (s.getAxis() != side.getAxis()) {
|
||||
// FIXME FABRIC FacadeRenderState otherState = ent.getValue();
|
||||
// FIXME FABRIC if (!otherState.isTransparent()) {
|
||||
// FIXME FABRIC facadeMask |= 1 << s.ordinal();
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC // Setup the edge stripper.
|
||||
// FIXME FABRIC edgeStripper.setBounds(fullBounds);
|
||||
// FIXME FABRIC edgeStripper.setMask(facadeMask);
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // Setup the kicker.
|
||||
// FIXME FABRIC kicker.setSide(sideIndex);
|
||||
// FIXME FABRIC kicker.setFacadeMask(facadeMask);
|
||||
// FIXME FABRIC kicker.setBox(fullBounds);
|
||||
// FIXME FABRIC kicker.setThickness(thinFacades ? THIN_THICKNESS : THICK_THICKNESS);
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC for (BakedQuad quad : modelQuads) {
|
||||
// FIXME FABRIC // lookup the format in CachedFormat.
|
||||
// FIXME FABRIC CachedFormat format = CachedFormat.lookup(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
|
||||
// FIXME FABRIC // If this quad has a tint index, setup the tinter.
|
||||
// FIXME FABRIC if (quad.hasTintIndex()) {
|
||||
// FIXME FABRIC tinter.setTint(blockColors.getColor(blockState, facadeAccess, pos, quad.getColorIndex()));
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC for (Box box : holeStrips) {
|
||||
// FIXME FABRIC // setup the clamper for this box
|
||||
// FIXME FABRIC clamper.setClampBounds(box);
|
||||
// FIXME FABRIC // Reset the pipeline, clears all enabled/disabled states.
|
||||
// FIXME FABRIC pipeline.reset(format);
|
||||
// FIXME FABRIC // Reset out collector.
|
||||
// FIXME FABRIC collectorQuad.reset(format);
|
||||
// FIXME FABRIC // Enable / disable the optional elements
|
||||
// FIXME FABRIC pipeline.setElementState("tinter", quad.hasTintIndex());
|
||||
// FIXME FABRIC pipeline.setElementState("transparent", transparent);
|
||||
// FIXME FABRIC // Prepare the pipeline for a quad.
|
||||
// FIXME FABRIC pipeline.prepare(collectorQuad);
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // Pipe our quad into the pipeline.
|
||||
// FIXME FABRIC quad.pipe(pipeline);
|
||||
// FIXME FABRIC // Check if the collector got any data.
|
||||
// FIXME FABRIC if (collectorQuad.full) {
|
||||
// FIXME FABRIC // Add the result.
|
||||
// FIXME FABRIC quads.add(collectorQuad.bake());
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is slow, so should be cached.
|
||||
*
|
||||
* @return The model.
|
||||
*/
|
||||
public List<BakedQuad> buildFacadeItemQuads(ItemStack textureItem, Direction side) {
|
||||
List<BakedQuad> facadeQuads = new ArrayList<>();
|
||||
|
||||
BakedModel model = MinecraftClient.getInstance().getItemRenderer().getHeldItemModel(textureItem, null,
|
||||
null);
|
||||
List<BakedQuad> modelQuads = gatherQuads(model, null, new Random());
|
||||
|
||||
//FIXME BakedPipeline pipeline = this.pipelines.get();
|
||||
//FIXME Quad collectorQuad = this.collectors.get();
|
||||
|
||||
// Grab pipeline elements.
|
||||
// FIXME QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
|
||||
// FIXME QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
|
||||
|
||||
for (BakedQuad quad : modelQuads) {
|
||||
// Lookup the CachedFormat for this quads format.
|
||||
// FIXME CachedFormat format = CachedFormat.lookup(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
|
||||
// Reset the pipeline.
|
||||
// FIXME pipeline.reset(format);
|
||||
// Reset the collector.
|
||||
//FIXME collectorQuad.reset(format);
|
||||
// If we have a tint index, setup the tinter and enable it.
|
||||
// FIXME if (quad.hasTintIndex()) {
|
||||
// FIXME tinter.setTint(MinecraftClient.getInstance().getItemColors().getColor(textureItem, quad.getColorIndex()));
|
||||
// FIXME pipeline.enableElement("tinter");
|
||||
// FIXME }
|
||||
// Disable elements we don't need for items.
|
||||
// FIXME pipeline.disableElement("face_stripper");
|
||||
// FIXME pipeline.disableElement("corner_kicker");
|
||||
// FIXME // Setup the clamper
|
||||
// FIXME clamper.setClampBounds(THICK_FACADE_BOXES[side.ordinal()]);
|
||||
// FIXME // Prepare the pipeline.
|
||||
// FIXME pipeline.prepare(collectorQuad);
|
||||
// FIXME // Pipe our quad into the pipeline.
|
||||
// FIXME quad.pipe(pipeline);
|
||||
// FIXME // Check the collector for data and add the quad if there was.
|
||||
// FIXME if (collectorQuad.full) {
|
||||
// FIXME facadeQuads.add(collectorQuad.bake());
|
||||
// FIXME }
|
||||
}
|
||||
return facadeQuads;
|
||||
}
|
||||
|
||||
// Helper to gather all quads from a model into a list.
|
||||
private static List<BakedQuad> gatherQuads(BakedModel model, BlockState state, Random rand) {
|
||||
List<BakedQuad> modelQuads = new ArrayList<>();
|
||||
for (Direction face : Direction.values()) {
|
||||
modelQuads.addAll(model.getQuads(state, face, rand));
|
||||
}
|
||||
modelQuads.addAll(model.getQuads(state, null, rand));
|
||||
return modelQuads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the actual facade bounding box, and the bounding boxes of all parts,
|
||||
* determine the biggest union of AABB that intersect with the facade's bounding
|
||||
* box. This AABB will need to be "cut out" when the facade is rendered.
|
||||
*/
|
||||
@Nullable
|
||||
private static AEAxisAlignedBB getCutOutBox(Box facadeBox, List<Box> partBoxes) {
|
||||
AEAxisAlignedBB b = null;
|
||||
for (Box bb : partBoxes) {
|
||||
if (bb.intersects(facadeBox)) {
|
||||
if (b == null) {
|
||||
b = AEAxisAlignedBB.fromBounds(bb);
|
||||
} else {
|
||||
b.maxX = Math.max(b.maxX, bb.maxX);
|
||||
b.maxY = Math.max(b.maxY, bb.maxY);
|
||||
b.maxZ = Math.max(b.maxZ, bb.maxZ);
|
||||
b.minX = Math.min(b.minX, bb.minX);
|
||||
b.minY = Math.min(b.minY, bb.minY);
|
||||
b.minZ = Math.min(b.minZ, bb.minZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the box segments around the specified hole. If the specified hole
|
||||
* is null, a Singleton of the Facade box is returned.
|
||||
*
|
||||
* @param fb The Facade's box.
|
||||
* @param hole The hole to 'cut'.
|
||||
* @param axis The axis the facade is on.
|
||||
*
|
||||
* @return The box segments.
|
||||
*/
|
||||
private static List<Box> getBoxes(Box fb, AEAxisAlignedBB hole, Axis axis) {
|
||||
if (hole == null) {
|
||||
return Collections.singletonList(fb);
|
||||
}
|
||||
List<Box> boxes = new ArrayList<>();
|
||||
switch (axis) {
|
||||
case Y:
|
||||
boxes.add(new Box(fb.minX, fb.minY, fb.minZ, hole.minX, fb.maxY, fb.maxZ));
|
||||
boxes.add(new Box(hole.maxX, fb.minY, fb.minZ, fb.maxX, fb.maxY, fb.maxZ));
|
||||
|
||||
boxes.add(new Box(hole.minX, fb.minY, fb.minZ, hole.maxX, fb.maxY, hole.minZ));
|
||||
boxes.add(new Box(hole.minX, fb.minY, hole.maxZ, hole.maxX, fb.maxY, fb.maxZ));
|
||||
|
||||
break;
|
||||
case Z:
|
||||
boxes.add(new Box(fb.minX, fb.minY, fb.minZ, fb.maxX, hole.minY, fb.maxZ));
|
||||
boxes.add(new Box(fb.minX, hole.maxY, fb.minZ, fb.maxX, fb.maxY, fb.maxZ));
|
||||
|
||||
boxes.add(new Box(fb.minX, hole.minY, fb.minZ, hole.minX, hole.maxY, fb.maxZ));
|
||||
boxes.add(new Box(hole.maxX, hole.minY, fb.minZ, fb.maxX, hole.maxY, fb.maxZ));
|
||||
|
||||
break;
|
||||
case X:
|
||||
boxes.add(new Box(fb.minX, fb.minY, fb.minZ, fb.maxX, hole.minY, fb.maxZ));
|
||||
boxes.add(new Box(fb.minX, hole.maxY, fb.minZ, fb.maxX, fb.maxY, fb.maxZ));
|
||||
|
||||
boxes.add(new Box(fb.minX, hole.minY, fb.minZ, fb.maxX, hole.maxY, hole.minZ));
|
||||
boxes.add(new Box(fb.minX, hole.minY, hole.maxZ, fb.maxX, hole.maxY, fb.maxZ));
|
||||
break;
|
||||
default:
|
||||
// should never happen.
|
||||
throw new RuntimeException("switch falloff. " + String.valueOf(axis));
|
||||
}
|
||||
|
||||
return boxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if any of the part's bounding boxes intersects with the outside 2
|
||||
* voxel wide layer. If so, we should use thinner facades (1 voxel deep).
|
||||
*/
|
||||
private static boolean isUseThinFacades(List<Box> partBoxes) {
|
||||
final double min = 2.0 / 16.0;
|
||||
final double max = 14.0 / 16.0;
|
||||
|
||||
for (Box bb : partBoxes) {
|
||||
int o = 0;
|
||||
o += bb.maxX > max ? 1 : 0;
|
||||
o += bb.maxY > max ? 1 : 0;
|
||||
o += bb.maxZ > max ? 1 : 0;
|
||||
o += bb.minX < min ? 1 : 0;
|
||||
o += bb.minY < min ? 1 : 0;
|
||||
o += bb.minZ < min ? 1 : 0;
|
||||
|
||||
if (o >= 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
||||
/**
|
||||
* Captures the state required to render a facade properly.
|
||||
*/
|
||||
public class FacadeRenderState {
|
||||
|
||||
// The block state to use for rendering this facade
|
||||
private final BlockState sourceBlock;
|
||||
|
||||
private final boolean transparent;
|
||||
|
||||
public FacadeRenderState(BlockState sourceBlock, boolean transparent) {
|
||||
this.sourceBlock = sourceBlock;
|
||||
this.transparent = transparent;
|
||||
}
|
||||
|
||||
public BlockState getSourceBlock() {
|
||||
return this.sourceBlock;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return this.transparent;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class P2PTunnelFrequencyBakedModel implements FabricBakedModel {
|
||||
|
||||
private final Sprite texture;
|
||||
|
||||
private final static Cache<Long, List<BakedQuad>> modelCache = CacheBuilder.newBuilder().maximumSize(100).build();
|
||||
|
||||
private static final int[][] QUAD_OFFSETS = new int[][] { { 4, 10, 2 }, { 10, 10, 2 }, { 4, 4, 2 }, { 10, 4, 2 } };
|
||||
|
||||
public P2PTunnelFrequencyBakedModel(final Sprite texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData modelData) {
|
||||
if (side != null || !(modelData instanceof P2PTunnelFrequencyModelData)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
P2PTunnelFrequencyModelData freqModelData = (P2PTunnelFrequencyModelData) modelData;
|
||||
|
||||
return this.getPartQuads(freqModelData.getFrequency());
|
||||
}
|
||||
|
||||
private List<BakedQuad> getQuadsForFrequency(final short frequency, final boolean active) {
|
||||
final AEColor[] colors = Platform.p2p().toColors(frequency);
|
||||
final CubeBuilder cb = new CubeBuilder();
|
||||
|
||||
cb.setTexture(this.texture);
|
||||
cb.useStandardUV();
|
||||
cb.setRenderFullBright(active);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
final int[] offs = QUAD_OFFSETS[i];
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
final AEColor c = colors[j];
|
||||
if (active) {
|
||||
cb.setColorRGB(c.dye.getColorValue());
|
||||
} else {
|
||||
final float[] cv = c.dye.getColorComponentValues();
|
||||
cb.setColorRGB(cv[0] * 0.5f, cv[1] * 0.5f, cv[2] * 0.5f);
|
||||
}
|
||||
|
||||
final int startx = j % 2;
|
||||
final int starty = 1 - j / 2;
|
||||
|
||||
cb.addCube(offs[0] + startx, offs[1] + starty, offs[2], offs[0] + startx + 1, offs[1] + starty + 1,
|
||||
offs[2] + 1);
|
||||
}
|
||||
|
||||
}
|
||||
return cb.getOutput();
|
||||
}
|
||||
|
||||
private List<BakedQuad> getPartQuads(long partFlags) {
|
||||
try {
|
||||
return modelCache.get(partFlags, () -> {
|
||||
short frequency = (short) (partFlags & 0xffffL);
|
||||
boolean active = (partFlags & 0x10000L) != 0;
|
||||
return this.getQuadsForFrequency(frequency, active);
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class P2PTunnelFrequencyModel implements IModelGeometry<P2PTunnelFrequencyModel> {
|
||||
private static final SpriteIdentifier TEXTURE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "parts/p2p_tunnel_frequency"));
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
try {
|
||||
final Sprite texture = spriteGetter.apply(TEXTURE);
|
||||
return new P2PTunnelFrequencyBakedModel(texture);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.singleton(TEXTURE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
|
||||
import appeng.client.render.model.AEInternalModelData;
|
||||
|
||||
public final class P2PTunnelFrequencyModelData extends AEInternalModelData {
|
||||
|
||||
public static final ModelProperty<Long> FREQUENCY = new ModelProperty<>();
|
||||
|
||||
private final long frequency;
|
||||
|
||||
public P2PTunnelFrequencyModelData(long frequency) {
|
||||
this.frequency = frequency;
|
||||
}
|
||||
|
||||
public long getFrequency() {
|
||||
return frequency;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
|
||||
/**
|
||||
* Assuming a default-orientation of forward=NORTH and up=UP, this class rotates
|
||||
* a given list of quads to the desired facing
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class QuadRotator implements RenderContext.QuadTransform {
|
||||
// FIXME private static final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> //
|
||||
// FIXME BakedPipeline.builder()//
|
||||
// FIXME .addElement("transformer", QuadMatrixTransformer.FACTORY)//
|
||||
// FIXME .build());
|
||||
// FIXME private static final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
|
||||
|
||||
private static final RenderContext.QuadTransform NULL_TRANSFORM = quad -> true;
|
||||
|
||||
private final FacingToRotation rotation;
|
||||
|
||||
public QuadRotator(FacingToRotation rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public static RenderContext.QuadTransform get(Direction newForward, Direction newUp) {
|
||||
if (newForward == Direction.NORTH && newUp == Direction.UP) {
|
||||
return NULL_TRANSFORM; // This is the default orientation
|
||||
}
|
||||
FacingToRotation rotation = getRotation(newForward, newUp);
|
||||
if (rotation.isRedundant()) {
|
||||
return NULL_TRANSFORM;
|
||||
}
|
||||
return new QuadRotator(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean transform(MutableQuadView quad) {
|
||||
|
||||
// FIXME: Temporary rotation fix
|
||||
Matrix4f mat = new Matrix4f();
|
||||
mat.addToLastColumn(new Vector3f(-0.5f, -0.5f, -0.5f));
|
||||
mat.multiply(rotation.getMat());
|
||||
mat.addToLastColumn(new Vector3f(0.5f, 0.5f, 0.5f));
|
||||
|
||||
// FIXME ROTATION pipeline.reset(format);
|
||||
// FIXME ROTATION collector.reset(format);
|
||||
// FIXME ROTATION
|
||||
// FIXME ROTATION transformer.setMatrix(mat);
|
||||
// FIXME ROTATION pipeline.prepare(collector);
|
||||
// FIXME ROTATION quad.pipe(pipeline);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static FacingToRotation getRotation(Direction forward, Direction up) {
|
||||
// Sanitize forward/up
|
||||
if (forward.getAxis() == up.getAxis()) {
|
||||
if (up.getAxis() == Direction.Axis.Y) {
|
||||
up = Direction.NORTH;
|
||||
} else {
|
||||
up = Direction.UP;
|
||||
}
|
||||
}
|
||||
|
||||
return FacingToRotation.get(forward, up);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.cablebus;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* Manages the channel textures for smart cables.
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class SmartCableTextures {
|
||||
|
||||
public static final SpriteIdentifier[] SMART_CHANNELS_TEXTURES = Arrays
|
||||
.stream(new Identifier[] { new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_00"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_01"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_02"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_03"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_04"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_10"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_11"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_12"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_13"), //
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/smart/channels_14")//
|
||||
}).map(e -> new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, e)).toArray(SpriteIdentifier[]::new);
|
||||
|
||||
// Textures used to display channels on smart cables. There's two sets of 5
|
||||
// textures each, and
|
||||
// one of each set are composed together to get even/odd colored channels
|
||||
private final Sprite[] textures;
|
||||
|
||||
public SmartCableTextures(Function<SpriteIdentifier, Sprite> bakedTextureGetter) {
|
||||
this.textures = Arrays.stream(SMART_CHANNELS_TEXTURES)//
|
||||
.map(bakedTextureGetter)//
|
||||
.toArray(Sprite[]::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* The odd variant is used for displaying channels 1-4 as in use.
|
||||
*/
|
||||
public Sprite getOddTextureForChannels(int channels) {
|
||||
if (channels < 0) {
|
||||
return this.textures[0];
|
||||
} else if (channels <= 4) {
|
||||
return this.textures[channels];
|
||||
} else {
|
||||
return this.textures[4];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The odd variant is used for displaying channels 5-8 as in use.
|
||||
*/
|
||||
public Sprite getEvenTextureForChannels(int channels) {
|
||||
if (channels < 5) {
|
||||
return this.textures[5];
|
||||
} else if (channels <= 8) {
|
||||
return this.textures[1 + channels];
|
||||
} else {
|
||||
return this.textures[9];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.tile.crafting.CraftingCubeModelData;
|
||||
import appeng.util.Platform;
|
||||
|
||||
/**
|
||||
* The base model for baked models used by components of the crafting cube
|
||||
* multi-block in it's formed state. Primarily this base class handles adding
|
||||
* the "ring" that frames the multi-block structure and delegates rendering of
|
||||
* the "inner" part of each block to the subclasses of this class.
|
||||
*/
|
||||
abstract class CraftingCubeBakedModel implements IDynamicBakedModel {
|
||||
|
||||
private final Sprite ringCorner;
|
||||
|
||||
private final Sprite ringHor;
|
||||
|
||||
private final Sprite ringVer;
|
||||
|
||||
CraftingCubeBakedModel(Sprite ringCorner, Sprite ringHor, Sprite ringVer) {
|
||||
this.ringCorner = ringCorner;
|
||||
this.ringHor = ringHor;
|
||||
this.ringVer = ringVer;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
|
||||
@Nonnull IModelData extraData) {
|
||||
if (side == null) {
|
||||
return Collections.emptyList(); // No generic quads for this model
|
||||
}
|
||||
|
||||
EnumSet<Direction> connections = getConnections(extraData);
|
||||
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
CubeBuilder builder = new CubeBuilder(quads);
|
||||
|
||||
builder.setDrawFaces(EnumSet.of(side));
|
||||
|
||||
// Add the quads for the ring that frames the entire multi-block structure
|
||||
this.addRing(builder, side, connections);
|
||||
|
||||
// Calculate the bounds of the "inner" block that is framed by the border drawn
|
||||
// above
|
||||
float x2 = connections.contains(Direction.EAST) ? 16 : 13.01f;
|
||||
float x1 = connections.contains(Direction.WEST) ? 0 : 2.99f;
|
||||
|
||||
float y2 = connections.contains(Direction.UP) ? 16 : 13.01f;
|
||||
float y1 = connections.contains(Direction.DOWN) ? 0 : 2.99f;
|
||||
|
||||
float z2 = connections.contains(Direction.SOUTH) ? 16 : 13.01f;
|
||||
float z1 = connections.contains(Direction.NORTH) ? 0 : 2.99f;
|
||||
|
||||
// On the axis of the side that we're currently drawing, extend the dimensions
|
||||
// out to the outer face of the block
|
||||
switch (side) {
|
||||
case DOWN:
|
||||
case UP:
|
||||
y1 = 0;
|
||||
y2 = 16;
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
z1 = 0;
|
||||
z2 = 16;
|
||||
break;
|
||||
case WEST:
|
||||
case EAST:
|
||||
x1 = 0;
|
||||
x2 = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
this.addInnerCube(side, state, extraData, builder, x1, y1, z1, x2, y2, z2);
|
||||
|
||||
return quads;
|
||||
}
|
||||
|
||||
private void addRing(CubeBuilder builder, @Nullable Direction side, EnumSet<Direction> connections) {
|
||||
// Fill in the corners
|
||||
builder.setTexture(this.ringCorner);
|
||||
this.addCornerCap(builder, connections, side, Direction.UP, Direction.EAST, Direction.NORTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.UP, Direction.EAST, Direction.SOUTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.UP, Direction.WEST, Direction.NORTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.UP, Direction.WEST, Direction.SOUTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.DOWN, Direction.EAST, Direction.NORTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.DOWN, Direction.EAST, Direction.SOUTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.DOWN, Direction.WEST, Direction.NORTH);
|
||||
this.addCornerCap(builder, connections, side, Direction.DOWN, Direction.WEST, Direction.SOUTH);
|
||||
|
||||
// Fill in the remaining stripes of the face
|
||||
for (Direction a : Direction.values()) {
|
||||
if (a == side || a == side.getOpposite()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Select the horizontal or vertical ring texture depending on which side we're
|
||||
// filling in
|
||||
if ((side.getAxis() != Direction.Axis.Y)
|
||||
&& (a == Direction.NORTH || a == Direction.EAST || a == Direction.WEST || a == Direction.SOUTH)) {
|
||||
builder.setTexture(this.ringVer);
|
||||
} else if (side.getAxis() == Direction.Axis.Y && (a == Direction.EAST || a == Direction.WEST)) {
|
||||
builder.setTexture(this.ringVer);
|
||||
} else {
|
||||
builder.setTexture(this.ringHor);
|
||||
}
|
||||
|
||||
// If there's an adjacent crafting cube block on side a, then the core of the
|
||||
// block already extends
|
||||
// fully to this side. So only bother drawing the stripe, if there's no
|
||||
// connection.
|
||||
if (!connections.contains(a)) {
|
||||
// Note that since we're drawing something that "looks" 2-dimensional,
|
||||
// two of the following will always be 0 and 16.
|
||||
float x1 = 0, y1 = 0, z1 = 0, x2 = 16, y2 = 16, z2 = 16;
|
||||
|
||||
switch (a) {
|
||||
case DOWN:
|
||||
y1 = 0;
|
||||
y2 = 3;
|
||||
break;
|
||||
case UP:
|
||||
y1 = 13.0f;
|
||||
y2 = 16;
|
||||
break;
|
||||
case WEST:
|
||||
x1 = 0;
|
||||
x2 = 3;
|
||||
break;
|
||||
case EAST:
|
||||
x1 = 13;
|
||||
x2 = 16;
|
||||
break;
|
||||
case NORTH:
|
||||
z1 = 0;
|
||||
z2 = 3;
|
||||
break;
|
||||
case SOUTH:
|
||||
z1 = 13;
|
||||
z2 = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
// Constraint the stripe in the two directions perpendicular to a in case there
|
||||
// has been a corner
|
||||
// drawn in those directions. Since a corner is drawn if the three touching
|
||||
// faces dont have adjacent
|
||||
// crafting cube blocks, we'd have to check for a, side, and the perpendicular
|
||||
// direction. But in this
|
||||
// block, we've already checked for side (due to face culling) and a (see
|
||||
// above).
|
||||
Direction perpendicular = Platform.rotateAround(a, side);
|
||||
for (Direction cornerCandidate : EnumSet.of(perpendicular, perpendicular.getOpposite())) {
|
||||
if (!connections.contains(cornerCandidate)) {
|
||||
// There's a cap in this direction
|
||||
switch (cornerCandidate) {
|
||||
case DOWN:
|
||||
y1 = 3;
|
||||
break;
|
||||
case UP:
|
||||
y2 = 13;
|
||||
break;
|
||||
case NORTH:
|
||||
z1 = 3;
|
||||
break;
|
||||
case SOUTH:
|
||||
z2 = 13;
|
||||
break;
|
||||
case WEST:
|
||||
x1 = 3;
|
||||
break;
|
||||
case EAST:
|
||||
x2 = 13;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 3x3x3 corner cap to the cube builder if there are no adjacent crafting
|
||||
* cubes on that corner.
|
||||
*/
|
||||
private void addCornerCap(CubeBuilder builder, EnumSet<Direction> connections, Direction side, Direction down,
|
||||
Direction west, Direction north) {
|
||||
if (connections.contains(down) || connections.contains(west) || connections.contains(north)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only add faces for sides that can actually be seen (the outside of the cube)
|
||||
if (side != down && side != west && side != north) {
|
||||
return;
|
||||
}
|
||||
|
||||
float x1 = (west == Direction.WEST ? 0 : 13);
|
||||
float y1 = (down == Direction.DOWN ? 0 : 13);
|
||||
float z1 = (north == Direction.NORTH ? 0 : 13);
|
||||
float x2 = (west == Direction.WEST ? 3 : 16);
|
||||
float y2 = (down == Direction.DOWN ? 3 : 16);
|
||||
float z2 = (north == Direction.NORTH ? 3 : 16);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
// Retrieve the cube connection state from the block state
|
||||
// If none is present, just assume there are no adjacent crafting cube blocks
|
||||
private static EnumSet<Direction> getConnections(IModelData modelData) {
|
||||
if (!(modelData instanceof CraftingCubeModelData)) {
|
||||
return EnumSet.noneOf(Direction.class);
|
||||
}
|
||||
|
||||
return ((CraftingCubeModelData) modelData).getConnections();
|
||||
}
|
||||
|
||||
protected abstract void addInnerCube(Direction facing, BlockState state, IModelData modelData, CubeBuilder builder,
|
||||
float x1, float y1, float z1, float x2, float y2, float z2);
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.ringCorner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.block.crafting.AbstractCraftingUnitBlock;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* The built-in model for the connected texture crafting cube.
|
||||
*/
|
||||
class CraftingCubeModel implements IModelGeometry<CraftingCubeModel> {
|
||||
|
||||
private final static SpriteIdentifier RING_CORNER = texture("ring_corner");
|
||||
private final static SpriteIdentifier RING_SIDE_HOR = texture("ring_side_hor");
|
||||
private final static SpriteIdentifier RING_SIDE_VER = texture("ring_side_ver");
|
||||
private final static SpriteIdentifier UNIT_BASE = texture("unit_base");
|
||||
private final static SpriteIdentifier LIGHT_BASE = texture("light_base");
|
||||
private final static SpriteIdentifier ACCELERATOR_LIGHT = texture("accelerator_light");
|
||||
private final static SpriteIdentifier STORAGE_1K_LIGHT = texture("1k_storage_light");
|
||||
private final static SpriteIdentifier STORAGE_4K_LIGHT = texture("4k_storage_light");
|
||||
private final static SpriteIdentifier STORAGE_16K_LIGHT = texture("16k_storage_light");
|
||||
private final static SpriteIdentifier STORAGE_64K_LIGHT = texture("64k_storage_light");
|
||||
private final static SpriteIdentifier MONITOR_BASE = texture("monitor_base");
|
||||
private final static SpriteIdentifier MONITOR_LIGHT_DARK = texture("monitor_light_dark");
|
||||
private final static SpriteIdentifier MONITOR_LIGHT_MEDIUM = texture("monitor_light_medium");
|
||||
private final static SpriteIdentifier MONITOR_LIGHT_BRIGHT = texture("monitor_light_bright");
|
||||
|
||||
private final AbstractCraftingUnitBlock.CraftingUnitType type;
|
||||
|
||||
CraftingCubeModel(AbstractCraftingUnitBlock.CraftingUnitType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return ImmutableList.of(RING_CORNER, RING_SIDE_HOR, RING_SIDE_VER, UNIT_BASE, LIGHT_BASE, ACCELERATOR_LIGHT,
|
||||
STORAGE_1K_LIGHT, STORAGE_4K_LIGHT, STORAGE_16K_LIGHT, STORAGE_64K_LIGHT, MONITOR_BASE,
|
||||
MONITOR_LIGHT_DARK, MONITOR_LIGHT_MEDIUM, MONITOR_LIGHT_BRIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
// Retrieve our textures and pass them on to the baked model
|
||||
Sprite ringCorner = spriteGetter.apply(RING_CORNER);
|
||||
Sprite ringSideHor = spriteGetter.apply(RING_SIDE_HOR);
|
||||
Sprite ringSideVer = spriteGetter.apply(RING_SIDE_VER);
|
||||
|
||||
switch (this.type) {
|
||||
case UNIT:
|
||||
return new UnitBakedModel(ringCorner, ringSideHor, ringSideVer, spriteGetter.apply(UNIT_BASE));
|
||||
case ACCELERATOR:
|
||||
case STORAGE_1K:
|
||||
case STORAGE_4K:
|
||||
case STORAGE_16K:
|
||||
case STORAGE_64K:
|
||||
return new LightBakedModel(ringCorner, ringSideHor, ringSideVer, spriteGetter.apply(LIGHT_BASE),
|
||||
getLightTexture(spriteGetter, this.type));
|
||||
case MONITOR:
|
||||
return new MonitorBakedModel(ringCorner, ringSideHor, ringSideVer, spriteGetter.apply(UNIT_BASE),
|
||||
spriteGetter.apply(MONITOR_BASE), spriteGetter.apply(MONITOR_LIGHT_DARK),
|
||||
spriteGetter.apply(MONITOR_LIGHT_MEDIUM), spriteGetter.apply(MONITOR_LIGHT_BRIGHT));
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported crafting unit type: " + this.type);
|
||||
}
|
||||
}
|
||||
|
||||
private static Sprite getLightTexture(Function<SpriteIdentifier, Sprite> textureGetter,
|
||||
AbstractCraftingUnitBlock.CraftingUnitType type) {
|
||||
switch (type) {
|
||||
case ACCELERATOR:
|
||||
return textureGetter.apply(ACCELERATOR_LIGHT);
|
||||
case STORAGE_1K:
|
||||
return textureGetter.apply(STORAGE_1K_LIGHT);
|
||||
case STORAGE_4K:
|
||||
return textureGetter.apply(STORAGE_4K_LIGHT);
|
||||
case STORAGE_16K:
|
||||
return textureGetter.apply(STORAGE_16K_LIGHT);
|
||||
case STORAGE_64K:
|
||||
return textureGetter.apply(STORAGE_64K_LIGHT);
|
||||
default:
|
||||
throw new IllegalArgumentException("Crafting unit type " + type + " does not use a light texture.");
|
||||
}
|
||||
}
|
||||
|
||||
private static SpriteIdentifier texture(String name) {
|
||||
return new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/crafting/" + name));
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
|
||||
import appeng.block.crafting.AbstractCraftingUnitBlock;
|
||||
|
||||
/**
|
||||
* Loader that allows access to the built-in crafting cube model from
|
||||
* block-model JSONs.
|
||||
*/
|
||||
public class CraftingCubeModelLoader implements IModelLoader<CraftingCubeModel> {
|
||||
|
||||
public static final CraftingCubeModelLoader INSTANCE = new CraftingCubeModelLoader();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingCubeModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
|
||||
AbstractCraftingUnitBlock.CraftingUnitType unitType = null;
|
||||
|
||||
JsonElement typeEl = modelContents.get("type");
|
||||
if (typeEl != null) {
|
||||
String typeName = deserializationContext.deserialize(typeEl, String.class);
|
||||
if (typeName != null) {
|
||||
unitType = AbstractCraftingUnitBlock.CraftingUnitType.valueOf(typeName.toUpperCase());
|
||||
}
|
||||
}
|
||||
if (unitType == null) {
|
||||
throw new JsonParseException("type property is missing");
|
||||
}
|
||||
|
||||
return new CraftingCubeModel(unitType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
|
||||
/**
|
||||
* Rendering customization for the crafting cube.
|
||||
*/
|
||||
public class CraftingCubeRendering extends BlockRenderingCustomizer {
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
// Disable auto-rotation
|
||||
rendering.modelCustomizer((loc, model) -> model);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.render.TesrRenderHelper;
|
||||
import appeng.tile.crafting.CraftingMonitorBlockEntity;
|
||||
|
||||
/**
|
||||
* Renders the item currently being crafted
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class CraftingMonitorTESR extends BlockEntityRenderer<CraftingMonitorBlockEntity> {
|
||||
|
||||
public CraftingMonitorTESR(BlockEntityRenderDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(CraftingMonitorBlockEntity te, float partialTicks, MatrixStack matrixStack,
|
||||
VertexConsumerProvider buffers, int combinedLight, int combinedOverlay) {
|
||||
|
||||
Direction facing = te.getForward();
|
||||
|
||||
IAEItemStack jobProgress = te.getJobProgress();
|
||||
|
||||
if (jobProgress != null) {
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0.5, 0.5, 0.5); // Move to the center of the block
|
||||
|
||||
TesrRenderHelper.rotateToFace(matrixStack, facing, (byte) 0);
|
||||
matrixStack.translate(0, 0.08, 0.5);
|
||||
TesrRenderHelper.renderItem2dWithAmount(matrixStack, buffers, jobProgress, 0.3f, -0.18f, 15728880,
|
||||
combinedOverlay);
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package appeng.client.render.crafting;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.PerspectiveMapWrapper;
|
||||
|
||||
import appeng.client.render.DelegateBakedModel;
|
||||
import appeng.items.misc.EncodedPatternItem;
|
||||
|
||||
/**
|
||||
* This model is used to substitute the crafting result's item model for our
|
||||
* encoded pattern model if these two conditions are met: - The player is
|
||||
* holding shift - The itemstack is being rendered in the UI (not on the ground,
|
||||
* etc.)
|
||||
*
|
||||
* We do this by abusing a custom {@link ModelOverrideList} since it will be
|
||||
* called each frame with the itemstack that is about to be rendered. We return
|
||||
* a custom IBakedModel ({@link ShiftHoldingModelWrapper} if the player is
|
||||
* holding down shift from the override list. This custom baked model implements
|
||||
* {@link #doesHandlePerspectives()} and returns the crafting result model if
|
||||
* the model for {@link ModelTransformation.Mode#GUI} is requested.
|
||||
*/
|
||||
public class EncodedPatternBakedModel extends DelegateBakedModel {
|
||||
|
||||
private final CustomOverrideList overrides;
|
||||
|
||||
EncodedPatternBakedModel(BakedModel baseModel) {
|
||||
super(baseModel);
|
||||
this.overrides = new CustomOverrideList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return this.overrides;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the ItemOverrideList handling comes before handling the perspective
|
||||
* awareness (which is the first place where we know how we are being rendered)
|
||||
* we need to remember the model of the crafting output, and make the decision
|
||||
* on which to render later on. Sadly, Forge is pretty inconsistent when it will
|
||||
* call the handlePerspective method, so some methods are called even on this
|
||||
* interim-model. Usually those methods only matter for rendering on the ground
|
||||
* and other cases, where we wouldn't render the crafting output model anyway,
|
||||
* so in those cases we delegate to the model of the encoded pattern.
|
||||
*/
|
||||
private static class ShiftHoldingModelWrapper extends DelegateBakedModel {
|
||||
|
||||
private final BakedModel outputModel;
|
||||
|
||||
private ShiftHoldingModelWrapper(BakedModel patternModel, BakedModel outputModel) {
|
||||
super(patternModel);
|
||||
this.outputModel = outputModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesHandlePerspectives() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(ModelTransformation.Mode cameraTransformType, MatrixStack mat) {
|
||||
// No need to re-check for shift being held since this model is only handed out
|
||||
// in that case
|
||||
if (cameraTransformType == ModelTransformation.Mode.GUI) {
|
||||
ImmutableMap<ModelTransformation.Mode, AffineTransformation> transforms = PerspectiveMapWrapper
|
||||
.getTransforms(outputModel.getTransformation());
|
||||
return PerspectiveMapWrapper.handlePerspective(this.outputModel, transforms, cameraTransformType, mat);
|
||||
} else {
|
||||
return getBaseModel().handlePerspective(cameraTransformType, mat);
|
||||
}
|
||||
}
|
||||
|
||||
// This determines diffuse lighting in the UI, and since we want to render
|
||||
// the outputModel in the UI, we need to use it's setting here
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return outputModel.isSideLit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesHandlePerspectives() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(ModelTransformation.Mode cameraTransformType, MatrixStack mat) {
|
||||
return getBaseModel().handlePerspective(cameraTransformType, mat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Item Override Lists are the only point during item rendering where we can
|
||||
* access the item stack that is being rendered. So this is the point where we
|
||||
* actually check if shift is being held, and if so, determine the crafting
|
||||
* output model.
|
||||
*/
|
||||
private class CustomOverrideList extends ModelOverrideList {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BakedModel getModelWithOverrides(BakedModel originalModel, ItemStack stack, @Nullable World world,
|
||||
@Nullable LivingEntity entity) {
|
||||
boolean shiftHeld = Screen.hasShiftDown();
|
||||
if (shiftHeld && world != null) {
|
||||
EncodedPatternItem iep = (EncodedPatternItem) stack.getItem();
|
||||
ItemStack output = iep.getOutput(world, stack);
|
||||
if (!output.isEmpty()) {
|
||||
BakedModel realModel = MinecraftClient.getInstance().getItemRenderer().getItemModelMesher()
|
||||
.getItemModel(output);
|
||||
// Give the item model a chance to handle the overrides as well
|
||||
realModel = realModel.getOverrides().getModelWithOverrides(realModel, output, world, entity);
|
||||
return new ShiftHoldingModelWrapper(getBaseModel(), realModel);
|
||||
}
|
||||
}
|
||||
|
||||
return getBaseModel().getOverrides().getModelWithOverrides(originalModel, stack, world, entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package appeng.client.render.crafting;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
/**
|
||||
* This model is used to provide the {@link EncodedPatternBakedModel}.
|
||||
*/
|
||||
public class EncodedPatternModel implements IModelGeometry<EncodedPatternModel> {
|
||||
|
||||
private final Identifier baseModel;
|
||||
|
||||
public EncodedPatternModel(Identifier baseModel) {
|
||||
this.baseModel = baseModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return modelGetter.apply(baseModel).getTextures(modelGetter, missingTextureErrors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
BakedModel baseModel = bakery.getBakedModel(this.baseModel, modelTransform, spriteGetter);
|
||||
return new EncodedPatternBakedModel(baseModel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package appeng.client.render.crafting;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
|
||||
/**
|
||||
* Provides our custom {@link EncodedPatternBakedModel encoded pattern item
|
||||
* model}.
|
||||
*/
|
||||
public class EncodedPatternModelLoader implements IModelLoader<EncodedPatternModel> {
|
||||
|
||||
public static final EncodedPatternModelLoader INSTANCE = new EncodedPatternModelLoader();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncodedPatternModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
|
||||
modelContents.remove("loader"); // Avoid recursion
|
||||
Identifier baseModel = new Identifier(JsonHelper.getString(modelContents, "baseModel"));
|
||||
return new EncodedPatternModel(baseModel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
|
||||
import appeng.block.crafting.AbstractCraftingUnitBlock;
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
|
||||
/**
|
||||
* Crafting cube baked model that adds a full-bright light texture on top of a
|
||||
* normal base texture onto the inner cube. The light texture is only drawn
|
||||
* fullbright if the multiblock is currently powered.
|
||||
*/
|
||||
class LightBakedModel extends CraftingCubeBakedModel {
|
||||
|
||||
private final Sprite baseTexture;
|
||||
|
||||
private final Sprite lightTexture;
|
||||
|
||||
LightBakedModel(Sprite ringCorner, Sprite ringHor, Sprite ringVer,
|
||||
Sprite baseTexture, Sprite lightTexture) {
|
||||
super(ringCorner, ringHor, ringVer);
|
||||
this.baseTexture = baseTexture;
|
||||
this.lightTexture = lightTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addInnerCube(Direction facing, BlockState state, IModelData modelData, CubeBuilder builder, float x1,
|
||||
float y1, float z1, float x2, float y2, float z2) {
|
||||
builder.setTexture(this.baseTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
|
||||
boolean powered = state.get(AbstractCraftingUnitBlock.POWERED);
|
||||
builder.setRenderFullBright(powered);
|
||||
builder.setTexture(this.lightTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.block.crafting.CraftingMonitorBlock;
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.client.render.model.AEModelData;
|
||||
import appeng.tile.crafting.CraftingMonitorModelData;
|
||||
|
||||
/**
|
||||
* The baked model for the crafting monitor. Please note that this model doesn't
|
||||
* handle the item being displayed. That is handled by a TESR. Instead, this
|
||||
* model adds 3 layered light textures using the [dark|medium|bright] color
|
||||
* variants of the attached bus color. The textures are full-bright if the cube
|
||||
* is powered.
|
||||
*/
|
||||
public class MonitorBakedModel extends CraftingCubeBakedModel {
|
||||
|
||||
private final Sprite chassisTexture;
|
||||
|
||||
private final Sprite baseTexture;
|
||||
|
||||
private final Sprite lightDarkTexture;
|
||||
|
||||
private final Sprite lightMediumTexture;
|
||||
|
||||
private final Sprite lightBrightTexture;
|
||||
|
||||
MonitorBakedModel(Sprite ringCorner, Sprite ringHor, Sprite ringVer,
|
||||
Sprite chassisTexture, Sprite baseTexture, Sprite lightDarkTexture,
|
||||
Sprite lightMediumTexture, Sprite lightBrightTexture) {
|
||||
super(ringCorner, ringHor, ringVer);
|
||||
this.chassisTexture = chassisTexture;
|
||||
this.baseTexture = baseTexture;
|
||||
this.lightDarkTexture = lightDarkTexture;
|
||||
this.lightMediumTexture = lightMediumTexture;
|
||||
this.lightBrightTexture = lightBrightTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addInnerCube(Direction side, BlockState state, IModelData modelData, CubeBuilder builder, float x1,
|
||||
float y1, float z1, float x2, float y2, float z2) {
|
||||
Direction forward = getForward(modelData);
|
||||
|
||||
// For sides other than the front, use the chassis texture
|
||||
if (side != forward) {
|
||||
builder.setTexture(this.chassisTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
return;
|
||||
}
|
||||
|
||||
builder.setTexture(this.baseTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
|
||||
// Now add the three layered light textures
|
||||
AEColor color = getColor(modelData);
|
||||
boolean powered = state.get(CraftingMonitorBlock.POWERED);
|
||||
|
||||
builder.setRenderFullBright(powered);
|
||||
|
||||
builder.setColorRGB(color.whiteVariant);
|
||||
builder.setTexture(this.lightBrightTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
|
||||
builder.setColorRGB(color.mediumVariant);
|
||||
builder.setTexture(this.lightMediumTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
|
||||
builder.setColorRGB(color.blackVariant);
|
||||
builder.setTexture(this.lightDarkTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
|
||||
}
|
||||
|
||||
private static AEColor getColor(IModelData modelData) {
|
||||
if (modelData instanceof CraftingMonitorModelData) {
|
||||
return ((CraftingMonitorModelData) modelData).getColor();
|
||||
}
|
||||
return AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
private static Direction getForward(IModelData modelData) {
|
||||
if (modelData instanceof AEModelData) {
|
||||
return ((AEModelData) modelData).getForward();
|
||||
}
|
||||
return Direction.NORTH;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
|
||||
/**
|
||||
* A simple crafting unit model that uses an un-lit texture for the inner block.
|
||||
*/
|
||||
class UnitBakedModel extends CraftingCubeBakedModel {
|
||||
|
||||
private final Sprite unitTexture;
|
||||
|
||||
UnitBakedModel(Sprite ringCorner, Sprite ringHor, Sprite ringVer,
|
||||
Sprite unitTexture) {
|
||||
super(ringCorner, ringHor, ringVer);
|
||||
this.unitTexture = unitTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addInnerCube(Direction facing, BlockState state, IModelData modelData, CubeBuilder builder, float x1,
|
||||
float y1, float z1, float x2, float y2, float z2) {
|
||||
builder.setTexture(this.unitTexture);
|
||||
builder.addCube(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.particle.ParticleFactory;
|
||||
import net.minecraft.client.particle.SpriteProvider;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.particle.RedDustParticle;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
import net.minecraft.particle.DustParticleEffect;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ChargedOreFX extends RedDustParticle {
|
||||
|
||||
private static final DustParticleEffect PARTICLE_DATA = new DustParticleEffect(0.21f, 0.61f, 1.0f, 1.0f);
|
||||
|
||||
private ChargedOreFX(ClientWorld world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed,
|
||||
SpriteProvider spriteSet) {
|
||||
super(world, x, y, z, xSpeed, ySpeed, zSpeed, PARTICLE_DATA, spriteSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorMultiplier(final float par1) {
|
||||
int j1 = super.getColorMultiplier(par1);
|
||||
j1 = Math.max(j1 >> 20, j1 >> 4);
|
||||
j1 += 3;
|
||||
if (j1 > 15) {
|
||||
j1 = 15;
|
||||
}
|
||||
return j1 << 20 | j1 << 4;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<DefaultParticleType> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider p_i50477_1_) {
|
||||
this.spriteSet = p_i50477_1_;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z,
|
||||
double xSpeed, double ySpeed, double zSpeed) {
|
||||
return new ChargedOreFX(world, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.client.particle.*;
|
||||
import net.minecraft.client.particle.ParticleTextureSheet;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class CraftingFx extends SpriteBillboardParticle {
|
||||
|
||||
// Offset relative to center of block, is the starting point of the particle
|
||||
// movement
|
||||
private final float offsetX;
|
||||
private final float offsetY;
|
||||
private final float offsetZ;
|
||||
|
||||
public CraftingFx(ClientWorld world, final double x, final double y, final double z,
|
||||
final SpriteProvider sprite) {
|
||||
super(world, x, y, z);
|
||||
|
||||
// Pick a random normal, offset it by 0.35 and use that as the particle origin
|
||||
Vector3f off = new Vector3f(random.nextFloat() - 0.5f, random.nextFloat() - 0.5f, random.nextFloat() - 0.5f);
|
||||
off.normalize();
|
||||
off.scale(0.35f);
|
||||
offsetX = off.getX();
|
||||
offsetY = off.getY();
|
||||
offsetZ = off.getZ();
|
||||
|
||||
this.gravityStrength = 0;
|
||||
this.colorBlue = 1;
|
||||
this.colorGreen = 0.9f;
|
||||
this.colorRed = 1;
|
||||
this.setSprite(sprite);
|
||||
this.maxAge /= 1.2;
|
||||
this.collidesWithWorld = false; // we're INSIDE the block anyway
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void buildGeometry(VertexConsumer buffer, Camera camera, float partialTicks) {
|
||||
|
||||
float f = (this.age + partialTicks) / this.maxAge;
|
||||
|
||||
float offX = (float) x + MathHelper.lerp(f, offsetX, 0);
|
||||
float offY = (float) y + MathHelper.lerp(f, offsetY, 0);
|
||||
float offZ = (float) z + MathHelper.lerp(f, offsetZ, 0);
|
||||
float alpha = MathHelper.lerp(easeOutCirc(f), 1.3f, 0.1f);
|
||||
float scale = MathHelper.lerp(easeOutCirc(f), 0.13f, 0.0f);
|
||||
|
||||
// I believe this particle is same as breaking particle, but should not exit the
|
||||
// original block it was
|
||||
// spawned in (which is encased in glass)
|
||||
Vec3d vec3d = camera.getPos();
|
||||
offX -= vec3d.x;
|
||||
offY -= vec3d.y;
|
||||
offZ -= vec3d.z;
|
||||
|
||||
Vector3f[] avector3f = new Vector3f[] { new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F),
|
||||
new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F) };
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
Vector3f vector3f = avector3f[i];
|
||||
vector3f.rotate(camera.getRotation());
|
||||
vector3f.scale(scale);
|
||||
vector3f.add(offX, offY, offZ);
|
||||
}
|
||||
|
||||
float minU = this.getMinU();
|
||||
float maxU = this.getMaxU();
|
||||
float minV = this.getMinV();
|
||||
float maxV = this.getMaxV();
|
||||
int j = 15728880; // full brightness
|
||||
buffer.vertex(avector3f[0].getX(), avector3f[0].getY(), avector3f[0].getZ()).texture(maxU, maxV)
|
||||
.color(this.colorRed, this.colorGreen, this.colorBlue, alpha).light(j).next();
|
||||
buffer.vertex(avector3f[1].getX(), avector3f[1].getY(), avector3f[1].getZ()).texture(maxU, minV)
|
||||
.color(this.colorRed, this.colorGreen, this.colorBlue, alpha).light(j).next();
|
||||
buffer.vertex(avector3f[2].getX(), avector3f[2].getY(), avector3f[2].getZ()).texture(minU, minV)
|
||||
.color(this.colorRed, this.colorGreen, this.colorBlue, alpha).light(j).next();
|
||||
buffer.vertex(avector3f[3].getX(), avector3f[3].getY(), avector3f[3].getZ()).texture(minU, maxV)
|
||||
.color(this.colorRed, this.colorGreen, this.colorBlue, alpha).light(j).next();
|
||||
}
|
||||
|
||||
// https://easings.net/#easeOutCirc
|
||||
private static float easeOutCirc(float x) {
|
||||
return (float) Math.sqrt(1 - Math.pow(x - 1, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.age++ >= this.maxAge) {
|
||||
this.markDead();
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<DefaultParticleType> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider p_i50477_1_) {
|
||||
this.spriteSet = p_i50477_1_;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z, double xSpeed,
|
||||
double ySpeed, double zSpeed) {
|
||||
return new CraftingFx(world, x, y, z, spriteSet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.particle.*;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EnergyFx extends SpriteBillboardParticle {
|
||||
|
||||
private final int startBlkX;
|
||||
private final int startBlkY;
|
||||
private final int startBlkZ;
|
||||
|
||||
public EnergyFx(ClientWorld world, final double par2, final double par4, final double par6,
|
||||
final SpriteProvider sprite) {
|
||||
super(world, par2, par4, par6);
|
||||
this.gravityStrength = 0;
|
||||
this.colorBlue = 1;
|
||||
this.colorGreen = 1;
|
||||
this.colorRed = 1;
|
||||
this.colorAlpha = 1.4f;
|
||||
this.scale = 3.5f;
|
||||
this.setSprite(sprite);
|
||||
|
||||
this.startBlkX = MathHelper.floor(this.x);
|
||||
this.startBlkY = MathHelper.floor(this.y);
|
||||
this.startBlkZ = MathHelper.floor(this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSize(float tickDelta) {
|
||||
return 0.1f * this.scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildGeometry(VertexConsumer buffer, Camera camera, float partialTicks) {
|
||||
float x = (float) (this.prevPosX + (this.x - this.prevPosX) * partialTicks);
|
||||
float y = (float) (this.prevPosY + (this.y - this.prevPosY) * partialTicks);
|
||||
float z = (float) (this.prevPosZ + (this.z - this.prevPosZ) * partialTicks);
|
||||
|
||||
final int blkX = MathHelper.floor(x);
|
||||
final int blkY = MathHelper.floor(y);
|
||||
final int blkZ = MathHelper.floor(z);
|
||||
|
||||
if (blkX == this.startBlkX && blkY == this.startBlkY && blkZ == this.startBlkZ) {
|
||||
super.buildGeometry(buffer, camera, partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.onGround = false;
|
||||
|
||||
this.scale *= 0.89f;
|
||||
this.colorAlpha *= 0.89f;
|
||||
}
|
||||
|
||||
public void setVelocityX(float velocityX) {
|
||||
this.velocityX = velocityX;
|
||||
}
|
||||
|
||||
public void setVelocityY(float velocityY) {
|
||||
this.velocityY = velocityY;
|
||||
}
|
||||
|
||||
public void setVelocityZ(float velocityZ) {
|
||||
this.velocityZ = velocityZ;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<EnergyParticleData> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(EnergyParticleData effect, ClientWorld world, double x, double y, double z,
|
||||
double xSpeed, double ySpeed, double zSpeed) {
|
||||
EnergyFx result = new EnergyFx(world, x, y, z, spriteSet);
|
||||
result.setVelocityX((float) xSpeed);
|
||||
result.setVelocityY((float) ySpeed);
|
||||
result.setVelocityZ((float) zSpeed);
|
||||
if (effect.forItem) {
|
||||
result.x += -0.2 * effect.direction.xOffset;
|
||||
result.y += -0.2 * effect.direction.yOffset;
|
||||
result.z += -0.2 * effect.direction.zOffset;
|
||||
result.scale *= 0.8f;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.particle.ParticleType;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
public class EnergyParticleData implements ParticleEffect {
|
||||
|
||||
public static final EnergyParticleData FOR_BLOCK = new EnergyParticleData(false, AEPartLocation.INTERNAL);
|
||||
|
||||
public final boolean forItem;
|
||||
|
||||
public final AEPartLocation direction;
|
||||
|
||||
public EnergyParticleData(boolean forItem, AEPartLocation direction) {
|
||||
this.forItem = forItem;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public static final Factory<EnergyParticleData> DESERIALIZER = new Factory<EnergyParticleData>() {
|
||||
@Override
|
||||
public EnergyParticleData read(ParticleType<EnergyParticleData> particleTypeIn, StringReader reader)
|
||||
throws CommandSyntaxException {
|
||||
reader.expect(' ');
|
||||
boolean forItem = reader.readBoolean();
|
||||
reader.expect(' ');
|
||||
AEPartLocation direction = AEPartLocation.valueOf(reader.readString().toUpperCase());
|
||||
return new EnergyParticleData(forItem, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyParticleData read(ParticleType<EnergyParticleData> particleTypeIn, PacketByteBuf buffer) {
|
||||
boolean forItem = buffer.readBoolean();
|
||||
AEPartLocation direction = AEPartLocation.values()[buffer.readByte()];
|
||||
return new EnergyParticleData(forItem, direction);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public ParticleType<?> getType() {
|
||||
return ParticleTypes.ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf buffer) {
|
||||
buffer.writeBoolean(forItem);
|
||||
buffer.writeByte((byte) direction.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return String.format(Locale.ROOT, "%s %s", forItem ? "true" : "false", direction.name().toLowerCase());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.particle.SpriteProvider;
|
||||
import net.minecraft.client.particle.ParticleFactory;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.particle.SpriteBillboardParticle;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class LightningArcFX extends LightningFX {
|
||||
|
||||
private static final Random RANDOM_GENERATOR = new Random();
|
||||
|
||||
private final double rx;
|
||||
private final double ry;
|
||||
private final double rz;
|
||||
|
||||
public LightningArcFX(ClientWorld world, final double x, final double y, final double z, final double ex,
|
||||
final double ey, final double ez, final double r, final double g, final double b) {
|
||||
super(world, x, y, z, r, g, b, 6);
|
||||
|
||||
this.rx = ex - x;
|
||||
this.ry = ey - y;
|
||||
this.rz = ez - z;
|
||||
|
||||
this.regen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void regen() {
|
||||
final double i = 1.0 / (this.getSteps() - 1);
|
||||
final double lastDirectionX = this.rx * i;
|
||||
final double lastDirectionY = this.ry * i;
|
||||
final double lastDirectionZ = this.rz * i;
|
||||
|
||||
final double len = Math.sqrt(
|
||||
lastDirectionX * lastDirectionX + lastDirectionY * lastDirectionY + lastDirectionZ * lastDirectionZ);
|
||||
for (int s = 0; s < this.getSteps(); s++) {
|
||||
final double[][] localSteps = this.getPrecomputedSteps();
|
||||
|
||||
localSteps[s][0] = (lastDirectionX + (RANDOM_GENERATOR.nextDouble() - 0.5) * len * 1.2) / 2.0;
|
||||
localSteps[s][1] = (lastDirectionY + (RANDOM_GENERATOR.nextDouble() - 0.5) * len * 1.2) / 2.0;
|
||||
localSteps[s][2] = (lastDirectionZ + (RANDOM_GENERATOR.nextDouble() - 0.5) * len * 1.2) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<LightningArcParticleData> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(LightningArcParticleData effect, ClientWorld world, double x, double y, double z,
|
||||
double xSpeed, double ySpeed, double zSpeed) {
|
||||
SpriteBillboardParticle lightningFX = new LightningArcFX(world, x, y, z, effect.target.x, effect.target.y,
|
||||
effect.target.z, 0, 0, 0);
|
||||
lightningFX.setSprite(this.spriteSet);
|
||||
return lightningFX;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package appeng.client.render.effects;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.particle.ParticleType;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* Contains the target point of the lightning arc (the source point is infered
|
||||
* from the particle starting position).
|
||||
*/
|
||||
public class LightningArcParticleData implements ParticleEffect {
|
||||
|
||||
public final Vec3d target;
|
||||
|
||||
public LightningArcParticleData(Vec3d target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public static final Factory<LightningArcParticleData> DESERIALIZER = new Factory<LightningArcParticleData>() {
|
||||
@Override
|
||||
public LightningArcParticleData read(ParticleType<LightningArcParticleData> particleTypeIn,
|
||||
StringReader reader) throws CommandSyntaxException {
|
||||
reader.expect(' ');
|
||||
float x = reader.readFloat();
|
||||
reader.expect(' ');
|
||||
float y = reader.readFloat();
|
||||
reader.expect(' ');
|
||||
float z = reader.readFloat();
|
||||
return new LightningArcParticleData(new Vec3d(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LightningArcParticleData read(ParticleType<LightningArcParticleData> particleTypeIn,
|
||||
PacketByteBuf buffer) {
|
||||
float x = buffer.readFloat();
|
||||
float y = buffer.readFloat();
|
||||
float z = buffer.readFloat();
|
||||
return new LightningArcParticleData(new Vec3d(x, y, z));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public ParticleType<?> getType() {
|
||||
return ParticleTypes.LIGHTNING_ARC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf buffer) {
|
||||
buffer.writeFloat((float) target.x);
|
||||
buffer.writeFloat((float) target.y);
|
||||
buffer.writeFloat((float) target.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return String.format(Locale.ROOT, "%.2f %.2f %.2f", target.x, target.y, target.z);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.particle.*;
|
||||
import net.minecraft.client.particle.ParticleTextureSheet;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class LightningFX extends SpriteBillboardParticle {
|
||||
|
||||
private static final Random RANDOM_GENERATOR = new Random();
|
||||
private static final int STEPS = 5;
|
||||
private static final int BRIGHTNESS = 13 << 4;
|
||||
|
||||
private final double[][] precomputedSteps;
|
||||
private final double[] vertices = new double[3];
|
||||
private final double[] verticesWithUV = new double[3];
|
||||
private boolean hasData = false;
|
||||
|
||||
private LightningFX(ClientWorld world, final double x, final double y, final double z, final double r, final double g,
|
||||
final double b) {
|
||||
this(world, x, y, z, r, g, b, 6);
|
||||
this.regen();
|
||||
}
|
||||
|
||||
protected LightningFX(ClientWorld world, final double x, final double y, final double z, final double r, final double g,
|
||||
final double b, final int maxAge) {
|
||||
super(world, x, y, z, r, g, b);
|
||||
this.precomputedSteps = new double[LightningFX.STEPS][3];
|
||||
this.velocityX = 0;
|
||||
this.velocityY = 0;
|
||||
this.velocityZ = 0;
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
|
||||
protected void regen() {
|
||||
double lastDirectionX = (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9;
|
||||
double lastDirectionY = (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9;
|
||||
double lastDirectionZ = (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9;
|
||||
for (int s = 0; s < LightningFX.STEPS; s++) {
|
||||
this.precomputedSteps[s][0] = lastDirectionX = (lastDirectionX
|
||||
+ (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9) / 2.0;
|
||||
this.precomputedSteps[s][1] = lastDirectionY = (lastDirectionY
|
||||
+ (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9) / 2.0;
|
||||
this.precomputedSteps[s][2] = lastDirectionZ = (lastDirectionZ
|
||||
+ (RANDOM_GENERATOR.nextDouble() - 0.5) * 0.9) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getSteps() {
|
||||
return LightningFX.STEPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
// TODO: FIXME
|
||||
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.prevPosX = this.x;
|
||||
this.prevPosY = this.y;
|
||||
this.prevPosZ = this.z;
|
||||
|
||||
if (this.age++ >= this.maxAge) {
|
||||
this.markDead();
|
||||
}
|
||||
|
||||
this.velocityY -= 0.04D * this.gravityStrength;
|
||||
this.move(this.velocityX, this.velocityY, this.velocityZ);
|
||||
this.velocityX *= 0.9800000190734863D;
|
||||
this.velocityY *= 0.9800000190734863D;
|
||||
this.velocityZ *= 0.9800000190734863D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildGeometry(VertexConsumer buffer, Camera camera, float partialTicks) {
|
||||
Vec3d vec3d = camera.getPos();
|
||||
float centerX = (float) (MathHelper.lerp(partialTicks, this.prevPosX, this.x) - vec3d.getX());
|
||||
float centerY = (float) (MathHelper.lerp(partialTicks, this.prevPosY, this.y) - vec3d.getY());
|
||||
float centerZ = (float) (MathHelper.lerp(partialTicks, this.prevPosZ, this.z) - vec3d.getZ());
|
||||
|
||||
final float j = 1.0f;
|
||||
float red = this.colorRed * j * 0.9f;
|
||||
float green = this.colorGreen * j * 0.95f;
|
||||
float blue = this.colorBlue * j;
|
||||
final float alpha = this.colorAlpha;
|
||||
|
||||
if (this.age == 3) {
|
||||
this.regen();
|
||||
}
|
||||
|
||||
float u = this.getMinU() + (this.getMaxU() - this.getMinU()) / 2;
|
||||
float v = this.getMinV() + (this.getMaxV() - this.getMinV()) / 2;
|
||||
|
||||
double scale = 0.02;// 0.02F * this.scale;
|
||||
|
||||
final double[] a = new double[3];
|
||||
final double[] b = new double[3];
|
||||
|
||||
double ox = 0;
|
||||
double oy = 0;
|
||||
double oz = 0;
|
||||
|
||||
final PlayerEntity p = MinecraftClient.getInstance().player;
|
||||
|
||||
// FIXME: Billboard rotation is not applied to the particle yet,
|
||||
// FIXME The old version apparently did this by hand using rX,rZ -> replicate
|
||||
// using the quaternion
|
||||
|
||||
for (int layer = 0; layer < 2; layer++) {
|
||||
if (layer == 0) {
|
||||
scale = 0.04;
|
||||
// FIXME offX *= 0.001;
|
||||
// FIXME offY *= 0.001;
|
||||
// FIXME offZ *= 0.001;
|
||||
red = this.colorRed * j * 0.4f;
|
||||
green = this.colorGreen * j * 0.25f;
|
||||
blue = this.colorBlue * j * 0.45f;
|
||||
} else {
|
||||
// FIXME offX = 0;
|
||||
// FIXME offY = 0;
|
||||
// FIXME offZ = 0;
|
||||
scale = 0.02;
|
||||
red = this.colorRed * j * 0.9f;
|
||||
green = this.colorGreen * j * 0.65f;
|
||||
blue = this.colorBlue * j * 0.85f;
|
||||
}
|
||||
|
||||
for (int cycle = 0; cycle < 3; cycle++) {
|
||||
this.clear();
|
||||
|
||||
// FIXME removed interpPos here, check if this is correct
|
||||
double x = centerX; // FIXME - offX;
|
||||
double y = centerY; // FIXME - offY;
|
||||
double z = centerZ; // FIXME - offZ;
|
||||
|
||||
for (int s = 0; s < LightningFX.STEPS; s++) {
|
||||
final double xN = x + this.precomputedSteps[s][0];
|
||||
final double yN = y + this.precomputedSteps[s][1];
|
||||
final double zN = z + this.precomputedSteps[s][2];
|
||||
|
||||
final double xD = xN - x;
|
||||
final double yD = yN - y;
|
||||
final double zD = zN - z;
|
||||
|
||||
if (cycle == 0) {
|
||||
ox = (yD * 0) - (1 * zD);
|
||||
oy = (zD * 0) - (0 * xD);
|
||||
oz = (xD * 1) - (0 * yD);
|
||||
}
|
||||
if (cycle == 1) {
|
||||
ox = (yD * 1) - (0 * zD);
|
||||
oy = (zD * 0) - (1 * xD);
|
||||
oz = (xD * 0) - (0 * yD);
|
||||
}
|
||||
if (cycle == 2) {
|
||||
ox = (yD * 0) - (0 * zD);
|
||||
oy = (zD * 1) - (0 * xD);
|
||||
oz = (xD * 0) - (1 * yD);
|
||||
}
|
||||
|
||||
final double ss = Math.sqrt(ox * ox + oy * oy + oz * oz)
|
||||
/ ((((double) LightningFX.STEPS - (double) s) / LightningFX.STEPS) * scale);
|
||||
ox /= ss;
|
||||
oy /= ss;
|
||||
oz /= ss;
|
||||
|
||||
a[0] = x + ox;
|
||||
a[1] = y + oy;
|
||||
a[2] = z + oz;
|
||||
|
||||
b[0] = x;
|
||||
b[1] = y;
|
||||
b[2] = z;
|
||||
|
||||
this.draw(red, green, blue, buffer, a, b, u, v);
|
||||
|
||||
x = xN;
|
||||
y = yN;
|
||||
z = zN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
this.hasData = false;
|
||||
}
|
||||
|
||||
private void draw(float red, float green, float blue, final VertexConsumer tess, final double[] a, final double[] b,
|
||||
final float u, final float v) {
|
||||
if (this.hasData) {
|
||||
tess.vertex(a[0], a[1], a[2]).texture(u, v).color(red, green, blue, this.colorAlpha)
|
||||
.light(BRIGHTNESS, BRIGHTNESS).next();
|
||||
tess.vertex(this.vertices[0], this.vertices[1], this.vertices[2]).texture(u, v)
|
||||
.color(red, green, blue, this.colorAlpha).light(BRIGHTNESS, BRIGHTNESS).next();
|
||||
tess.vertex(this.verticesWithUV[0], this.verticesWithUV[1], this.verticesWithUV[2]).texture(u, v)
|
||||
.color(red, green, blue, this.colorAlpha).light(BRIGHTNESS, BRIGHTNESS).next();
|
||||
tess.vertex(b[0], b[1], b[2]).texture(u, v).color(red, green, blue, this.colorAlpha)
|
||||
.light(BRIGHTNESS, BRIGHTNESS).next();
|
||||
}
|
||||
this.hasData = true;
|
||||
for (int x = 0; x < 3; x++) {
|
||||
this.vertices[x] = a[x];
|
||||
this.verticesWithUV[x] = b[x];
|
||||
}
|
||||
}
|
||||
|
||||
protected double[][] getPrecomputedSteps() {
|
||||
return this.precomputedSteps;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<DefaultParticleType> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(DefaultParticleType type, ClientWorld world, double x, double y, double z,
|
||||
double xSpeed, double ySpeed, double zSpeed) {
|
||||
LightningFX lightningFX = new LightningFX(world, x, y, z, xSpeed, ySpeed, zSpeed);
|
||||
lightningFX.setSprite(this.spriteSet);
|
||||
return lightningFX;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.client.particle.*;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
public class MatterCannonFX extends SpriteBillboardParticle {
|
||||
|
||||
public MatterCannonFX(ClientWorld world, final double x, final double y, final double z,
|
||||
SpriteProvider sprite) {
|
||||
super(world, x, y, z);
|
||||
this.gravityStrength = 0;
|
||||
this.colorBlue = 1;
|
||||
this.colorGreen = 1;
|
||||
this.colorRed = 1;
|
||||
this.colorAlpha = 1.4f;
|
||||
this.scale = 1.1f;
|
||||
this.velocityX = 0.0f;
|
||||
this.velocityY = 0.0f;
|
||||
this.velocityZ = 0.0f;
|
||||
this.setSprite(sprite);
|
||||
}
|
||||
|
||||
public void fromItem(final AEPartLocation d) {
|
||||
this.scale *= 1.2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.prevPosX = this.x;
|
||||
this.prevPosY = this.y;
|
||||
this.prevPosZ = this.z;
|
||||
|
||||
if (this.age++ >= this.maxAge) {
|
||||
this.markDead();
|
||||
}
|
||||
|
||||
this.velocityY -= 0.04D * this.gravityStrength;
|
||||
this.move(this.velocityX, this.velocityY, this.velocityZ);
|
||||
this.velocityX *= 0.9800000190734863D;
|
||||
this.velocityY *= 0.9800000190734863D;
|
||||
this.velocityZ *= 0.9800000190734863D;
|
||||
|
||||
this.scale *= 1.19f;
|
||||
this.colorAlpha *= 0.59f;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<DefaultParticleType> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z, double xSpeed,
|
||||
double ySpeed, double zSpeed) {
|
||||
return new MatterCannonFX(world, x, y, z, spriteSet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package appeng.client.render.effects;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
|
||||
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.particle.ParticleManager;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
import net.minecraft.particle.ParticleType;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public final class ParticleTypes {
|
||||
|
||||
private ParticleTypes() {
|
||||
}
|
||||
|
||||
public static final DefaultParticleType CHARGED_ORE = FabricParticleTypes.simple(false);
|
||||
public static final DefaultParticleType CRAFTING = FabricParticleTypes.simple(false);
|
||||
public static final ParticleType<EnergyParticleData> ENERGY = FabricParticleTypes.complex(false,
|
||||
EnergyParticleData.DESERIALIZER);
|
||||
public static final ParticleType<LightningArcParticleData> LIGHTNING_ARC = FabricParticleTypes.complex(false,
|
||||
LightningArcParticleData.DESERIALIZER);
|
||||
public static final DefaultParticleType LIGHTNING = FabricParticleTypes.simple(false);
|
||||
public static final DefaultParticleType MATTER_CANNON = FabricParticleTypes.simple(false);
|
||||
public static final DefaultParticleType VIBRANT = FabricParticleTypes.simple(false);
|
||||
|
||||
public static void registerClient() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.effects;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.particle.*;
|
||||
import net.minecraft.client.particle.ParticleFactory;
|
||||
import net.minecraft.client.particle.ParticleTextureSheet;
|
||||
import net.minecraft.client.particle.SpriteProvider;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class VibrantFX extends SpriteBillboardParticle {
|
||||
|
||||
public VibrantFX(ClientWorld world, final double x, final double y, final double z, final double par8,
|
||||
final double par10, final double par12, SpriteProvider sprite) {
|
||||
super(world, x, y, z, par8, par10, par12);
|
||||
final float f = this.random.nextFloat() * 0.1F + 0.8F;
|
||||
this.colorRed = f * 0.7f;
|
||||
this.colorGreen = f * 0.89f;
|
||||
this.colorBlue = f * 0.9f;
|
||||
this.setSprite(sprite);
|
||||
this.setBoundingBoxSpacing(0.04F, 0.04F);
|
||||
this.scale *= this.random.nextFloat() * 0.6F + 1.9F;
|
||||
this.velocityX = 0.0D;
|
||||
this.velocityY = 0.0D;
|
||||
this.velocityZ = 0.0D;
|
||||
this.prevPosX = this.x;
|
||||
this.prevPosY = this.y;
|
||||
this.prevPosZ = this.z;
|
||||
this.maxAge = (int) (20.0D / (Math.random() * 0.8D + 0.1D));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
// FIXME Might be PARTICLE_SHEET_LIT
|
||||
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorMultiplier(final float par1) {
|
||||
// This just means full brightness
|
||||
return 15 << 20 | 15 << 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to update the entity's position/logic.
|
||||
*/
|
||||
@Override
|
||||
public void tick() {
|
||||
this.prevPosX = this.x;
|
||||
this.prevPosY = this.y;
|
||||
this.prevPosZ = this.z;
|
||||
// this.moveEntity(this.velocityX, this.velocityY, this.velocityZ);
|
||||
this.scale *= 0.95;
|
||||
|
||||
if (this.maxAge <= 0 || this.scale < 0.1) {
|
||||
this.markDead();
|
||||
}
|
||||
this.maxAge--;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Factory implements ParticleFactory<DefaultParticleType> {
|
||||
private final SpriteProvider spriteSet;
|
||||
|
||||
public Factory(SpriteProvider spriteSet) {
|
||||
this.spriteSet = spriteSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle createParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z,
|
||||
double xSpeed, double ySpeed, double zSpeed) {
|
||||
return new VibrantFX(world, x, y, z, xSpeed, ySpeed, zSpeed, spriteSet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
|
||||
public abstract class AEInternalModelData implements IModelData {
|
||||
|
||||
@Override
|
||||
public final boolean hasProperty(ModelProperty<?> prop) {
|
||||
throw new IllegalStateException("This model data must be used by internal models only.");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public final <T> T getData(ModelProperty<T> prop) {
|
||||
throw new IllegalStateException("This model data must be used by internal models only.");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public final <T> T setData(ModelProperty<T> prop, T data) {
|
||||
throw new IllegalStateException("This model data must be used by internal models only.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
/**
|
||||
* This implementation of IModelData allows us to know precisely which data is
|
||||
* part of the model data. This is relevant for {@link AutoRotatingBakedModel}
|
||||
* and {@link AutoRotatingCacheKey}.
|
||||
*/
|
||||
public class AEModelData {
|
||||
|
||||
private final Direction up;
|
||||
private final Direction forward;
|
||||
|
||||
public AEModelData(Direction up, Direction forward) {
|
||||
this.up = Preconditions.checkNotNull(up);
|
||||
this.forward = Preconditions.checkNotNull(forward);
|
||||
}
|
||||
|
||||
public Direction getUp() {
|
||||
return up;
|
||||
}
|
||||
|
||||
public Direction getForward() {
|
||||
return forward;
|
||||
}
|
||||
|
||||
public boolean isCacheable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
AEModelData that = (AEModelData) o;
|
||||
return up == that.up && forward == that.forward;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(up, forward);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormatElement;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.Vector4f;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
|
||||
|
||||
import appeng.client.render.FacingToRotation;
|
||||
|
||||
public class AutoRotatingBakedModel implements BakedModel {
|
||||
|
||||
private final BakedModel parent;
|
||||
private final LoadingCache<AutoRotatingCacheKey, List<BakedQuad>> quadCache;
|
||||
|
||||
public AutoRotatingBakedModel(BakedModel parent) {
|
||||
this.parent = parent;
|
||||
// 6 (DUNSWE) * 6 (DUNSWE) * 7 (DUNSWE + null) = 252
|
||||
this.quadCache = CacheBuilder.newBuilder().maximumSize(252)
|
||||
.build(new CacheLoader<AutoRotatingCacheKey, List<BakedQuad>>() {
|
||||
@Override
|
||||
public List<BakedQuad> load(AutoRotatingCacheKey key) {
|
||||
return AutoRotatingBakedModel.this.getRotatedModel(key.getBlockState(), key.getSide(),
|
||||
new Random(0), key.getModelData());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||
VertexRotator rot = new VertexRotator(f2r, quad.getFace());
|
||||
rot.setParent(builder);
|
||||
quad.pipe(rot);
|
||||
if (quad.getFace() != null) {
|
||||
builder.setQuadOrientation(f2r.rotate(quad.getFace()));
|
||||
} else {
|
||||
builder.setQuadOrientation(null);
|
||||
|
||||
}
|
||||
BakedQuad unpackedQuad = builder.build();
|
||||
|
||||
// Make a copy of it to resolve the vertex data and throw away the unpacked
|
||||
// stuff
|
||||
// This also fixes a bug in Forge's UnpackedBakedQuad, which unpacks a
|
||||
// byte-based normal like 0,0,-1
|
||||
// to 0,0,-0.99607843. We replace these normals with the proper 0,0,-1 when
|
||||
// rotation, which
|
||||
// causes a bug in the AO lighter, if an unpacked quad pipes this value back to
|
||||
// it.
|
||||
// Packing it back to the vanilla vertex format will fix this inconsistency
|
||||
// because it converts
|
||||
// the normal back to a byte-based format, which then re-applies Forge's own bug
|
||||
// when piping it
|
||||
// to the AO lighter, thus fixing our problem.
|
||||
BakedQuad packedQuad = new BakedQuad(unpackedQuad.getVertexData(), quad.getColorIndex(),
|
||||
unpackedQuad.getFace(), quad.func_187508_a(), quad.shouldApplyDiffuseLighting());
|
||||
rotated.add(packedQuad);
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.parent.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return this.parent.hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return parent.isSideLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return this.parent.isBuiltin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.parent.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public ModelTransformation getTransformation() {
|
||||
return parent.getTransformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return parent.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
|
||||
@Nonnull IModelData extraData) {
|
||||
|
||||
if (!(extraData instanceof AEModelData)) {
|
||||
return this.parent.getQuads(state, side, rand, extraData);
|
||||
}
|
||||
|
||||
AEModelData aeModelData = (AEModelData) extraData;
|
||||
|
||||
if (aeModelData.isCacheable()) {
|
||||
return quadCache.getUnchecked(new AutoRotatingCacheKey(state, aeModelData, side));
|
||||
} else {
|
||||
return this.getRotatedModel(state, side, rand, aeModelData);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData(@Nonnull BlockRenderView world, @Nonnull BlockPos pos, @Nonnull BlockState state,
|
||||
@Nonnull IModelData tileData) {
|
||||
return this.parent.getModelData(world, pos, state, tileData);
|
||||
}
|
||||
|
||||
public static class VertexRotator extends QuadGatheringTransformer {
|
||||
private final FacingToRotation f2r;
|
||||
private final Direction face;
|
||||
|
||||
public VertexRotator(FacingToRotation f2r, Direction face) {
|
||||
this.f2r = f2r;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(IVertexConsumer parent) {
|
||||
super.setParent(parent);
|
||||
if (Objects.equal(this.getVertexFormat(), parent.getVertexFormat())) {
|
||||
return;
|
||||
}
|
||||
this.setVertexFormat(parent.getVertexFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processQuad() {
|
||||
VertexFormat format = this.parent.getVertexFormat();
|
||||
ImmutableList<VertexFormatElement> elements = format.getElements();
|
||||
|
||||
for (int v = 0; v < 4; v++) {
|
||||
for (int e = 0; e < elements.size(); e++) {
|
||||
VertexFormatElement element = elements.get(e);
|
||||
if (element.getType() == VertexFormatElement.Usage.POSITION) {
|
||||
this.parent.put(e, this.transform(this.quadData[e][v]));
|
||||
} else if (element.getType() == VertexFormatElement.Usage.NORMAL) {
|
||||
this.parent.put(e, this.transformNormal(this.quadData[e][v]));
|
||||
} else {
|
||||
this.parent.put(e, this.quadData[e][v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float[] transform(float[] fs) {
|
||||
switch (fs.length) {
|
||||
case 3:
|
||||
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.f2r.getMat());
|
||||
vec.setX(vec.getX() + 0.5f);
|
||||
vec.setY(vec.getY() + 0.5f);
|
||||
vec.setZ(vec.getZ() + 0.5f);
|
||||
return new float[] { vec.getX(), vec.getY(), vec.getZ() };
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f(fs[0], fs[1], fs[2], fs[3]);
|
||||
vecc.setX(vecc.getX() - 0.5f);
|
||||
vecc.setY(vecc.getY() - 0.5f);
|
||||
vecc.setZ(vecc.getZ() - 0.5f);
|
||||
vecc.transform(this.f2r.getMat());
|
||||
vecc.setX(vecc.getX() + 0.5f);
|
||||
vecc.setY(vecc.getY() + 0.5f);
|
||||
vecc.setZ(vecc.getZ() + 0.5f);
|
||||
return new float[] { vecc.getX(), vecc.getY(), vecc.getZ(), vecc.getW() };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
private float[] transformNormal(float[] fs) {
|
||||
if (this.face == null) {
|
||||
switch (fs.length) {
|
||||
case 3:
|
||||
Vector4f vec = new Vector4f(fs[0], fs[1], fs[2], 0);
|
||||
vec.transform(this.f2r.getMat());
|
||||
return new float[] { vec.getX(), vec.getY(), vec.getZ() };
|
||||
case 4:
|
||||
Vector4f vec4 = new Vector4f(fs[0], fs[1], fs[2], fs[3]);
|
||||
vec4.transform(this.f2r.getMat());
|
||||
return new float[] { vec4.getX(), vec4.getY(), vec4.getZ(), 0 };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
} else {
|
||||
switch (fs.length) {
|
||||
case 3:
|
||||
Vec3i vec = this.f2r.rotate(this.face).getVector();
|
||||
return new float[] { vec.getX(), vec.getY(), vec.getZ() };
|
||||
case 4:
|
||||
Vector4f veccc = new Vector4f(fs[0], fs[1], fs[2], fs[3]);
|
||||
Vec3i vecc = this.f2r.rotate(this.face).getVector();
|
||||
return new float[] { vecc.getX(), vecc.getY(), vecc.getZ(), veccc.getW() };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadTint(int tint) {
|
||||
this.parent.setQuadTint(tint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadOrientation(Direction orientation) {
|
||||
this.parent.setQuadOrientation(f2r.rotate(orientation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplyDiffuseLighting(boolean diffuse) {
|
||||
this.parent.setApplyDiffuseLighting(diffuse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(Sprite texture) {
|
||||
this.parent.setTexture(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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 net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
/**
|
||||
* Used as the cache key for caching automatically rotated baked models.
|
||||
*/
|
||||
final class AutoRotatingCacheKey {
|
||||
private final BlockState blockState;
|
||||
private final AEModelData modelData;
|
||||
private final Direction side;
|
||||
|
||||
AutoRotatingCacheKey(BlockState blockState, AEModelData modelData, Direction side) {
|
||||
this.blockState = blockState;
|
||||
this.modelData = modelData;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public BlockState getBlockState() {
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
public AEModelData getModelData() {
|
||||
return modelData;
|
||||
}
|
||||
|
||||
public Direction getSide() {
|
||||
return this.side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || this.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoRotatingCacheKey cacheKey = (AutoRotatingCacheKey) o;
|
||||
return this.blockState.equals(cacheKey.blockState) && this.modelData.equals(cacheKey.modelData)
|
||||
&& this.side == cacheKey.side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.blockState.hashCode();
|
||||
result = 31 * result + this.modelData.hashCode();
|
||||
result = 31 * result + (this.side != null ? this.side.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.core.AELog;
|
||||
|
||||
class BiometricCardBakedModel implements BakedModel {
|
||||
|
||||
private final BakedModel baseModel;
|
||||
|
||||
private final Sprite texture;
|
||||
|
||||
private final int hash;
|
||||
|
||||
private final Cache<Integer, BiometricCardBakedModel> modelCache;
|
||||
|
||||
private final ImmutableList<BakedQuad> generalQuads;
|
||||
|
||||
BiometricCardBakedModel(BakedModel baseModel, Sprite texture) {
|
||||
this(baseModel, texture, 0, createCache());
|
||||
}
|
||||
|
||||
private BiometricCardBakedModel(BakedModel baseModel, Sprite texture, int hash,
|
||||
Cache<Integer, BiometricCardBakedModel> modelCache) {
|
||||
this.baseModel = baseModel;
|
||||
this.texture = texture;
|
||||
this.hash = hash;
|
||||
this.generalQuads = ImmutableList.copyOf(this.buildGeneralQuads());
|
||||
this.modelCache = modelCache;
|
||||
}
|
||||
|
||||
private static Cache<Integer, BiometricCardBakedModel> createCache() {
|
||||
return CacheBuilder.newBuilder().maximumSize(100).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
|
||||
List<BakedQuad> quads = this.baseModel.getQuads(state, side, rand, EmptyModelData.INSTANCE);
|
||||
|
||||
if (side != null) {
|
||||
return quads;
|
||||
}
|
||||
|
||||
List<BakedQuad> result = new ArrayList<>(quads.size() + this.generalQuads.size());
|
||||
result.addAll(quads);
|
||||
result.addAll(this.generalQuads);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<BakedQuad> buildGeneralQuads() {
|
||||
CubeBuilder builder = new CubeBuilder();
|
||||
|
||||
builder.setTexture(this.texture);
|
||||
|
||||
AEColor col = AEColor.values()[Math.abs(3 + this.hash) % AEColor.values().length];
|
||||
if (this.hash == 0) {
|
||||
col = AEColor.BLACK;
|
||||
}
|
||||
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = 0; y < 6; y++) {
|
||||
final boolean isLit;
|
||||
|
||||
// This makes the border always use the darker color
|
||||
if (x == 0 || y == 0 || x == 7 || y == 5) {
|
||||
isLit = false;
|
||||
} else {
|
||||
isLit = (this.hash & (1 << x)) != 0 || (this.hash & (1 << y)) != 0;
|
||||
}
|
||||
|
||||
if (isLit) {
|
||||
builder.setColorRGB(col.mediumVariant);
|
||||
} else {
|
||||
final float scale = 0.3f / 255.0f;
|
||||
builder.setColorRGB(((col.blackVariant >> 16) & 0xff) * scale,
|
||||
((col.blackVariant >> 8) & 0xff) * scale, (col.blackVariant & 0xff) * scale);
|
||||
}
|
||||
|
||||
builder.addCube(4 + x, 6 + y, 7.5f, 4 + x + 1, 6 + y + 1, 8.5f);
|
||||
}
|
||||
}
|
||||
return builder.getOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.baseModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return this.baseModel.hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return this.baseModel.isBuiltin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.baseModel.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return this.baseModel.getTransformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return new ModelOverrideList() {
|
||||
@Override
|
||||
public BakedModel getModelWithOverrides(BakedModel originalModel, ItemStack stack, World world,
|
||||
LivingEntity entity) {
|
||||
String username = "";
|
||||
if (stack.getItem() instanceof IBiometricCard) {
|
||||
final GameProfile gp = ((IBiometricCard) stack.getItem()).getProfile(stack);
|
||||
if (gp != null) {
|
||||
if (gp.getId() != null) {
|
||||
username = gp.getId().toString();
|
||||
} else {
|
||||
username = gp.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
final int hash = !username.isEmpty() ? username.hashCode() : 0;
|
||||
|
||||
// Get hash
|
||||
if (hash == 0) {
|
||||
return BiometricCardBakedModel.this;
|
||||
}
|
||||
|
||||
try {
|
||||
return BiometricCardBakedModel.this.modelCache.get(hash,
|
||||
() -> new BiometricCardBakedModel(BiometricCardBakedModel.this.baseModel,
|
||||
BiometricCardBakedModel.this.texture, hash,
|
||||
BiometricCardBakedModel.this.modelCache));
|
||||
} catch (ExecutionException e) {
|
||||
AELog.error(e);
|
||||
return BiometricCardBakedModel.this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesHandlePerspectives() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(ModelTransformation.Mode cameraTransformType, MatrixStack mat) {
|
||||
baseModel.handlePerspective(cameraTransformType, mat);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* Model wrapper for the biometric card item model, which combines a base card
|
||||
* layer with a "visual hash" of the player name
|
||||
*/
|
||||
public class BiometricCardModel implements IModelGeometry<BiometricCardModel> {
|
||||
|
||||
public static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID, "item/biometric_card_base");
|
||||
private static final SpriteIdentifier TEXTURE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "item/biometric_card_hash"));
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.singleton(TEXTURE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform transformIn,
|
||||
ModelOverrideList overrides, Identifier locationIn) {
|
||||
Sprite texture = spriteGetter.apply(TEXTURE);
|
||||
|
||||
BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, transformIn, spriteGetter);
|
||||
|
||||
return new BiometricCardBakedModel(baseModel, texture);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.PerspectiveMapWrapper;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
class ColorApplicatorBakedModel implements BakedModel {
|
||||
|
||||
private final BakedModel baseModel;
|
||||
|
||||
private final IModelTransform transforms;
|
||||
|
||||
private final EnumMap<Direction, List<BakedQuad>> quadsBySide;
|
||||
|
||||
private final List<BakedQuad> generalQuads;
|
||||
|
||||
ColorApplicatorBakedModel(BakedModel baseModel, IModelTransform transforms, Sprite texDark,
|
||||
Sprite texMedium, Sprite texBright) {
|
||||
this.baseModel = baseModel;
|
||||
this.transforms = transforms;
|
||||
|
||||
// Put the tint indices in... Since this is an item model, we are ignoring rand
|
||||
this.generalQuads = this.fixQuadTint(null, texDark, texMedium, texBright);
|
||||
this.quadsBySide = new EnumMap<>(Direction.class);
|
||||
for (Direction facing : Direction.values()) {
|
||||
this.quadsBySide.put(facing, this.fixQuadTint(facing, texDark, texMedium, texBright));
|
||||
}
|
||||
}
|
||||
|
||||
private List<BakedQuad> fixQuadTint(Direction facing, Sprite texDark, Sprite texMedium,
|
||||
Sprite texBright) {
|
||||
List<BakedQuad> quads = this.baseModel.getQuads(null, facing, new Random(0), EmptyModelData.INSTANCE);
|
||||
List<BakedQuad> result = new ArrayList<>(quads.size());
|
||||
for (BakedQuad quad : quads) {
|
||||
int tint;
|
||||
|
||||
if (quad.func_187508_a() == texDark) {
|
||||
tint = 1;
|
||||
} else if (quad.func_187508_a() == texMedium) {
|
||||
tint = 2;
|
||||
} else if (quad.func_187508_a() == texBright) {
|
||||
tint = 3;
|
||||
} else {
|
||||
result.add(quad);
|
||||
continue;
|
||||
}
|
||||
|
||||
BakedQuad newQuad = new BakedQuad(quad.getVertexData(), tint, quad.getFace(), quad.func_187508_a(),
|
||||
quad.shouldApplyDiffuseLighting());
|
||||
result.add(newQuad);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
if (side == null) {
|
||||
return this.generalQuads;
|
||||
}
|
||||
return this.quadsBySide.get(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.baseModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return this.baseModel.hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return this.baseModel.isBuiltin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.baseModel.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return this.baseModel.getTransformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return this.baseModel.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(ModelTransformation.Mode cameraTransformType, MatrixStack mat) {
|
||||
return PerspectiveMapWrapper.handlePerspective(this, transforms, cameraTransformType, mat);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* A color applicator uses the base model, and extends it with additional layers
|
||||
* that are colored according to the selected color of the applicator.
|
||||
*/
|
||||
public class ColorApplicatorModel implements IModelGeometry<ColorApplicatorModel> {
|
||||
|
||||
private static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID,
|
||||
"item/color_applicator_colored");
|
||||
|
||||
private static final SpriteIdentifier TEXTURE_DARK = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "item/color_applicator_tip_dark"));
|
||||
private static final SpriteIdentifier TEXTURE_MEDIUM = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "item/color_applicator_tip_medium"));
|
||||
private static final SpriteIdentifier TEXTURE_BRIGHT = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "item/color_applicator_tip_bright"));
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Arrays.asList(TEXTURE_DARK, TEXTURE_MEDIUM, TEXTURE_DARK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
|
||||
Sprite texDark = spriteGetter.apply(TEXTURE_DARK);
|
||||
Sprite texMedium = spriteGetter.apply(TEXTURE_MEDIUM);
|
||||
Sprite texBright = spriteGetter.apply(TEXTURE_BRIGHT);
|
||||
|
||||
return new ColorApplicatorBakedModel(baseModel, modelTransform, texDark, texMedium, texBright);
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.block.storage.DriveSlotCellType;
|
||||
import appeng.block.storage.DriveSlotsState;
|
||||
import appeng.client.render.DelegateBakedModel;
|
||||
import appeng.core.Api;
|
||||
|
||||
public class DriveBakedModel extends DelegateBakedModel {
|
||||
private final Map<DriveSlotCellType, BakedModel> bakedCells;
|
||||
|
||||
public DriveBakedModel(BakedModel bakedBase, Map<DriveSlotCellType, BakedModel> bakedCells) {
|
||||
super(bakedBase);
|
||||
this.bakedCells = bakedCells;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
|
||||
@Nonnull IModelData extraData) {
|
||||
|
||||
List<BakedQuad> result = new ArrayList<>(super.getQuads(state, side, rand, extraData));
|
||||
|
||||
if (!(extraData instanceof DriveModelData)) {
|
||||
return result;
|
||||
}
|
||||
DriveModelData driveModelData = (DriveModelData) extraData;
|
||||
|
||||
DriveSlotsState slotsState = driveModelData.getSlotsState();
|
||||
|
||||
if (slotsState != null) {
|
||||
for (int row = 0; row < 5; row++) {
|
||||
for (int col = 0; col < 2; col++) {
|
||||
Matrix4f transform = new Matrix4f();
|
||||
|
||||
// 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 * 8 / 16.0f;
|
||||
float yOffset = -row * 3 / 16.0f;
|
||||
transform.addToLastColumn(new Vector3f(xOffset, yOffset, 0));
|
||||
|
||||
int slot = row * 2 + col;
|
||||
|
||||
// Add the drive chassis
|
||||
Item cell = slotsState.getCell(slot);
|
||||
BakedModel cellChassisModel = getCellChassisModel(cell);
|
||||
addModel(state, rand, extraData, result, side, cellChassisModel, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
// 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 BakedModel 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, Direction side, IBakedModel bakedCell, Matrix4f transform) {
|
||||
MatrixVertexTransformer transformer = new MatrixVertexTransformer(transform);
|
||||
for (BakedQuad bakedQuad : bakedCell.getQuads(state, side, rand, extraData)) {
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||
transformer.setParent(builder);
|
||||
transformer.setVertexFormat(builder.getVertexFormat());
|
||||
bakedQuad.pipe(transformer);
|
||||
result.add(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.block.storage.DriveSlotCellType;
|
||||
|
||||
public class DriveModel implements IModelGeometry<DriveModel> {
|
||||
|
||||
private static final Identifier MODEL_BASE = new Identifier(
|
||||
"appliedenergistics2:block/drive/drive_base");
|
||||
|
||||
private static final Map<DriveSlotCellType, Identifier> MODELS_CELLS = ImmutableMap.of(
|
||||
DriveSlotCellType.EMPTY, new Identifier("appliedenergistics2:block/drive/drive_cell_empty"),
|
||||
DriveSlotCellType.ITEM, new Identifier("appliedenergistics2:block/drive/drive_cell_items"),
|
||||
DriveSlotCellType.FLUID, new Identifier("appliedenergistics2:block/drive/drive_cell_fluids"));
|
||||
|
||||
public static final Set<Identifier> DEPENDENCIES = ImmutableSet.<Identifier>builder()
|
||||
.addAll(MODELS_CELLS.values()).add(MODEL_BASE).build();
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
EnumMap<DriveSlotCellType, BakedModel> cellModels = new EnumMap<>(DriveSlotCellType.class);
|
||||
|
||||
// Load the base model and the model for each cell state.
|
||||
for (DriveSlotCellType cellType : MODELS_CELLS.keySet()) {
|
||||
BakedModel cellModel = bakery.getBakedModel(MODELS_CELLS.get(cellType), modelTransform, spriteGetter);
|
||||
cellModels.put(cellType, cellModel);
|
||||
}
|
||||
|
||||
BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
return new DriveBakedModel(baseModel, cellModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import appeng.block.storage.DriveSlotsState;
|
||||
|
||||
public class DriveModelData extends AEModelData {
|
||||
|
||||
private final DriveSlotsState slotsState;
|
||||
|
||||
public DriveModelData(Direction up, Direction forward, DriveSlotsState slotsState) {
|
||||
super(up, forward);
|
||||
this.slotsState = slotsState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable() {
|
||||
return false; // Too many combinations
|
||||
}
|
||||
|
||||
public DriveSlotsState getSlotsState() {
|
||||
return slotsState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
DriveModelData that = (DriveModelData) o;
|
||||
return slotsState.equals(that.slotsState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), slotsState);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,328 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormatElement;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
|
||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
|
||||
import appeng.decorative.solid.GlassState;
|
||||
import appeng.decorative.solid.QuartzGlassBlock;
|
||||
|
||||
class GlassBakedModel implements IDynamicBakedModel {
|
||||
|
||||
// This unlisted property is used to determine the actual block that should be
|
||||
// rendered
|
||||
public static final ModelProperty<GlassState> GLASS_STATE = new ModelProperty<>();
|
||||
|
||||
private static final byte[][][] OFFSETS = generateOffsets();
|
||||
|
||||
// Alternating textures based on position
|
||||
static final SpriteIdentifier TEXTURE_A = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier("appliedenergistics2:block/glass/quartz_glass_a"));
|
||||
static final SpriteIdentifier TEXTURE_B = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier("appliedenergistics2:block/glass/quartz_glass_b"));
|
||||
static final SpriteIdentifier TEXTURE_C = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier("appliedenergistics2:block/glass/quartz_glass_c"));
|
||||
static final SpriteIdentifier TEXTURE_D = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier("appliedenergistics2:block/glass/quartz_glass_d"));
|
||||
|
||||
// Frame texture
|
||||
static final SpriteIdentifier[] TEXTURES_FRAME = generateTexturesFrame();
|
||||
|
||||
// Generates the required textures for the frame
|
||||
private static SpriteIdentifier[] generateTexturesFrame() {
|
||||
return IntStream.range(1, 16).mapToObj(Integer::toBinaryString).map(s -> Strings.padStart(s, 4, '0'))
|
||||
.map(s -> new Identifier("appliedenergistics2:block/glass/quartz_glass_frame" + s))
|
||||
.map(rl -> new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, rl)).toArray(SpriteIdentifier[]::new);
|
||||
}
|
||||
|
||||
private final Sprite[] glassTextures;
|
||||
|
||||
private final Sprite[] frameTextures;
|
||||
|
||||
public GlassBakedModel(Function<SpriteIdentifier, Sprite> bakedTextureGetter) {
|
||||
this.glassTextures = new Sprite[] { bakedTextureGetter.apply(TEXTURE_A),
|
||||
bakedTextureGetter.apply(TEXTURE_B), bakedTextureGetter.apply(TEXTURE_C),
|
||||
bakedTextureGetter.apply(TEXTURE_D) };
|
||||
|
||||
// The first frame texture would be empty, so we simply leave it set to null
|
||||
// here
|
||||
this.frameTextures = new Sprite[16];
|
||||
for (int i = 0; i < TEXTURES_FRAME.length; i++) {
|
||||
this.frameTextures[1 + i] = bakedTextureGetter.apply(TEXTURES_FRAME[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand,
|
||||
IModelData extraData) {
|
||||
if (side == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final GlassState glassState = extraData.getData(GLASS_STATE);
|
||||
|
||||
if (glassState == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// TODO: This could just use the Random instance we're given...
|
||||
final int cx = Math.abs(glassState.getX() % 10);
|
||||
final int cy = Math.abs(glassState.getY() % 10);
|
||||
final int cz = Math.abs(glassState.getZ() % 10);
|
||||
|
||||
int u = OFFSETS[cx][cy][cz] % 4;
|
||||
int v = OFFSETS[9 - cx][9 - cy][9 - cz] % 4;
|
||||
|
||||
int texIdx = Math.abs((OFFSETS[cx][cy][cz] + (glassState.getX() + glassState.getY() + glassState.getZ())) % 4);
|
||||
|
||||
if (texIdx < 2) {
|
||||
u /= 2;
|
||||
v /= 2;
|
||||
}
|
||||
|
||||
final Sprite glassTexture = this.glassTextures[texIdx];
|
||||
|
||||
// Render the glass side
|
||||
final List<BakedQuad> quads = new ArrayList<>(5); // At most 5
|
||||
|
||||
final List<Vec3d> corners = RenderHelper.getFaceCorners(side);
|
||||
quads.add(this.createQuad(side, corners, glassTexture, u, v));
|
||||
|
||||
/*
|
||||
* This needs some explanation: The bit-field contains 4-bits, one for each
|
||||
* direction that a frame may be drawn. Converted to a number, the bit-field is
|
||||
* then used as an index into the list of frame textures, which have been
|
||||
* created in such a way that their filenames indicate, in which directions they
|
||||
* contain borders. i.e. bitmask = 0101 means a border should be drawn up and
|
||||
* down (in terms of u,v space). Converted to a number, this bitmask is 5. So
|
||||
* the texture at index 5 is used. That texture had "0101" in its filename to
|
||||
* indicate this.
|
||||
*/
|
||||
final int edgeBitmask = makeBitmask(glassState, side);
|
||||
final Sprite sideSprite = this.frameTextures[edgeBitmask];
|
||||
|
||||
if (sideSprite != null) {
|
||||
quads.add(this.createQuad(side, corners, sideSprite, 0, 0));
|
||||
}
|
||||
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
// TODO: Forge: Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the bitmask that indicates, in which directions (in terms of u,v
|
||||
* space) a border should be drawn.
|
||||
*/
|
||||
private static int makeBitmask(GlassState state, Direction side) {
|
||||
switch (side) {
|
||||
case DOWN:
|
||||
return makeBitmask(state, Direction.SOUTH, Direction.EAST, Direction.NORTH, Direction.WEST);
|
||||
case UP:
|
||||
return makeBitmask(state, Direction.SOUTH, Direction.WEST, Direction.NORTH, Direction.EAST);
|
||||
case NORTH:
|
||||
return makeBitmask(state, Direction.UP, Direction.WEST, Direction.DOWN, Direction.EAST);
|
||||
case SOUTH:
|
||||
return makeBitmask(state, Direction.UP, Direction.EAST, Direction.DOWN, Direction.WEST);
|
||||
case WEST:
|
||||
return makeBitmask(state, Direction.UP, Direction.SOUTH, Direction.DOWN, Direction.NORTH);
|
||||
case EAST:
|
||||
return makeBitmask(state, Direction.UP, Direction.NORTH, Direction.DOWN, Direction.SOUTH);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported side!");
|
||||
}
|
||||
}
|
||||
|
||||
private static int makeBitmask(GlassState state, Direction up, Direction right, Direction down, Direction left) {
|
||||
|
||||
int bitmask = 0;
|
||||
|
||||
if (!state.isFlushWith(up)) {
|
||||
bitmask |= 1;
|
||||
}
|
||||
if (!state.isFlushWith(right)) {
|
||||
bitmask |= 2;
|
||||
}
|
||||
if (!state.isFlushWith(down)) {
|
||||
bitmask |= 4;
|
||||
}
|
||||
if (!state.isFlushWith(left)) {
|
||||
bitmask |= 8;
|
||||
}
|
||||
return bitmask;
|
||||
}
|
||||
|
||||
private BakedQuad createQuad(Direction side, List<Vec3d> corners, Sprite sprite, float uOffset,
|
||||
float vOffset) {
|
||||
return this.createQuad(side, corners.get(0), corners.get(1), corners.get(2), corners.get(3), sprite, uOffset,
|
||||
vOffset);
|
||||
}
|
||||
|
||||
private BakedQuad createQuad(Direction side, Vec3d c1, Vec3d c2, Vec3d c3, Vec3d c4, Sprite sprite,
|
||||
float uOffset, float vOffset) {
|
||||
Vec3d normal = new Vec3d(side.getVector());
|
||||
|
||||
// Apply the u,v shift.
|
||||
// This mirrors the logic from OffsetIcon from 1.7
|
||||
float u1 = MathHelper.clamp(0 - uOffset, 0, 16);
|
||||
float u2 = MathHelper.clamp(16 - uOffset, 0, 16);
|
||||
float v1 = MathHelper.clamp(0 - vOffset, 0, 16);
|
||||
float v2 = MathHelper.clamp(16 - vOffset, 0, 16);
|
||||
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
|
||||
builder.setQuadOrientation(side);
|
||||
this.putVertex(builder, normal, c1.x, c1.y, c1.z, sprite, u1, v1);
|
||||
this.putVertex(builder, normal, c2.x, c2.y, c2.z, sprite, u1, v2);
|
||||
this.putVertex(builder, normal, c3.x, c3.y, c3.z, sprite, u2, v2);
|
||||
this.putVertex(builder, normal, c4.x, c4.y, c4.z, sprite, u2, v1);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/*
|
||||
* This method is as complicated as it is, because the order in which we push
|
||||
* data into the vertexbuffer actually has to be precisely the order in which
|
||||
* the vertex elements had been declared in the vertex format.
|
||||
*/
|
||||
private void putVertex(BakedQuadBuilder builder, Vec3d normal, double x, double y, double z,
|
||||
Sprite sprite, float u, float v) {
|
||||
VertexFormat vertexFormat = builder.getVertexFormat();
|
||||
for (int e = 0; e < vertexFormat.getElements().size(); e++) {
|
||||
VertexFormatElement el = vertexFormat.getElements().get(e);
|
||||
switch (el.getType()) {
|
||||
case POSITION:
|
||||
builder.put(e, (float) x, (float) y, (float) z, 1.0f);
|
||||
break;
|
||||
case COLOR:
|
||||
builder.put(e, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
break;
|
||||
case NORMAL:
|
||||
builder.put(e, (float) normal.x, (float) normal.y, (float) normal.z, 0f);
|
||||
break;
|
||||
case UV:
|
||||
if (el.getIndex() == 0) {
|
||||
u = sprite.getFrameU(u);
|
||||
v = sprite.getFrameV(v);
|
||||
builder.put(e, u, v, 0f, 1f);
|
||||
break;
|
||||
}
|
||||
// Important: Fall through for getIndex() != 0
|
||||
default:
|
||||
builder.put(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.frameTextures[this.frameTextures.length - 1];
|
||||
}
|
||||
|
||||
private static byte[][][] generateOffsets() {
|
||||
final Random r = new Random(924);
|
||||
final byte[][][] offset = new byte[10][10][10];
|
||||
|
||||
for (int x = 0; x < 10; x++) {
|
||||
for (int y = 0; y < 10; y++) {
|
||||
r.nextBytes(offset[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData(@Nonnull BlockRenderView world, @Nonnull BlockPos pos, @Nonnull BlockState state,
|
||||
@Nonnull IModelData tileData) {
|
||||
|
||||
EnumSet<Direction> flushWith = EnumSet.noneOf(Direction.class);
|
||||
// Test every direction for another glass block
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (isGlassBlock(world, pos, facing)) {
|
||||
flushWith.add(facing);
|
||||
}
|
||||
}
|
||||
|
||||
GlassState glassState = new GlassState(pos.getX(), pos.getY(), pos.getZ(), flushWith);
|
||||
return new ModelDataMap.Builder().withInitial(GLASS_STATE, glassState).build();
|
||||
|
||||
}
|
||||
|
||||
private static boolean isGlassBlock(BlockView world, BlockPos pos, Direction facing) {
|
||||
return world.getBlockState(pos.offset(facing)).getBlock() instanceof QuartzGlassBlock;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
/**
|
||||
* Model class for the connected texture glass model.
|
||||
*/
|
||||
public class GlassModel implements IModelGeometry<GlassModel> {
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
return new GlassBakedModel(spriteGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return ImmutableSet
|
||||
.<SpriteIdentifier>builder().add(GlassBakedModel.TEXTURE_A, GlassBakedModel.TEXTURE_B,
|
||||
GlassBakedModel.TEXTURE_C, GlassBakedModel.TEXTURE_D)
|
||||
.add(GlassBakedModel.TEXTURES_FRAME).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
import net.minecraft.client.render.VertexFormatElement;
|
||||
import net.minecraft.client.util.math.Vector4f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
|
||||
|
||||
/**
|
||||
* Applies an arbitrary transformation matrix to the vertices of a quad.
|
||||
*/
|
||||
final class MatrixVertexTransformer extends QuadGatheringTransformer {
|
||||
|
||||
private final Matrix4f transform;
|
||||
|
||||
public MatrixVertexTransformer(Matrix4f transform) {
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processQuad() {
|
||||
VertexFormat format = this.parent.getVertexFormat();
|
||||
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 = elements.get(e);
|
||||
if (element.getType() == VertexFormatElement.Usage.POSITION) {
|
||||
this.parent.put(e, this.transform(this.quadData[e][v], element.getElementCount()));
|
||||
} else if (element.getType() == VertexFormatElement.Usage.NORMAL) {
|
||||
this.parent.put(e, this.transformNormal(this.quadData[e][v]));
|
||||
} else {
|
||||
this.parent.put(e, this.quadData[e][v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadTint(int tint) {
|
||||
this.parent.setQuadTint(tint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadOrientation(Direction orientation) {
|
||||
this.parent.setQuadOrientation(orientation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplyDiffuseLighting(boolean diffuse) {
|
||||
this.parent.setApplyDiffuseLighting(diffuse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(Sprite texture) {
|
||||
this.parent.setTexture(texture);
|
||||
}
|
||||
|
||||
private float[] transform(float[] fs, int elemCount) {
|
||||
switch (fs.length) {
|
||||
case 3:
|
||||
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.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.setW(1);
|
||||
}
|
||||
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.getX(), vecc.getY(), vecc.getZ(), vecc.getW() };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
private float[] transformNormal(float[] fs) {
|
||||
Vector4f normal;
|
||||
|
||||
switch (fs.length) {
|
||||
case 3:
|
||||
normal = new Vector4f(fs[0], fs[1], fs[2], 0);
|
||||
normal.transform(this.transform);
|
||||
normal.normalize();
|
||||
return new float[] { normal.getX(), normal.getY(), normal.getZ() };
|
||||
|
||||
case 4:
|
||||
normal = new Vector4f(fs[0], fs[1], fs[2], fs[3]);
|
||||
normal.transform(this.transform);
|
||||
normal.normalize();
|
||||
return new float[] { normal.getX(), normal.getY(), normal.getZ(), normal.getW() };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.core.AELog;
|
||||
|
||||
class MemoryCardBakedModel implements BakedModel {
|
||||
private static final AEColor[] DEFAULT_COLOR_CODE = new AEColor[] { AEColor.TRANSPARENT, AEColor.TRANSPARENT,
|
||||
AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT,
|
||||
AEColor.TRANSPARENT, };
|
||||
|
||||
private final BakedModel baseModel;
|
||||
|
||||
private final Sprite texture;
|
||||
|
||||
private final AEColor[] colorCode;
|
||||
|
||||
private final Cache<CacheKey, MemoryCardBakedModel> modelCache;
|
||||
|
||||
private final ImmutableList<BakedQuad> generalQuads;
|
||||
|
||||
MemoryCardBakedModel(BakedModel baseModel, Sprite texture) {
|
||||
this(baseModel, texture, DEFAULT_COLOR_CODE, createCache());
|
||||
}
|
||||
|
||||
private MemoryCardBakedModel(BakedModel baseModel, Sprite texture, AEColor[] hash,
|
||||
Cache<CacheKey, MemoryCardBakedModel> modelCache) {
|
||||
this.baseModel = baseModel;
|
||||
this.texture = texture;
|
||||
this.colorCode = hash;
|
||||
this.generalQuads = ImmutableList.copyOf(this.buildGeneralQuads());
|
||||
this.modelCache = modelCache;
|
||||
}
|
||||
|
||||
private static Cache<CacheKey, MemoryCardBakedModel> createCache() {
|
||||
return CacheBuilder.newBuilder().maximumSize(100).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
|
||||
List<BakedQuad> quads = this.baseModel.getQuads(state, side, rand, EmptyModelData.INSTANCE);
|
||||
|
||||
if (side != null) {
|
||||
return quads;
|
||||
}
|
||||
|
||||
List<BakedQuad> result = new ArrayList<>(quads.size() + this.generalQuads.size());
|
||||
result.addAll(quads);
|
||||
result.addAll(this.generalQuads);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<BakedQuad> buildGeneralQuads() {
|
||||
CubeBuilder builder = new CubeBuilder();
|
||||
|
||||
builder.setTexture(this.texture);
|
||||
|
||||
for (int x = 0; x < 4; x++) {
|
||||
for (int y = 0; y < 2; y++) {
|
||||
final AEColor color = this.colorCode[x + y * 4];
|
||||
|
||||
builder.setColorRGB(color.mediumVariant);
|
||||
builder.addCube(7 + x, 8 + (1 - y), 7.5f, 7 + x + 1, 8 + (1 - y) + 1, 8.5f);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.getOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.baseModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return this.baseModel.hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return this.baseModel.isBuiltin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.baseModel.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return this.baseModel.getTransformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return new ModelOverrideList() {
|
||||
@Override
|
||||
public BakedModel getModelWithOverrides(BakedModel originalModel, ItemStack stack, World world,
|
||||
LivingEntity entity) {
|
||||
try {
|
||||
if (stack.getItem() instanceof IMemoryCard) {
|
||||
final IMemoryCard memoryCard = (IMemoryCard) stack.getItem();
|
||||
final AEColor[] colors = memoryCard.getColorCode(stack);
|
||||
|
||||
return MemoryCardBakedModel.this.modelCache.get(new CacheKey(colors),
|
||||
() -> new MemoryCardBakedModel(MemoryCardBakedModel.this.baseModel,
|
||||
MemoryCardBakedModel.this.texture, colors,
|
||||
MemoryCardBakedModel.this.modelCache));
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
AELog.error(e);
|
||||
}
|
||||
|
||||
return MemoryCardBakedModel.this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(ModelTransformation.Mode cameraTransformType, MatrixStack mat) {
|
||||
baseModel.handlePerspective(cameraTransformType, mat);
|
||||
return this;
|
||||
}
|
||||
|
||||
private static class CacheKey {
|
||||
private final AEColor[] key;
|
||||
|
||||
CacheKey(AEColor[] key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(this.key);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
CacheKey other = (CacheKey) obj;
|
||||
return Arrays.equals(this.key, other.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
/**
|
||||
* Model wrapper for the memory card item model, which combines a base card
|
||||
* layer with a "visual hash" of the part/tile.
|
||||
*/
|
||||
public class MemoryCardModel implements IModelGeometry<MemoryCardModel> {
|
||||
|
||||
public static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID, "item/memory_card_base");
|
||||
private static final SpriteIdentifier TEXTURE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "item/memory_card_hash"));
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.singleton(TEXTURE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
Sprite texture = spriteGetter.apply(TEXTURE);
|
||||
|
||||
BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
|
||||
return new MemoryCardBakedModel(baseModel, texture);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
// TODO: Investigate use of CubeBuilder instead
|
||||
final class RenderHelper {
|
||||
|
||||
private static EnumMap<Direction, List<Vec3d>> cornersForFacing = generateCornersForFacings();
|
||||
|
||||
private RenderHelper() {
|
||||
|
||||
}
|
||||
|
||||
static List<Vec3d> getFaceCorners(Direction side) {
|
||||
return cornersForFacing.get(side);
|
||||
}
|
||||
|
||||
private static EnumMap<Direction, List<Vec3d>> generateCornersForFacings() {
|
||||
EnumMap<Direction, List<Vec3d>> result = new EnumMap<>(Direction.class);
|
||||
|
||||
for (Direction facing : Direction.values()) {
|
||||
List<Vec3d> corners;
|
||||
|
||||
float offset = (facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE) ? 0 : 1;
|
||||
|
||||
switch (facing.getAxis()) {
|
||||
default:
|
||||
case X:
|
||||
corners = Lists.newArrayList(new Vec3d(offset, 1, 1), new Vec3d(offset, 0, 1),
|
||||
new Vec3d(offset, 0, 0), new Vec3d(offset, 1, 0));
|
||||
break;
|
||||
case Y:
|
||||
corners = Lists.newArrayList(new Vec3d(1, offset, 1), new Vec3d(1, offset, 0),
|
||||
new Vec3d(0, offset, 0), new Vec3d(0, offset, 1));
|
||||
break;
|
||||
case Z:
|
||||
corners = Lists.newArrayList(new Vec3d(0, 1, offset), new Vec3d(0, 0, offset),
|
||||
new Vec3d(1, 0, offset), new Vec3d(1, 1, offset));
|
||||
break;
|
||||
}
|
||||
|
||||
if (facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE) {
|
||||
corners = Lists.reverse(corners);
|
||||
}
|
||||
|
||||
result.put(facing, ImmutableList.copyOf(corners));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Vec3d adjust(Vec3d vec, Direction.Axis axis, double delta) {
|
||||
switch (axis) {
|
||||
default:
|
||||
case X:
|
||||
return new Vec3d(vec.x + delta, vec.y, vec.z);
|
||||
case Y:
|
||||
return new Vec3d(vec.x, vec.y + delta, vec.z);
|
||||
case Z:
|
||||
return new Vec3d(vec.x, vec.y, vec.z + delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.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.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.
|
||||
*/
|
||||
public class SkyCompassBakedModel implements IDynamicBakedModel {
|
||||
// Rotation is expressed as radians
|
||||
public static final ModelProperty<Float> ROTATION = new ModelProperty<>();
|
||||
|
||||
private final BakedModel base;
|
||||
|
||||
private final BakedModel pointer;
|
||||
|
||||
private float fallbackRotation = 0;
|
||||
|
||||
public SkyCompassBakedModel(BakedModel base, BakedModel 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;
|
||||
}
|
||||
|
||||
// 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.loadIdentity();
|
||||
matrix.multiply(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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.base.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.base.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return this.base.getTransformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList 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 ModelOverrideList() {
|
||||
@Override
|
||||
public BakedModel getModelWithOverrides(BakedModel 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.yaw / 180.0f * (float) Math.PI + Math.PI);
|
||||
|
||||
SkyCompassBakedModel.this.fallbackRotation = offRads
|
||||
+ getAnimatedRotation(player.getPosition(), true);
|
||||
} else {
|
||||
SkyCompassBakedModel.this.fallbackRotation = getAnimatedRotation(null, false);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
// 3 seconds per full rotation
|
||||
timeMillis %= 3000;
|
||||
return timeMillis / 3000.f * (float) Math.PI * 2;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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 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 com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
/**
|
||||
* The parent model for the compass baked model. Declares the dependencies for
|
||||
* the base and pointer submodels mostly.
|
||||
*/
|
||||
public class SkyCompassModel implements IModelGeometry<SkyCompassModel> {
|
||||
|
||||
private static final Identifier MODEL_BASE = new Identifier(
|
||||
"appliedenergistics2:block/sky_compass_base");
|
||||
|
||||
private static final Identifier MODEL_POINTER = new Identifier(
|
||||
"appliedenergistics2:block/sky_compass_pointer");
|
||||
|
||||
public static final List<Identifier> DEPENDENCIES = ImmutableList.of(MODEL_BASE, MODEL_POINTER);
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter);
|
||||
BakedModel pointerModel = bakery.getBakedModel(MODEL_POINTER, modelTransform, spriteGetter);
|
||||
return new SkyCompassBakedModel(baseModel, pointerModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.BlockFaceUV;
|
||||
import net.minecraft.client.render.model.BlockModel;
|
||||
import net.minecraft.client.render.model.BlockPart;
|
||||
import net.minecraft.client.render.model.BlockPartFace;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.ItemOverride;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.render.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraftforge.client.model.IModelBuilder;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
public class UVLModelLoader implements IModelLoader<UVLModelLoader.UVLModelWrapper> {
|
||||
|
||||
public static final UVLModelLoader INSTANCE = new UVLModelLoader();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UVLModelWrapper read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
|
||||
modelContents.remove("loader");
|
||||
BlockModel blockModel = UVLSERIALIZER.fromJson(modelContents, BlockModel.class);
|
||||
return new UVLModelWrapper(blockModel);
|
||||
}
|
||||
|
||||
final Gson UVLSERIALIZER = (new GsonBuilder())
|
||||
.registerTypeAdapter(BlockModel.class, new ModelLoaderRegistry.ExpandedBlockModelDeserializer())
|
||||
.registerTypeAdapter(BlockPart.class, new BlockPart.Deserializer())
|
||||
.registerTypeAdapter(BlockPartFace.class, new BlockPartFaceOverrideSerializer())
|
||||
.registerTypeAdapter(BlockFaceUV.class, new BlockFaceUV.Deserializer())
|
||||
.registerTypeAdapter(ItemTransformVec3f.class, new ItemTransformVec3f.Deserializer())
|
||||
.registerTypeAdapter(ModelTransformation.class, new ModelTransformation.Deserializer())
|
||||
.registerTypeAdapter(ItemOverride.class, new ItemOverride.Deserializer())
|
||||
.registerTypeAdapter(AffineTransformation.class, new TransformationHelper.Deserializer()).create();
|
||||
|
||||
private static class BlockPartFaceOverrideSerializer extends BlockPartFace.Deserializer {
|
||||
@Override
|
||||
public BlockPartFace deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_,
|
||||
JsonDeserializationContext p_deserialize_3_) throws JsonParseException {
|
||||
BlockPartFace blockFace = super.deserialize(p_deserialize_1_, p_deserialize_2_, p_deserialize_3_);
|
||||
Pair<Float, Float> uvl = this.parseUVL(p_deserialize_1_.getAsJsonObject());
|
||||
if (uvl != null) {
|
||||
return new BlockPartFaceWithUVL(blockFace.cullFace, blockFace.tintIndex, blockFace.texture,
|
||||
blockFace.blockFaceUV, uvl.getLeft(), uvl.getRight());
|
||||
}
|
||||
return blockFace;
|
||||
}
|
||||
|
||||
protected Pair<Float, Float> parseUVL(JsonObject object) {
|
||||
if (!object.has("uvlightmap")) {
|
||||
return null;
|
||||
}
|
||||
object = object.get("uvlightmap").getAsJsonObject();
|
||||
return new ImmutablePair<>(JsonHelper.getFloat(object, "sky", 0), JsonHelper.getFloat(object, "block", 0));
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockPartFaceWithUVL extends BlockPartFace {
|
||||
|
||||
private final float sky;
|
||||
private final float block;
|
||||
|
||||
public BlockPartFaceWithUVL(@Nullable Direction cullFaceIn, int tintIndexIn, String textureIn,
|
||||
BlockFaceUV blockFaceUVIn, float sky, float block) {
|
||||
super(cullFaceIn, tintIndexIn, textureIn, blockFaceUVIn);
|
||||
this.sky = sky;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public float getSky() {
|
||||
return sky;
|
||||
}
|
||||
|
||||
public float getBlock() {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UVLModelWrapper implements IModelGeometry<UVLModelWrapper> {
|
||||
private final BlockModel parent;
|
||||
|
||||
public UVLModelWrapper(BlockModel parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
Sprite particle = spriteGetter.apply(owner.resolveTexture("particle"));
|
||||
|
||||
IModelBuilder<?> builder = IModelBuilder.of(owner, overrides, particle);
|
||||
for (BlockPart blockpart : parent.getElements()) {
|
||||
for (Direction direction : blockpart.mapFaces.keySet()) {
|
||||
BlockPartFace blockpartface = blockpart.mapFaces.get(direction);
|
||||
Sprite textureatlassprite1 = spriteGetter
|
||||
.apply(owner.resolveTexture(blockpartface.texture));
|
||||
BakedQuad quad = BlockModel.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, direction,
|
||||
modelTransform, modelLocation);
|
||||
|
||||
if (blockpartface instanceof BlockPartFaceWithUVL) {
|
||||
BlockPartFaceWithUVL uvlFace = (BlockPartFaceWithUVL) blockpartface;
|
||||
quad = applyPreBakedLighting(quad, textureatlassprite1, uvlFace.sky, uvlFace.block);
|
||||
}
|
||||
|
||||
if (blockpartface.cullFace == null) {
|
||||
builder.addGeneralQuad(quad);
|
||||
} else {
|
||||
builder.addFaceQuad(modelTransform.getRotation().rotateTransform(blockpartface.cullFace), quad);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private BakedQuad applyPreBakedLighting(BakedQuad quad, Sprite sprite, float sky, float block) {
|
||||
// FIXME: just piping through the quads and manipulating uv index 2 directly
|
||||
// seems way easier than this
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
|
||||
VertexLighterFlat trans = new VertexLighterFlat(MinecraftClient.getInstance().getBlockColors()) {
|
||||
|
||||
@Override
|
||||
protected void updateLightmap(float[] normal, float[] lightmap, float x, float y, float z) {
|
||||
lightmap[0] = block;
|
||||
lightmap[1] = sky;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadTint(int tint) {
|
||||
// Tint requires a block state which we don't have at this point
|
||||
}
|
||||
};
|
||||
MatrixStack identity = new MatrixStack();
|
||||
trans.setTransform(identity.getLast());
|
||||
trans.setParent(builder);
|
||||
quad.pipe(trans);
|
||||
builder.setQuadTint(quad.getColorIndex());
|
||||
builder.setQuadOrientation(quad.getFace());
|
||||
builder.setApplyDiffuseLighting(false);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter,
|
||||
Set<com.mojang.datafixers.util.Pair<String, String>> missingTextureErrors) {
|
||||
return parent.getTextures(modelGetter, missingTextureErrors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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.renderable;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.render.model.json.Transformation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ItemRenderable<T extends BlockEntity> implements Renderable<T> {
|
||||
|
||||
private final Function<T, Pair<ItemStack, Transformation>> f;
|
||||
|
||||
public ItemRenderable(Function<T, Pair<ItemStack, Transformation>> f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(T te, float partialTicks, net.minecraft.client.util.math.MatrixStack matrixStack,
|
||||
VertexConsumerProvider buffers, int combinedLight, int combinedOverlay) {
|
||||
Pair<ItemStack, Transformation> pair = this.f.apply(te);
|
||||
if (pair != null && pair.getLeft() != null) {
|
||||
matrixStack.push();
|
||||
if (pair.getRight() != null) {
|
||||
pair.getRight().apply(true, matrixStack); // FIXME: check left handed
|
||||
}
|
||||
MinecraftClient.getInstance().getItemRenderer().renderItem(pair.getLeft(),
|
||||
ModelTransformation.Mode.GROUND, combinedLight, combinedOverlay, matrixStack, buffers);
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.renderable;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
|
||||
public interface Renderable<T extends BlockEntity> {
|
||||
|
||||
void renderTileEntityAt(T te, float partialTicks, MatrixStack matrixStack, VertexConsumerProvider buffers,
|
||||
int combinedLight, int combinedOverlay);
|
||||
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* 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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
|
||||
|
||||
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 IDynamicBakedModel {
|
||||
|
||||
private final Map<SpatialPylonTextureType, Sprite> textures;
|
||||
|
||||
SpatialPylonBakedModel(Map<SpatialPylonTextureType, Sprite> textures) {
|
||||
this.textures = ImmutableMap.copyOf(textures);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
|
||||
@Nonnull IModelData extraData) {
|
||||
int flags = this.getFlags(extraData);
|
||||
|
||||
CubeBuilder builder = new CubeBuilder();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return builder.getOutput();
|
||||
}
|
||||
|
||||
private int getFlags(IModelData modelData) {
|
||||
Integer flags = modelData.getData(SpatialPylonBlockEntity.STATE);
|
||||
return flags != null ? flags : 0;
|
||||
}
|
||||
|
||||
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 ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class SpatialPylonModel implements IModelGeometry<SpatialPylonModel> {
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
Map<SpatialPylonTextureType, Sprite> textures = new EnumMap<>(SpatialPylonTextureType.class);
|
||||
|
||||
for (SpatialPylonTextureType type : SpatialPylonTextureType.values()) {
|
||||
textures.put(type, spriteGetter.apply(getTexturePath(type)));
|
||||
}
|
||||
|
||||
return new SpatialPylonBakedModel(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Arrays.stream(SpatialPylonTextureType.values()).map(SpatialPylonModel::getTexturePath)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static SpriteIdentifier getTexturePath(SpatialPylonTextureType type) {
|
||||
return new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/spatial_pylon/" + type.name().toLowerCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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 net.fabricmc.api.EnvType;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
|
||||
public class SpatialPylonRendering extends BlockRenderingCustomizer {
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.tesr;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.tile.grindstone.CrankBlockEntity;
|
||||
|
||||
/**
|
||||
* This FastTESR only handles the animated model of the turning crank. When the
|
||||
* crank is at rest, it is rendered using a normal model.
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class CrankTESR extends BlockEntityRenderer<CrankBlockEntity> {
|
||||
|
||||
public CrankTESR(BlockEntityRenderDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(CrankBlockEntity te, float partialTicks, MatrixStack ms, VertexConsumerProvider buffers,
|
||||
int combinedLightIn, int combinedOverlayIn) {
|
||||
|
||||
// Apply GL transformations relative to the center of the block: 1) TE rotation
|
||||
// and 2) crank rotation
|
||||
ms.push();
|
||||
ms.translate(0.5, 0.5, 0.5);
|
||||
FacingToRotation.get(te.getForward(), te.getUp()).push(ms);
|
||||
ms.multiply(new Quaternion(0, te.getVisibleRotation(), 0, true));
|
||||
ms.translate(-0.5, -0.5, -0.5);
|
||||
|
||||
BlockState blockState = te.getCachedState();
|
||||
BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
BakedModel model = dispatcher.getModel(blockState);
|
||||
VertexConsumer buffer = buffers.getBuffer(TexturedRenderLayers.getEntityTranslucentCull());
|
||||
dispatcher.getModelRenderer().renderModelBrightnessColor(ms.peek(), buffer, null, model, 1, 1, 1,
|
||||
combinedLightIn, combinedOverlayIn);
|
||||
ms.pop();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
package appeng.client.render.tesr;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.renderer.RenderState;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.block.storage.DriveSlotState;
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.tile.storage.DriveBlockEntity;
|
||||
|
||||
/**
|
||||
* Renders the drive cell status indicators.
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class DriveLedTileEntityRenderer extends BlockEntityRenderer<DriveBlockEntity> {
|
||||
|
||||
private static final RenderState.TransparencyState TRANSLUCENT_TRANSPARENCY = new RenderState.TransparencyState(
|
||||
"translucent_transparency", () -> {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
}, () -> {
|
||||
RenderSystem.disableBlend();
|
||||
});
|
||||
|
||||
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.999f / 16.f; // front (z-axis)
|
||||
private static final float BA = 1.499f / 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 RenderLayer STATE = RenderLayer.makeType("ae_drive_leds", VertexFormats.POSITION_COLOR, 7,
|
||||
32565, false, true, RenderLayer.State.getBuilder().build(false));
|
||||
|
||||
public DriveLedTileEntityRenderer(BlockEntityRenderDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DriveBlockEntity drive, float partialTicks, MatrixStack ms, VertexConsumerProvider 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);
|
||||
|
||||
RenderType rt = RenderType.makeType("ae_drive_leds", VertexFormats.POSITION_COLOR, 7, 32565, false, true,
|
||||
RenderType.State.getBuilder().transparency(TRANSLUCENT_TRANSPARENCY).build(false));
|
||||
VertexConsumer 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 * 8 / 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.peek().getMatrix(), x, y, z).color(color.getX(), color.getY(), color.getZ(), 1.f)
|
||||
.endVertex();
|
||||
}
|
||||
|
||||
ms.pop();
|
||||
}
|
||||
}
|
||||
|
||||
ms.pop();
|
||||
|
||||
}
|
||||
|
||||
private Vector3f getColorForSlot(DriveBlockEntity drive, int slot, float partialTicks) {
|
||||
DriveSlotState state = DriveSlotState.fromCellStatus(drive.getCellStatus(slot));
|
||||
if (state == DriveSlotState.EMPTY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!drive.isPowered()) {
|
||||
return STATE_COLORS.get(DriveSlotState.OFFLINE);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
|
||||
package appeng.client.render.tesr;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.inventory.container.PlayerContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.recipes.handlers.InscriberRecipe;
|
||||
import appeng.tile.misc.InscriberBlockEntity;
|
||||
|
||||
/**
|
||||
* Renders the dynamic parts of an inscriber (the presses, the animation and the
|
||||
* item being smashed)
|
||||
*/
|
||||
public final class InscriberTESR extends BlockEntityRenderer<InscriberBlockEntity> {
|
||||
|
||||
private static final float ITEM_RENDER_SCALE = 1.0f / 1.2f;
|
||||
|
||||
private static final SpriteIdentifier TEXTURE_INSIDE = new SpriteIdentifier(PlayerContainer.LOCATION_BLOCKS_TEXTURE,
|
||||
new Identifier(AppEng.MOD_ID, "block/inscriber_inside"));
|
||||
|
||||
public InscriberTESR(BlockEntityRenderDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(InscriberBlockEntity tile, float partialTicks, MatrixStack ms, VertexConsumerProvider buffers,
|
||||
int combinedLight, int combinedOverlay) {
|
||||
|
||||
// render inscriber
|
||||
|
||||
ms.push();
|
||||
ms.translate(0.5F, 0.5F, 0.5F);
|
||||
FacingToRotation.get(tile.getForward(), tile.getUp()).push(ms);
|
||||
ms.translate(-0.5F, -0.5F, -0.5F);
|
||||
|
||||
// render sides of stamps
|
||||
|
||||
long absoluteProgress = 0;
|
||||
|
||||
if (tile.isSmash()) {
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
absoluteProgress = currentTime - tile.getClientStart();
|
||||
if (absoluteProgress > 800) {
|
||||
tile.setSmash(false);
|
||||
}
|
||||
}
|
||||
|
||||
final float relativeProgress = absoluteProgress % 800 / 400.0f;
|
||||
float progress = relativeProgress;
|
||||
|
||||
if (progress > 1.0f) {
|
||||
progress = 1.0f - (easeDecompressMotion(progress - 1.0f));
|
||||
} else {
|
||||
progress = easeCompressMotion(progress);
|
||||
}
|
||||
|
||||
float press = 0.2f;
|
||||
press -= progress / 5.0f;
|
||||
|
||||
float middle = 0.5f;
|
||||
middle += 0.02f;
|
||||
final float TwoPx = 2.0f / 16.0f;
|
||||
final float base = 0.4f;
|
||||
|
||||
final Sprite tas = TEXTURE_INSIDE.getSprite();
|
||||
|
||||
VertexConsumer buffer = buffers.getBuffer(RenderLayer.getSolid());
|
||||
|
||||
// Bottom of Top Stamp
|
||||
addVertex(buffer, ms, tas, TwoPx, middle + press, TwoPx, 2, 13, combinedOverlay, combinedLight, Direction.DOWN);
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle + press, TwoPx, 14, 13, combinedOverlay, combinedLight,
|
||||
Direction.DOWN);
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle + press, 1.0f - TwoPx, 14, 2, combinedOverlay, combinedLight,
|
||||
Direction.DOWN);
|
||||
addVertex(buffer, ms, tas, TwoPx, middle + press, 1.0f - TwoPx, 2, 2, combinedOverlay, combinedLight,
|
||||
Direction.DOWN);
|
||||
|
||||
// Front of Top Stamp
|
||||
addVertex(buffer, ms, tas, TwoPx, middle + base, TwoPx, 2, 3 - 16 * (press - base), combinedOverlay,
|
||||
combinedLight, Direction.NORTH);
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle + base, TwoPx, 14, 3 - 16 * (press - base), combinedOverlay,
|
||||
combinedLight, Direction.NORTH);
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle + press, TwoPx, 14, 3, combinedOverlay, combinedLight,
|
||||
Direction.NORTH);
|
||||
addVertex(buffer, ms, tas, TwoPx, middle + press, TwoPx, 2, 3, combinedOverlay, combinedLight, Direction.NORTH);
|
||||
|
||||
// Top of Bottom Stamp
|
||||
middle -= 2.0f * 0.02f;
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle - press, TwoPx, 2, 13, combinedOverlay, combinedLight,
|
||||
Direction.UP);
|
||||
addVertex(buffer, ms, tas, TwoPx, middle - press, TwoPx, 14, 13, combinedOverlay, combinedLight, Direction.UP);
|
||||
addVertex(buffer, ms, tas, TwoPx, middle - press, 1.0f - TwoPx, 14, 2, combinedOverlay, combinedLight,
|
||||
Direction.UP);
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle - press, 1.0f - TwoPx, 2, 2, combinedOverlay, combinedLight,
|
||||
Direction.UP);
|
||||
|
||||
// Front of Bottom Stamp
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle + -base, TwoPx, 2, 3 - 16 * (press - base), combinedOverlay,
|
||||
combinedLight, Direction.NORTH);
|
||||
addVertex(buffer, ms, tas, TwoPx, middle - base, TwoPx, 14, 3 - 16 * (press - base), combinedOverlay,
|
||||
combinedLight, Direction.NORTH);
|
||||
addVertex(buffer, ms, tas, TwoPx, middle - press, TwoPx, 14, 3, combinedOverlay, combinedLight,
|
||||
Direction.NORTH);
|
||||
addVertex(buffer, ms, tas, 1.0f - TwoPx, middle - press, TwoPx, 2, 3, combinedOverlay, combinedLight,
|
||||
Direction.NORTH);
|
||||
|
||||
// render items.
|
||||
|
||||
FixedItemInv tileInv = tile.getInternalInventory();
|
||||
|
||||
int items = 0;
|
||||
if (!tileInv.getInvStack(0).isEmpty()) {
|
||||
items++;
|
||||
}
|
||||
if (!tileInv.getInvStack(1).isEmpty()) {
|
||||
items++;
|
||||
}
|
||||
if (!tileInv.getInvStack(2).isEmpty()) {
|
||||
items++;
|
||||
}
|
||||
|
||||
boolean renderPresses;
|
||||
if (relativeProgress > 1.0f || items == 0) {
|
||||
// When crafting completes, dont render the presses (they mave have been
|
||||
// consumed, see below)
|
||||
renderPresses = false;
|
||||
|
||||
ItemStack is = tileInv.getInvStack(3);
|
||||
|
||||
if (is.isEmpty()) {
|
||||
final InscriberRecipe ir = tile.getTask();
|
||||
if (ir != null) {
|
||||
// The "PRESS" type will consume the presses so they should not render after
|
||||
// completing
|
||||
// the press animation
|
||||
renderPresses = ir.getProcessType() == InscriberProcessType.INSCRIBE;
|
||||
is = ir.getOutput().copy();
|
||||
}
|
||||
}
|
||||
this.renderItem(ms, is, 0.0f, buffers, combinedLight, combinedOverlay);
|
||||
} else {
|
||||
renderPresses = true;
|
||||
this.renderItem(ms, tileInv.getInvStack(2), 0.0f, buffers, combinedLight, combinedOverlay);
|
||||
}
|
||||
|
||||
if (renderPresses) {
|
||||
this.renderItem(ms, tileInv.getInvStack(0), press, buffers, combinedLight, combinedOverlay);
|
||||
this.renderItem(ms, tileInv.getInvStack(1), -press, buffers, combinedLight, combinedOverlay);
|
||||
}
|
||||
|
||||
ms.pop();
|
||||
}
|
||||
|
||||
private static void addVertex(VertexConsumer vb, MatrixStack ms, Sprite sprite, float x, float y,
|
||||
float z, double texU, double texV, int overlayUV, int lightmapUV, Direction front) {
|
||||
vb.pos(ms.peek().getMatrix(), x, y, z);
|
||||
vb.color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
vb.tex(sprite.getFrameU(texU), sprite.getFrameV(texV));
|
||||
vb.overlay(overlayUV);
|
||||
vb.lightmap(lightmapUV);
|
||||
vb.normal(ms.peek().getNormal(), front.getOffsetX(), front.getOffsetY(), front.getOffsetZ());
|
||||
vb.endVertex();
|
||||
}
|
||||
|
||||
private static final Identifier TAG_STORAGE_BLOCKS = new Identifier("forge:storage_blocks");
|
||||
|
||||
private void renderItem(MatrixStack ms, final ItemStack stack, final float o, VertexConsumerProvider buffers,
|
||||
int combinedLight, int combinedOverlay) {
|
||||
if (!stack.isEmpty()) {
|
||||
ms.push();
|
||||
// move to center
|
||||
ms.translate(0.5f, 0.5f + o, 0.5f);
|
||||
ms.multiply(new Quaternion(90, 0, 0, true));
|
||||
// set scale
|
||||
ms.scale(ITEM_RENDER_SCALE, ITEM_RENDER_SCALE, ITEM_RENDER_SCALE);
|
||||
|
||||
ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
|
||||
|
||||
// heuristic to scale items down much further than blocks
|
||||
if (!stack.getItem().getTags().contains(TAG_STORAGE_BLOCKS)) {
|
||||
ms.scale(0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
itemRenderer.renderItem(stack, ModelTransformation.Mode.FIXED, combinedLight, combinedOverlay, ms,
|
||||
buffers);
|
||||
ms.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTexture(TextureStitchEvent.Pre evt) {
|
||||
if (evt.getMap().getTextureLocation().equals(TEXTURE_INSIDE.getAtlasLocation())) {
|
||||
evt.addSprite(TEXTURE_INSIDE.getTextureLocation());
|
||||
}
|
||||
}
|
||||
|
||||
// See https://easings.net/#easeOutBack
|
||||
private static float easeCompressMotion(float x) {
|
||||
float c1 = 1.70158f;
|
||||
float c3 = c1 + 1;
|
||||
|
||||
return (float) (1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2));
|
||||
}
|
||||
|
||||
// See https://easings.net/#easeInQuint
|
||||
private static float easeDecompressMotion(float x) {
|
||||
return x * x * x * x * x;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.tesr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.client.render.renderable.Renderable;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModularTESR<T extends AEBaseBlockEntity> extends BlockEntityRenderer<T> {
|
||||
|
||||
private final List<Renderable<? super T>> renderables;
|
||||
|
||||
@SafeVarargs
|
||||
public ModularTESR(BlockEntityRenderDispatcher rendererDispatcherIn, Renderable<? super T>... renderables) {
|
||||
super(rendererDispatcherIn);
|
||||
this.renderables = ImmutableList.copyOf(renderables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(T te, float partialTicks, MatrixStack ms, VertexConsumerProvider buffers, int combinedLight,
|
||||
int combinedOverlay) {
|
||||
ms.push();
|
||||
ms.translate(0.5, 0.5, 0.5);
|
||||
FacingToRotation.get(te.getForward(), te.getUp()).push(ms);
|
||||
ms.translate(-0.5, -0.5, -0.5);
|
||||
for (Renderable<? super T> renderable : this.renderables) {
|
||||
renderable.renderTileEntityAt(te, partialTicks, ms, buffers, combinedLight, combinedOverlay);
|
||||
}
|
||||
ms.pop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.tesr;
|
||||
|
||||
import appeng.block.storage.SkyChestBlock;
|
||||
import appeng.block.storage.SkyChestBlock.SkyChestType;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.tile.storage.SkyChestBlockEntity;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
// This is mostly a copy&paste job of the vanilla chest TESR
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class SkyChestTESR extends BlockEntityRenderer<SkyChestBlockEntity> {
|
||||
|
||||
public static final SpriteIdentifier TEXTURE_STONE = new SpriteIdentifier(TexturedRenderLayers.CHEST_ATLAS_TEXTURE,
|
||||
new Identifier(AppEng.MOD_ID, "models/skychest"));
|
||||
public static final SpriteIdentifier TEXTURE_BLOCK = new SpriteIdentifier(TexturedRenderLayers.CHEST_ATLAS_TEXTURE,
|
||||
new Identifier(AppEng.MOD_ID, "models/skyblockchest"));
|
||||
|
||||
public static final ImmutableList<SpriteIdentifier> SPRITES = ImmutableList.of(
|
||||
TEXTURE_STONE,
|
||||
TEXTURE_BLOCK
|
||||
);
|
||||
|
||||
private final ModelPart singleLid;
|
||||
private final ModelPart singleBottom;
|
||||
private final ModelPart singleLatch;
|
||||
|
||||
public SkyChestTESR(BlockEntityRenderDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
|
||||
this.singleBottom = new ModelPart(64, 64, 0, 19);
|
||||
this.singleBottom.addCuboid(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F);
|
||||
this.singleLid = new ModelPart(64, 64, 0, 0);
|
||||
this.singleLid.addCuboid(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.singleLid.pivotY = 9.0F;
|
||||
this.singleLid.pivotZ = 1.0F;
|
||||
this.singleLatch = new ModelPart(64, 64, 0, 0);
|
||||
this.singleLatch.addCuboid(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.singleLatch.pivotY = 8.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SkyChestBlockEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn,
|
||||
VertexConsumerProvider bufferIn, int combinedLightIn, int combinedOverlayIn) {
|
||||
matrixStackIn.push();
|
||||
float f = tileEntityIn.getForward().asRotation();
|
||||
matrixStackIn.translate(0.5D, 0.5D, 0.5D);
|
||||
matrixStackIn.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-f));
|
||||
matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
|
||||
|
||||
float f1 = tileEntityIn.getAnimationProgress(partialTicks);
|
||||
f1 = 1.0F - f1;
|
||||
f1 = 1.0F - f1 * f1 * f1;
|
||||
SpriteIdentifier material = this.getMaterial(tileEntityIn);
|
||||
VertexConsumer ivertexbuilder = material.getVertexConsumer(bufferIn, RenderLayer::getEntityCutout);
|
||||
this.renderModels(matrixStackIn, ivertexbuilder, this.singleLid, this.singleLatch, this.singleBottom, f1,
|
||||
combinedLightIn, combinedOverlayIn);
|
||||
|
||||
matrixStackIn.pop();
|
||||
}
|
||||
|
||||
// See ChestBlockEntityRenderer
|
||||
private void renderModels(MatrixStack matrixStackIn, VertexConsumer bufferIn, ModelPart chestLid,
|
||||
ModelPart chestLatch, ModelPart chestBottom, float lidAngle, int combinedLightIn,
|
||||
int combinedOverlayIn) {
|
||||
chestLid.pitch = -(lidAngle * 1.5707964F);
|
||||
chestLatch.pitch = chestLid.pitch;
|
||||
chestLid.render(matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
|
||||
chestLatch.render(matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
|
||||
chestBottom.render(matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
|
||||
}
|
||||
|
||||
protected SpriteIdentifier getMaterial(SkyChestBlockEntity tileEntity) {
|
||||
SkyChestType type = SkyChestType.BLOCK;
|
||||
if (tileEntity.getWorld() != null) {
|
||||
Block blockType = tileEntity.getCachedState().getBlock();
|
||||
|
||||
if (blockType instanceof SkyChestBlock) {
|
||||
type = ((SkyChestBlock) blockType).type;
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case STONE:
|
||||
return TEXTURE_STONE;
|
||||
default:
|
||||
case BLOCK:
|
||||
return TEXTURE_BLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.tesr;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.tile.misc.SkyCompassBlockEntity;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class SkyCompassTESR extends BlockEntityRenderer<SkyCompassBlockEntity> {
|
||||
|
||||
private static BlockRenderManager blockRenderer;
|
||||
|
||||
public SkyCompassTESR(BlockEntityRenderDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SkyCompassBlockEntity te, float partialTicks, MatrixStack ms, VertexConsumerProvider buffers,
|
||||
int combinedLightIn, int combinedOverlayIn) {
|
||||
|
||||
if (blockRenderer == null) {
|
||||
blockRenderer = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
}
|
||||
|
||||
VertexConsumer buffer = buffers.getBuffer(TexturedRenderLayers.getEntityTranslucentCull());
|
||||
|
||||
BlockState blockState = te.getCachedState();
|
||||
BakedModel model = blockRenderer.getModels().getModel(blockState);
|
||||
|
||||
// FIXME: Rotation was previously handled by an auto rotating model I think, but
|
||||
// FIXME: Should be handled using matrices instead
|
||||
Direction forward = te.getForward();
|
||||
Direction up = te.getUp();
|
||||
// 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;
|
||||
}
|
||||
// Flip forward/up for rendering, the base model is facing up without any
|
||||
// rotation
|
||||
ms.push();
|
||||
ms.translate(0.5D, 0.5D, 0.5D);
|
||||
FacingToRotation.get(up, forward).push(ms);
|
||||
ms.translate(-0.5D, -0.5D, -0.5D);
|
||||
|
||||
// FIXME FABRIC ModelDataMap modelData = new ModelDataMap.Builder().withInitial(SkyCompassBakedModel.ROTATION, getRotation(te)).build();
|
||||
|
||||
blockRenderer.getModelRenderer().render(ms.peek(), buffer, null, model, 1, 1, 1, combinedLightIn,
|
||||
combinedOverlayIn);
|
||||
ms.pop();
|
||||
|
||||
}
|
||||
|
||||
// FIXME FABRIC This needs to go to the tile entity (?)
|
||||
private static float getRotation(SkyCompassBlockEntity skyCompass) {
|
||||
float rotation = 0;
|
||||
|
||||
if (skyCompass.getForward() == Direction.UP || skyCompass.getForward() == Direction.DOWN) {
|
||||
// FIXME FABRIC rotation = SkyCompassBakedModel.getAnimatedRotation(skyCompass.getPos(), false);
|
||||
} else {
|
||||
// FIXME FABRIC rotation = SkyCompassBakedModel.getAnimatedRotation(null, false);
|
||||
}
|
||||
|
||||
if (skyCompass.getForward() == Direction.DOWN) {
|
||||
// FIXME FABRIC rotation = flipidiy(rotation);
|
||||
}
|
||||
|
||||
return rotation;
|
||||
}
|
||||
|
||||
private static float flipidiy(float rad) {
|
||||
float x = (float) Math.cos(rad);
|
||||
float y = (float) Math.sin(rad);
|
||||
return (float) Math.atan2(-y, x);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user