Working on Inscriber TESR

This commit is contained in:
Sebastian Hartte
2020-06-05 00:58:11 +02:00
parent 51e82587c7
commit d0b8a5f33f
10 changed files with 207 additions and 139 deletions
@@ -26,13 +26,14 @@ import net.minecraft.client.renderer.Quaternion;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.Vector4f;
import net.minecraft.util.Direction;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.Vec3i;
/**
* TODO: Removed useless stuff.
*/
public enum FacingToRotation
public enum FacingToRotation implements IStringSerializable
{
// DUNSWE
@@ -137,4 +138,9 @@ public enum FacingToRotation
{
return values()[forward.ordinal() * 6 + up.ordinal()];
}
@Override
public String getName() {
return name().toLowerCase();
}
}
@@ -0,0 +1,140 @@
/*
* 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 java.util.Random;
import appeng.client.render.cablebus.QuadRotator;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.Direction;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.FacingToRotation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class AutoRotatingBakedModel implements IBakedModel
{
private final IBakedModel parent;
private final LoadingCache<AutoRotatingCacheKey, List<BakedQuad>> quadCache;
public AutoRotatingBakedModel(IBakedModel 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 ) throws Exception
{
return AutoRotatingBakedModel.this.getRotatedModel( key.getBlockState(), key.getSide(), key.getForward(), key.getUp() );
}
} );
}
private List<BakedQuad> getRotatedModel( BlockState state, Direction side, Direction forward, Direction up )
{
FacingToRotation f2r = FacingToRotation.get( forward, up );
List<BakedQuad> original = AutoRotatingBakedModel.this.parent.getQuads( state, f2r.resultingRotate( side ), new Random(0), EmptyModelData.INSTANCE );
return new QuadRotator().rotateQuads(original, forward, up);
}
@Override
public boolean isAmbientOcclusion()
{
return this.parent.isAmbientOcclusion();
}
@Override
public boolean isGui3d()
{
return this.parent.isGui3d();
}
@Override
public boolean func_230044_c_() {
return parent.func_230044_c_();
}
@Override
public boolean isBuiltInRenderer()
{
return this.parent.isBuiltInRenderer();
}
@Override
public TextureAtlasSprite getParticleTexture()
{
return this.parent.getParticleTexture();
}
@Override
@Deprecated
public ItemCameraTransforms getItemCameraTransforms() {
return parent.getItemCameraTransforms();
}
@Override
public ItemOverrideList 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) {
Direction forward = extraData.getData(AEBaseTileBlock.FORWARD);
Direction up = extraData.getData(AEBaseTileBlock.UP);
if( forward == null || up == null )
{
return this.parent.getQuads( state, side, rand );
}
// The model has other properties than just forward/up, so it would cause our cache to inadvertendly also cache
// these
// additional states, possibly leading to huge issues if the other extended state properties do not implement
// equals/hashCode correctly
// FIXME: IModelData does not expose a way for us to check if it only has the two properties and no other
return this.getRotatedModel( state, side, forward, up );
}
}
@@ -1,140 +1,34 @@
/*
* 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 java.util.Random;
import appeng.client.render.cablebus.QuadRotator;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.model.ItemOverrideList;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.Direction;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelConfiguration;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.FacingToRotation;
import java.util.Collection;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class AutoRotatingModel implements IModelGeometry<AutoRotatingModel> {
private final BlockModel blockModel;
public class AutoRotatingModel implements IBakedModel
{
public AutoRotatingModel(BlockModel blockModel) {
this.blockModel = blockModel;
}
private final IBakedModel parent;
private final LoadingCache<AutoRotatingCacheKey, List<BakedQuad>> quadCache;
@Override
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) {
return new AutoRotatingBakedModel(
this.blockModel.bakeModel(bakery, this.blockModel, spriteGetter, modelTransform, modelLocation, true)
);
}
public AutoRotatingModel( IBakedModel 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 ) throws Exception
{
return AutoRotatingModel.this.getRotatedModel( key.getBlockState(), key.getSide(), key.getForward(), key.getUp() );
}
} );
}
private List<BakedQuad> getRotatedModel( BlockState state, Direction side, Direction forward, Direction up )
{
FacingToRotation f2r = FacingToRotation.get( forward, up );
List<BakedQuad> original = AutoRotatingModel.this.parent.getQuads( state, f2r.resultingRotate( side ), new Random(0), EmptyModelData.INSTANCE );
return new QuadRotator().rotateQuads(original, forward, up);
}
@Override
public boolean isAmbientOcclusion()
{
return this.parent.isAmbientOcclusion();
}
@Override
public boolean isGui3d()
{
return this.parent.isGui3d();
}
@Override
public boolean func_230044_c_() {
return parent.func_230044_c_();
}
@Override
public boolean isBuiltInRenderer()
{
return this.parent.isBuiltInRenderer();
}
@Override
public TextureAtlasSprite getParticleTexture()
{
return this.parent.getParticleTexture();
}
@Override
@Deprecated
public ItemCameraTransforms getItemCameraTransforms() {
return parent.getItemCameraTransforms();
}
@Override
public ItemOverrideList 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) {
Direction forward = extraData.getData(AEBaseTileBlock.FORWARD);
Direction up = extraData.getData(AEBaseTileBlock.UP);
if( forward == null || up == null )
{
return this.parent.getQuads( state, side, rand );
}
// The model has other properties than just forward/up, so it would cause our cache to inadvertendly also cache
// these
// additional states, possibly leading to huge issues if the other extended state properties do not implement
// equals/hashCode correctly
// FIXME: IModelData does not expose a way for us to check if it only has the two properties and no other
return this.getRotatedModel( state, side, forward, up );
}
@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
return this.blockModel.getTextures(modelGetter, missingTextureErrors);
}
}
@@ -0,0 +1,24 @@
package appeng.client.render.model;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.client.renderer.model.BlockModel;
import net.minecraft.resources.IResourceManager;
import net.minecraftforge.client.model.IModelLoader;
public class AutoRotatingModelLoader implements IModelLoader<AutoRotatingModel> {
public static final AutoRotatingModelLoader INSTANCE = new AutoRotatingModelLoader();
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
}
@Override
public AutoRotatingModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
modelContents.remove("loader");
BlockModel blockModel = deserializationContext.deserialize(modelContents, BlockModel.class);
return new AutoRotatingModel(blockModel);
}
}
@@ -127,8 +127,6 @@ public final class InscriberTESR extends TileEntityRenderer<TileInscriber>
buffer.pos( 1.0 - TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 ) ).endVertex();
}
Tessellator.getInstance().draw();
// render items.
// FIXME RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );