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 );
+3
View File
@@ -23,6 +23,8 @@ import java.io.File;
import appeng.bootstrap.components.IClientSetupComponent;
import appeng.client.ClientHelper;
import appeng.client.render.model.AutoRotatingModel;
import appeng.client.render.model.AutoRotatingModelLoader;
import appeng.client.render.model.GlassModelLoader;
import appeng.client.render.model.SkyCompassModelLoader;
import appeng.core.stats.AdvancementTriggers;
@@ -128,6 +130,7 @@ public final class AppEng
definitions.getRegistry().getBootstrapComponents( IClientSetupComponent.class ).forEachRemaining(IClientSetupComponent::setup);
ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "glass"), GlassModelLoader.INSTANCE);
ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "sky_compass"), SkyCompassModelLoader.INSTANCE);
ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "auto_rotating"), AutoRotatingModelLoader.INSTANCE);
}
@Nonnull
@@ -24,7 +24,9 @@ import java.util.EnumSet;
import appeng.core.Api;
import appeng.core.worlddata.WorldData;
import appeng.hooks.TickHandler;
import appeng.me.cache.P2PCache;
import appeng.parts.networking.PartCable;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.PlayerEntity;
@@ -104,8 +106,7 @@ public class AENetworkProxy implements IGridBlock
{
if( this.gp instanceof AEBaseTile )
{
throw new IllegalStateException(); // FIXME just here to remember for sure
// FIXME TickHandler.INSTANCE.addInit( (AEBaseTile) this.gp );
TickHandler.INSTANCE.addInit( (AEBaseTile) this.gp );
}
}
@@ -328,10 +329,10 @@ public class AENetworkProxy implements IGridBlock
@Override
public void onGridNotification( final GridNotification notification )
{
// FIXME if( this.gp instanceof PartCable )
// FIXME {
// FIXME ( (PartCable) this.gp ).markForUpdate();
// FIXME }
if( this.gp instanceof PartCable)
{
( (PartCable) this.gp ).markForUpdate();
}
}
@Override
-1
View File
@@ -78,7 +78,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.*;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;