P2P tunnel frequency color indicators (#3610)
This commit is contained in:
@@ -355,4 +355,14 @@ public interface IPart extends IBoxProvider, ICustomCableConnection
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag to be passed to the renderer.
|
||||||
|
*
|
||||||
|
* @return flag or null
|
||||||
|
*/
|
||||||
|
default Long getRenderFlag()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
package appeng.api.parts;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IPartBakedModel
|
||||||
|
{
|
||||||
|
List<BakedQuad> getPartQuads( @Nullable Long partFlags, long rand );
|
||||||
|
}
|
||||||
@@ -44,6 +44,7 @@ import net.minecraft.util.ResourceLocation;
|
|||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||||
|
|
||||||
|
import appeng.api.parts.IPartBakedModel;
|
||||||
import appeng.api.parts.IPartModel;
|
import appeng.api.parts.IPartModel;
|
||||||
import appeng.api.util.AECableType;
|
import appeng.api.util.AECableType;
|
||||||
import appeng.api.util.AEColor;
|
import appeng.api.util.AEColor;
|
||||||
@@ -119,7 +120,15 @@ public class CableBusBakedModel implements IBakedModel
|
|||||||
throw new IllegalStateException( "Trying to use an unregistered part model: " + model );
|
throw new IllegalStateException( "Trying to use an unregistered part model: " + model );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BakedQuad> partQuads = bakedModel.getQuads( state, null, rand );
|
List<BakedQuad> partQuads;
|
||||||
|
if( bakedModel instanceof IPartBakedModel )
|
||||||
|
{
|
||||||
|
partQuads = ( (IPartBakedModel) bakedModel ).getPartQuads( renderState.getPartFlags().get( facing ), rand );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
partQuads = bakedModel.getQuads( state, null, rand );
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate quads accordingly
|
// Rotate quads accordingly
|
||||||
QuadRotator rotator = new QuadRotator();
|
QuadRotator rotator = new QuadRotator();
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public class CableBusRenderState
|
|||||||
// facades on this cable bus
|
// facades on this cable bus
|
||||||
private List<AxisAlignedBB> boundingBoxes = new ArrayList<>();
|
private List<AxisAlignedBB> boundingBoxes = new ArrayList<>();
|
||||||
|
|
||||||
|
private EnumMap<EnumFacing, Long> partFlags = new EnumMap<>( EnumFacing.class );
|
||||||
|
|
||||||
public CableCoreType getCoreType()
|
public CableCoreType getCoreType()
|
||||||
{
|
{
|
||||||
return this.coreType;
|
return this.coreType;
|
||||||
@@ -154,6 +156,11 @@ public class CableBusRenderState
|
|||||||
return this.boundingBoxes;
|
return this.boundingBoxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EnumMap<EnumFacing, Long> getPartFlags()
|
||||||
|
{
|
||||||
|
return this.partFlags;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
@@ -166,6 +173,7 @@ public class CableBusRenderState
|
|||||||
result = prime * result + ( ( this.channelsOnSide == null ) ? 0 : this.channelsOnSide.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.connectionTypes == null ) ? 0 : this.connectionTypes.hashCode() );
|
||||||
result = prime * result + ( ( this.coreType == null ) ? 0 : this.coreType.hashCode() );
|
result = prime * result + ( ( this.coreType == null ) ? 0 : this.coreType.hashCode() );
|
||||||
|
result = prime * result + ( ( this.partFlags == null ) ? 0 : this.partFlags.hashCode() );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +198,7 @@ public class CableBusRenderState
|
|||||||
return this.cableColor == other.cableColor && this.cableType == other.cableType && this.coreType == other.coreType && Objects
|
return this.cableColor == other.cableColor && this.cableType == other.cableType && this.coreType == other.coreType && Objects
|
||||||
.equals( this.attachmentConnections, other.attachmentConnections ) && Objects.equals( this.cableBusAdjacent,
|
.equals( this.attachmentConnections, other.attachmentConnections ) && Objects.equals( this.cableBusAdjacent,
|
||||||
other.cableBusAdjacent ) && Objects.equals( this.channelsOnSide, other.channelsOnSide ) && Objects.equals( this.connectionTypes,
|
other.cableBusAdjacent ) && Objects.equals( this.channelsOnSide, other.channelsOnSide ) && Objects.equals( this.connectionTypes,
|
||||||
other.connectionTypes );
|
other.connectionTypes ) && Objects.equals( this.partFlags, other.partFlags );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
|
||||||
|
package appeng.client.render.cablebus;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
import appeng.api.parts.IPartBakedModel;
|
||||||
|
import appeng.api.util.AEColor;
|
||||||
|
import appeng.util.Platform;
|
||||||
|
|
||||||
|
|
||||||
|
public class P2PTunnelFrequencyBakedModel implements IBakedModel, IPartBakedModel
|
||||||
|
{
|
||||||
|
private final VertexFormat format;
|
||||||
|
private final TextureAtlasSprite 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 VertexFormat format, final TextureAtlasSprite texture )
|
||||||
|
{
|
||||||
|
this.format = format;
|
||||||
|
this.texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BakedQuad> getPartQuads( Long partFlags, long rand )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return modelCache.get( partFlags, () ->
|
||||||
|
{
|
||||||
|
short frequency = 0;
|
||||||
|
boolean active = false;
|
||||||
|
if( partFlags != null )
|
||||||
|
{
|
||||||
|
frequency = (short) ( partFlags.longValue() & 0xffffL );
|
||||||
|
active = ( partFlags.longValue() & 0x10000L ) != 0;
|
||||||
|
}
|
||||||
|
return getQuadsForFrequency( frequency, active );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
catch( ExecutionException e )
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
||||||
|
{
|
||||||
|
if( side != null )
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return getPartQuads( null, rand );
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<BakedQuad> getQuadsForFrequency( final short frequency, final boolean active )
|
||||||
|
{
|
||||||
|
final AEColor[] colors = Platform.p2p().toColors( frequency );
|
||||||
|
final CubeBuilder cb = new CubeBuilder( this.format );
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAmbientOcclusion()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGui3d()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBuiltInRenderer()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TextureAtlasSprite getParticleTexture()
|
||||||
|
{
|
||||||
|
return this.texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemOverrideList getOverrides()
|
||||||
|
{
|
||||||
|
return ItemOverrideList.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
package appeng.client.render.cablebus;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.client.model.IModel;
|
||||||
|
import net.minecraftforge.common.model.IModelState;
|
||||||
|
|
||||||
|
import appeng.core.AppEng;
|
||||||
|
|
||||||
|
|
||||||
|
public class P2PTunnelFrequencyModel implements IModel
|
||||||
|
{
|
||||||
|
private static final ResourceLocation TEXTURE = new ResourceLocation( AppEng.MOD_ID, "parts/p2p_tunnel_frequency" );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ResourceLocation> getTextures()
|
||||||
|
{
|
||||||
|
return Collections.singletonList( TEXTURE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final TextureAtlasSprite texture = bakedTextureGetter.apply( TEXTURE );
|
||||||
|
return new P2PTunnelFrequencyBakedModel( format, texture );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
throw new RuntimeException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ import appeng.api.util.AEColor;
|
|||||||
import appeng.bootstrap.IItemRendering;
|
import appeng.bootstrap.IItemRendering;
|
||||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||||
import appeng.client.render.StaticItemColor;
|
import appeng.client.render.StaticItemColor;
|
||||||
|
import appeng.client.render.cablebus.P2PTunnelFrequencyModel;
|
||||||
import appeng.core.AppEng;
|
import appeng.core.AppEng;
|
||||||
import appeng.core.features.registries.PartModels;
|
import appeng.core.features.registries.PartModels;
|
||||||
import appeng.parts.automation.PlaneConnections;
|
import appeng.parts.automation.PlaneConnections;
|
||||||
@@ -128,6 +129,9 @@ public class ItemPartRendering extends ItemRenderingCustomizer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// base p2p model with frequency
|
||||||
|
rendering.builtInModel( "models/part/builtin/p2p_tunnel_frequency", new P2PTunnelFrequencyModel() );
|
||||||
|
|
||||||
List<ResourceLocation> partResourceLocs = modelNames.stream()
|
List<ResourceLocation> partResourceLocs = modelNames.stream()
|
||||||
.map( name -> new ResourceLocation( AppEng.MOD_ID, name ) )
|
.map( name -> new ResourceLocation( AppEng.MOD_ID, name ) )
|
||||||
.collect( Collectors.toList() );
|
.collect( Collectors.toList() );
|
||||||
|
|||||||
@@ -1247,6 +1247,8 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderState.getPartFlags().put( facing, part.getRenderFlag() );
|
||||||
|
|
||||||
// This will add the part's bounding boxes to the render state, which is required for facades
|
// This will add the part's bounding boxes to the render state, which is required for facades
|
||||||
final AEPartLocation loc = AEPartLocation.fromFacing( facing );
|
final AEPartLocation loc = AEPartLocation.fromFacing( facing );
|
||||||
final IPartCollisionHelper bch = new BusCollisionHelper( renderState.getBoundingBoxes(), loc, null, true );
|
final IPartCollisionHelper bch = new BusCollisionHelper( renderState.getBoundingBoxes(), loc, null, true );
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class P2PModels
|
|||||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_off" );
|
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_off" );
|
||||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_on" );
|
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_on" );
|
||||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_has_channel" );
|
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_has_channel" );
|
||||||
|
public static final ResourceLocation MODEL_FREQUENCY = new ResourceLocation( AppEng.MOD_ID, "part/builtin/p2p_tunnel_frequency" );
|
||||||
|
|
||||||
private final IPartModel modelsOff;
|
private final IPartModel modelsOff;
|
||||||
private final IPartModel modelsOn;
|
private final IPartModel modelsOn;
|
||||||
@@ -46,9 +47,10 @@ class P2PModels
|
|||||||
public P2PModels( String frontModelPath )
|
public P2PModels( String frontModelPath )
|
||||||
{
|
{
|
||||||
ResourceLocation frontModel = new ResourceLocation( AppEng.MOD_ID, frontModelPath );
|
ResourceLocation frontModel = new ResourceLocation( AppEng.MOD_ID, frontModelPath );
|
||||||
this.modelsOff = new PartModel( MODEL_STATUS_OFF, frontModel );
|
|
||||||
this.modelsOn = new PartModel( MODEL_STATUS_ON, frontModel );
|
this.modelsOff = new PartModel( MODEL_STATUS_OFF, MODEL_FREQUENCY, frontModel );
|
||||||
this.modelsHasChannel = new PartModel( MODEL_STATUS_HAS_CHANNEL, frontModel );
|
this.modelsOn = new PartModel( MODEL_STATUS_ON, MODEL_FREQUENCY, frontModel );
|
||||||
|
this.modelsHasChannel = new PartModel( MODEL_STATUS_HAS_CHANNEL, MODEL_FREQUENCY, frontModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPartModel getModel( boolean hasPower, boolean hasChannel )
|
public IPartModel getModel( boolean hasPower, boolean hasChannel )
|
||||||
|
|||||||
@@ -19,10 +19,13 @@
|
|||||||
package appeng.parts.p2p;
|
package appeng.parts.p2p;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -134,7 +137,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
|||||||
{
|
{
|
||||||
super.readFromNBT( data );
|
super.readFromNBT( data );
|
||||||
this.setOutput( data.getBoolean( "output" ) );
|
this.setOutput( data.getBoolean( "output" ) );
|
||||||
this.setFrequency( data.getShort( "freq" ) );
|
this.freq = data.getShort( "freq" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,6 +148,22 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
|||||||
data.setShort( "freq", this.getFrequency() );
|
data.setShort( "freq", this.getFrequency() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean readFromStream( ByteBuf data ) throws IOException
|
||||||
|
{
|
||||||
|
final boolean c = super.readFromStream( data );
|
||||||
|
final short oldf = this.freq;
|
||||||
|
this.freq = data.readShort();
|
||||||
|
return c || oldf != this.freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToStream( ByteBuf data ) throws IOException
|
||||||
|
{
|
||||||
|
super.writeToStream( data );
|
||||||
|
data.writeShort( getFrequency() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getCableConnectionLength( AECableType cable )
|
public float getCableConnectionLength( AECableType cable )
|
||||||
{
|
{
|
||||||
@@ -381,7 +400,12 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
|||||||
|
|
||||||
public void setFrequency( final short freq )
|
public void setFrequency( final short freq )
|
||||||
{
|
{
|
||||||
|
final short oldf = this.freq;
|
||||||
this.freq = freq;
|
this.freq = freq;
|
||||||
|
if( oldf != this.freq )
|
||||||
|
{
|
||||||
|
this.getHost().markForUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOutput()
|
public boolean isOutput()
|
||||||
@@ -393,4 +417,17 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
|
|||||||
{
|
{
|
||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getRenderFlag()
|
||||||
|
{
|
||||||
|
long ret = Short.toUnsignedLong( this.getFrequency() );
|
||||||
|
|
||||||
|
if( this.isActive() && this.isPowered() )
|
||||||
|
{
|
||||||
|
ret |= 0x10000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+865
-48
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
Reference in New Issue
Block a user