Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
@@ -0,0 +1,80 @@
/*
* 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,116 @@
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;
}
}
@@ -0,0 +1,46 @@
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);
}
}
@@ -0,0 +1,21 @@
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;
}
}