mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-10 11:59:59 +00:00
Improve turtles by 200%
Every other mod has some fun feature, so should we. And yes, this was worth the 400 lines it took to implement.
This commit is contained in:
parent
ce7923d248
commit
35da60543e
@ -9,7 +9,6 @@ package dan200.computercraft.client.render;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera;
|
||||
import dan200.computercraft.shared.util.Holiday;
|
||||
@ -129,18 +128,22 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
||||
GlStateManager.translate( posX + offset.x, posY + offset.y, posZ + offset.z );
|
||||
|
||||
// Render the label
|
||||
IComputer computer = (turtle != null) ? turtle.getComputer() : null;
|
||||
String label = (computer != null) ? computer.getLabel() : null;
|
||||
String label = turtle.getLabel();
|
||||
if( label != null )
|
||||
{
|
||||
renderLabel( turtle.getAccess().getPosition(), label );
|
||||
}
|
||||
|
||||
// Render the turtle
|
||||
GlStateManager.translate( 0.5f, 0.0f, 0.5f );
|
||||
GlStateManager.translate( 0.5f, 0.5f, 0.5f );
|
||||
GlStateManager.rotate( 180.0f - yaw, 0.0f, 1.0f, 0.0f );
|
||||
GlStateManager.translate( -0.5f, 0.0f, -0.5f );
|
||||
|
||||
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
||||
{
|
||||
// Flip the model and swap the cull face as winding order will have changed.
|
||||
GlStateManager.scale( 1.0f, -1.0f, 1.0f );
|
||||
GlStateManager.cullFace( GlStateManager.CullFace.FRONT );
|
||||
}
|
||||
GlStateManager.translate( -0.5f, -0.5f, -0.5f );
|
||||
// Render the turtle
|
||||
int colour;
|
||||
ComputerFamily family;
|
||||
@ -192,6 +195,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
||||
finally
|
||||
{
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.cullFace( GlStateManager.CullFace.BACK );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,17 @@ import java.util.Map;
|
||||
|
||||
public class TurtleMultiModel implements IBakedModel
|
||||
{
|
||||
private IBakedModel m_baseModel;
|
||||
private IBakedModel m_overlayModel;
|
||||
private IBakedModel m_leftUpgradeModel;
|
||||
private Matrix4f m_leftUpgradeTransform;
|
||||
private IBakedModel m_rightUpgradeModel;
|
||||
private Matrix4f m_rightUpgradeTransform;
|
||||
private final IBakedModel m_baseModel;
|
||||
private final IBakedModel m_overlayModel;
|
||||
private final Matrix4f m_generalTransform;
|
||||
private final IBakedModel m_leftUpgradeModel;
|
||||
private final Matrix4f m_leftUpgradeTransform;
|
||||
private final IBakedModel m_rightUpgradeModel;
|
||||
private final Matrix4f m_rightUpgradeTransform;
|
||||
private List<BakedQuad> m_generalQuads;
|
||||
private Map<EnumFacing, List<BakedQuad>> m_faceQuads;
|
||||
|
||||
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform )
|
||||
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, Matrix4f generalTransform, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform )
|
||||
{
|
||||
// Get the models
|
||||
m_baseModel = baseModel;
|
||||
@ -35,6 +36,7 @@ public class TurtleMultiModel implements IBakedModel
|
||||
m_leftUpgradeTransform = leftUpgradeTransform;
|
||||
m_rightUpgradeModel = rightUpgradeModel;
|
||||
m_rightUpgradeTransform = rightUpgradeTransform;
|
||||
m_generalTransform = generalTransform;
|
||||
m_generalQuads = null;
|
||||
m_faceQuads = new HashMap<>();
|
||||
}
|
||||
@ -58,18 +60,34 @@ public class TurtleMultiModel implements IBakedModel
|
||||
private List<BakedQuad> buildQuads( IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
ArrayList<BakedQuad> quads = new ArrayList<>();
|
||||
quads.addAll( m_baseModel.getQuads( state, side, rand ) );
|
||||
ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand ), m_generalTransform );
|
||||
if( m_overlayModel != null )
|
||||
{
|
||||
quads.addAll( m_overlayModel.getQuads( state, side, rand ) );
|
||||
ModelTransformer.transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand ), m_generalTransform );
|
||||
}
|
||||
if( m_overlayModel != null )
|
||||
{
|
||||
ModelTransformer.transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand ), m_generalTransform );
|
||||
}
|
||||
if( m_leftUpgradeModel != null )
|
||||
{
|
||||
ModelTransformer.transformQuadsTo( quads, m_leftUpgradeModel.getQuads( state, side, rand ), m_leftUpgradeTransform );
|
||||
Matrix4f upgradeTransform = m_generalTransform;
|
||||
if( m_leftUpgradeTransform != null )
|
||||
{
|
||||
upgradeTransform = new Matrix4f( m_generalTransform );
|
||||
upgradeTransform.mul( m_leftUpgradeTransform );
|
||||
}
|
||||
ModelTransformer.transformQuadsTo( quads, m_leftUpgradeModel.getQuads( state, side, rand ), upgradeTransform );
|
||||
}
|
||||
if( m_rightUpgradeModel != null )
|
||||
{
|
||||
ModelTransformer.transformQuadsTo( quads, m_rightUpgradeModel.getQuads( state, side, rand ), m_rightUpgradeTransform );
|
||||
Matrix4f upgradeTransform = m_generalTransform;
|
||||
if( m_rightUpgradeTransform != null )
|
||||
{
|
||||
upgradeTransform = new Matrix4f( m_generalTransform );
|
||||
upgradeTransform.mul( m_rightUpgradeTransform );
|
||||
}
|
||||
ModelTransformer.transformQuadsTo( quads, m_rightUpgradeModel.getQuads( state, side, rand ), upgradeTransform );
|
||||
}
|
||||
quads.trimToSize();
|
||||
return quads;
|
||||
|
@ -35,6 +35,19 @@ import java.util.List;
|
||||
|
||||
public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReloadListener
|
||||
{
|
||||
private static final Matrix4f s_identity, s_flip;
|
||||
|
||||
static
|
||||
{
|
||||
s_identity = new Matrix4f();
|
||||
s_identity.setIdentity();
|
||||
|
||||
s_flip = new Matrix4f();
|
||||
s_flip.setIdentity();
|
||||
s_flip.m11 = -1; // Flip on the y axis
|
||||
s_flip.m13 = 1; // Models go from (0,0,0) to (1,1,1), so push back up.
|
||||
}
|
||||
|
||||
private static class TurtleModelCombination
|
||||
{
|
||||
public final ComputerFamily m_family;
|
||||
@ -43,8 +56,9 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
|
||||
public final ITurtleUpgrade m_rightUpgrade;
|
||||
public final ResourceLocation m_overlay;
|
||||
public final boolean m_christmas;
|
||||
public final boolean m_flip;
|
||||
|
||||
public TurtleModelCombination( ComputerFamily family, boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas )
|
||||
public TurtleModelCombination( ComputerFamily family, boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas, boolean flip )
|
||||
{
|
||||
m_family = family;
|
||||
m_colour = colour;
|
||||
@ -52,22 +66,26 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
|
||||
m_rightUpgrade = rightUpgrade;
|
||||
m_overlay = overlay;
|
||||
m_christmas = christmas;
|
||||
m_flip = flip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object other )
|
||||
{
|
||||
if( other == this ) {
|
||||
if( other == this )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( other instanceof TurtleModelCombination ) {
|
||||
TurtleModelCombination otherCombo = (TurtleModelCombination)other;
|
||||
if( other instanceof TurtleModelCombination )
|
||||
{
|
||||
TurtleModelCombination otherCombo = (TurtleModelCombination) other;
|
||||
if( otherCombo.m_family == m_family &&
|
||||
otherCombo.m_colour == m_colour &&
|
||||
otherCombo.m_leftUpgrade == m_leftUpgrade &&
|
||||
otherCombo.m_rightUpgrade == m_rightUpgrade &&
|
||||
Objects.equal( otherCombo.m_overlay, m_overlay ) &&
|
||||
otherCombo.m_christmas == m_christmas )
|
||||
otherCombo.m_christmas == m_christmas &&
|
||||
otherCombo.m_flip == m_flip )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -86,10 +104,11 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
|
||||
result = prime * result + (m_rightUpgrade != null ? m_rightUpgrade.hashCode() : 0);
|
||||
result = prime * result + (m_overlay != null ? m_overlay.hashCode() : 0);
|
||||
result = prime * result + (m_christmas ? 1 : 0);
|
||||
result = prime * result + (m_flip ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private HashMap<TurtleModelCombination, IBakedModel> m_cachedModels;
|
||||
private ItemOverrideList m_overrides;
|
||||
private final TurtleModelCombination m_defaultCombination;
|
||||
@ -97,12 +116,12 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
|
||||
public TurtleSmartItemModel()
|
||||
{
|
||||
m_cachedModels = new HashMap<>();
|
||||
m_defaultCombination = new TurtleModelCombination( ComputerFamily.Normal, false, null, null, null, false );
|
||||
m_defaultCombination = new TurtleModelCombination( ComputerFamily.Normal, false, null, null, null, false, false );
|
||||
m_overrides = new ItemOverrideList( new ArrayList<>() )
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBakedModel handleItemState( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
|
||||
public IBakedModel handleItemState( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity )
|
||||
{
|
||||
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
|
||||
ComputerFamily family = turtle.getFamily( stack );
|
||||
@ -111,7 +130,9 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
|
||||
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.Right );
|
||||
ResourceLocation overlay = turtle.getOverlay( stack );
|
||||
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.Christmas;
|
||||
TurtleModelCombination combo = new TurtleModelCombination( family, colour != -1, leftUpgrade, rightUpgrade, overlay, christmas );
|
||||
String label = turtle.getLabel( stack );
|
||||
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
|
||||
TurtleModelCombination combo = new TurtleModelCombination( family, colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
|
||||
if( m_cachedModels.containsKey( combo ) )
|
||||
{
|
||||
return m_cachedModels.get( combo );
|
||||
@ -147,27 +168,24 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
|
||||
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_family, combo.m_overlay, combo.m_christmas );
|
||||
IBakedModel baseModel = modelManager.getModel( baseModelLocation );
|
||||
IBakedModel overlayModel = (overlayModelLocation != null) ? modelManager.getModel( baseModelLocation ) : null;
|
||||
Matrix4f transform = combo.m_flip ? s_flip : s_identity;
|
||||
Pair<IBakedModel, Matrix4f> leftModel = (combo.m_leftUpgrade != null) ? combo.m_leftUpgrade.getModel( null, TurtleSide.Left ) : null;
|
||||
Pair<IBakedModel, Matrix4f> rightModel = (combo.m_rightUpgrade != null) ? combo.m_rightUpgrade.getModel( null, TurtleSide.Right ) : null;
|
||||
if( leftModel != null && rightModel != null )
|
||||
{
|
||||
return new TurtleMultiModel( baseModel, overlayModel, leftModel.getLeft(), leftModel.getRight(), rightModel.getLeft(), rightModel.getRight() );
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel.getLeft(), leftModel.getRight(), rightModel.getLeft(), rightModel.getRight() );
|
||||
}
|
||||
else if( leftModel != null )
|
||||
{
|
||||
return new TurtleMultiModel( baseModel, overlayModel, leftModel.getLeft(), leftModel.getRight(), null, null );
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel.getLeft(), leftModel.getRight(), null, null );
|
||||
}
|
||||
else if( rightModel != null )
|
||||
{
|
||||
return new TurtleMultiModel( baseModel, overlayModel, null, null, rightModel.getLeft(), rightModel.getRight() );
|
||||
}
|
||||
else if( overlayModel != null )
|
||||
{
|
||||
return new TurtleMultiModel( baseModel, overlayModel, null, null, null, null );
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, null, null, rightModel.getLeft(), rightModel.getRight() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return baseModel;
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, null, null, null, null );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,6 +420,12 @@ public abstract class TileComputerBase extends TileGeneric
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
IComputer computer = getComputer();
|
||||
return computer == null ? m_label : computer.getLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IComputer createComputer()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user