Major Refactoring of Bootstrap Code (#75)
- Refactored boostrap code: * Completely reworked item/block/tile registration. * Fixed server side startup. * Fixed server side startup. * More documentation. * More heavy cleanup * More cleanups. * Major refactoring of state mapping and fixes a lot of other issue related to item rendering. * Fixes sky chest item models (no item TESR). * Only use CachingRotatingBakedModel for tile entities automatically. Fix default rotation of quartz pillar for item model. * Used method reference instead of lambda for ItemMeshDefinition for multiparts. * Removed unnecessary IHasSpecialItemModel * Removed unused IconReg class. * Updated resource pack version.
This commit is contained in:
committed by
Sebastian Hartte
parent
66df324ef0
commit
6f2bbfab4c
@@ -22,7 +22,6 @@ package appeng.block.networking;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -60,7 +59,6 @@ import appeng.api.util.AEColor;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.Api;
|
||||
import appeng.core.features.AECableBusFeatureHandler;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
@@ -88,7 +86,6 @@ public class BlockCableBus extends AEBaseTileBlock
|
||||
// this will actually be overwritten later through setupTile and the
|
||||
// combined layers
|
||||
this.setTileEntity( TileCableBus.class );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
}
|
||||
|
||||
public static final CableBusContainerUnlistedProperty cableBus = new CableBusContainerUnlistedProperty();
|
||||
@@ -96,19 +93,14 @@ public class BlockCableBus extends AEBaseTileBlock
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return new ExtendedBlockState( this, new IProperty[0], new IUnlistedProperty[] { cableBus } );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
return state;
|
||||
return new ExtendedBlockState( this, new IProperty[0], new IUnlistedProperty[] { FORWARD, UP, cableBus } );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState( IBlockState state, IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
return ( (IExtendedBlockState) state ).withProperty( cableBus, ( (TileCableBus) world.getTileEntity( pos ) ).getCableBus() );
|
||||
return ( (IExtendedBlockState) super.getExtendedState( state, world, pos ) )
|
||||
.withProperty( cableBus, ( (TileCableBus) world.getTileEntity( pos ) ).getCableBus() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,13 +351,6 @@ public class BlockCableBus extends AEBaseTileBlock
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFeature( final EnumSet<AEFeature> f )
|
||||
{
|
||||
final AECableBusFeatureHandler featureHandler = new AECableBusFeatureHandler( f, this, this.getFeatureSubName() );
|
||||
this.setHandler( featureHandler );
|
||||
}
|
||||
|
||||
public void setupTile()
|
||||
{
|
||||
noTesrTile = Api.INSTANCE.partHelper().getCombinedInstance( TileCableBus.class.getName() );
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
@@ -32,12 +30,11 @@ import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.tile.networking.TileController;
|
||||
|
||||
|
||||
public class BlockController extends AEBaseTileBlock
|
||||
{
|
||||
|
||||
@@ -77,7 +74,7 @@ public class BlockController extends AEBaseTileBlock
|
||||
@Override
|
||||
protected IProperty[] getAEStates()
|
||||
{
|
||||
return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP, CONTROLLER_STATE, CONTROLLER_TYPE };
|
||||
return new IProperty[] { CONTROLLER_STATE, CONTROLLER_TYPE };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +87,6 @@ public class BlockController extends AEBaseTileBlock
|
||||
{
|
||||
|
||||
// Only used for columns, really
|
||||
EnumFacing up = EnumFacing.UP;
|
||||
EnumFacing forward = EnumFacing.NORTH;
|
||||
ControllerRenderType type = ControllerRenderType.block;
|
||||
|
||||
int x = pos.getX();
|
||||
@@ -105,20 +100,14 @@ public class BlockController extends AEBaseTileBlock
|
||||
|
||||
if( xx && !yy && !zz )
|
||||
{
|
||||
up = EnumFacing.EAST;
|
||||
forward = EnumFacing.UP;
|
||||
type = ControllerRenderType.column;
|
||||
}
|
||||
else if( !xx && yy && !zz )
|
||||
{
|
||||
up = EnumFacing.UP;
|
||||
forward = EnumFacing.NORTH;
|
||||
type = ControllerRenderType.column;
|
||||
}
|
||||
else if( !xx && !yy && zz )
|
||||
{
|
||||
up = EnumFacing.NORTH;
|
||||
forward = EnumFacing.UP;
|
||||
type = ControllerRenderType.column;
|
||||
}
|
||||
else if( ( xx ? 1 : 0 ) + ( yy ? 1 : 0 ) + ( zz ? 1 : 0 ) >= 2 )
|
||||
@@ -137,7 +126,43 @@ public class BlockController extends AEBaseTileBlock
|
||||
}
|
||||
}
|
||||
|
||||
return state.withProperty( AE_BLOCK_FORWARD, forward ).withProperty( AE_BLOCK_UP, up ).withProperty( CONTROLLER_TYPE, type );
|
||||
return state.withProperty( CONTROLLER_TYPE, type );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState( IBlockState state, IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
// Only used for columns, really
|
||||
EnumFacing up = EnumFacing.UP;
|
||||
EnumFacing forward = EnumFacing.NORTH;
|
||||
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
|
||||
// Detect whether controllers are on both sides of the x, y, and z axes
|
||||
final boolean xx = this.getTileEntity( world, x - 1, y, z ) instanceof TileController && this.getTileEntity( world, x + 1, y, z ) instanceof TileController;
|
||||
final boolean yy = this.getTileEntity( world, x, y - 1, z ) instanceof TileController && this.getTileEntity( world, x, y + 1, z ) instanceof TileController;
|
||||
final boolean zz = this.getTileEntity( world, x, y, z - 1 ) instanceof TileController && this.getTileEntity( world, x, y, z + 1 ) instanceof TileController;
|
||||
|
||||
if( xx && !yy && !zz )
|
||||
{
|
||||
up = EnumFacing.EAST;
|
||||
forward = EnumFacing.UP;
|
||||
}
|
||||
else if( !xx && yy && !zz )
|
||||
{
|
||||
up = EnumFacing.UP;
|
||||
forward = EnumFacing.NORTH;
|
||||
}
|
||||
else if( !xx && !yy && zz )
|
||||
{
|
||||
up = EnumFacing.NORTH;
|
||||
forward = EnumFacing.UP;
|
||||
}
|
||||
|
||||
IExtendedBlockState extState = (IExtendedBlockState) super.getExtendedState( state, world, pos );
|
||||
return extState.withProperty( FORWARD, forward ).withProperty( UP, up );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +189,6 @@ public class BlockController extends AEBaseTileBlock
|
||||
super( Material.IRON );
|
||||
this.setTileEntity( TileController.class );
|
||||
this.setHardness( 6 );
|
||||
this.setFeature( EnumSet.of( AEFeature.Channels ) );
|
||||
this.setDefaultState( getDefaultState().withProperty( CONTROLLER_STATE, ControllerBlockState.offline ).withProperty( CONTROLLER_TYPE, ControllerRenderType.block ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,10 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.tile.networking.TileCreativeEnergyCell;
|
||||
|
||||
|
||||
public class BlockCreativeEnergyCell extends AEBaseTileBlock
|
||||
{
|
||||
|
||||
@@ -34,6 +30,5 @@ public class BlockCreativeEnergyCell extends AEBaseTileBlock
|
||||
{
|
||||
super( AEGlassMaterial.INSTANCE );
|
||||
this.setTileEntity( TileCreativeEnergyCell.class );
|
||||
this.setFeature( EnumSet.of( AEFeature.Creative ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,19 +19,14 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.tile.networking.TileDenseEnergyCell;
|
||||
|
||||
|
||||
public class BlockDenseEnergyCell extends BlockEnergyCell
|
||||
{
|
||||
|
||||
public BlockDenseEnergyCell()
|
||||
{
|
||||
this.setTileEntity( TileDenseEnergyCell.class );
|
||||
this.setFeature( EnumSet.of( AEFeature.DenseEnergyCells ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.tile.networking.TileEnergyAcceptor;
|
||||
|
||||
|
||||
@@ -35,6 +32,5 @@ public class BlockEnergyAcceptor extends AEBaseTileBlock
|
||||
{
|
||||
super( Material.IRON );
|
||||
this.setTileEntity( TileEnergyAcceptor.class );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,11 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -34,11 +31,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.block.AEBaseItemBlock;
|
||||
import appeng.block.AEBaseItemBlockChargeable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.tile.networking.TileEnergyCell;
|
||||
import appeng.util.Platform;
|
||||
@@ -66,7 +59,6 @@ public class BlockEnergyCell extends AEBaseTileBlock
|
||||
super( AEGlassMaterial.INSTANCE );
|
||||
|
||||
this.setTileEntity( TileEnergyCell.class );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,48 +83,7 @@ public class BlockEnergyCell extends AEBaseTileBlock
|
||||
@Override
|
||||
protected IProperty[] getAEStates()
|
||||
{
|
||||
return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP, ENERGY_STORAGE };
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends AEBaseItemBlock> getItemBlockClass()
|
||||
{
|
||||
return AEBaseItemBlockChargeable.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the energy fill factor (between 0 and 1) of a given item stack.
|
||||
* Returns 0 if the item stack has no fill factor.
|
||||
*/
|
||||
private static double getFillFactor( ItemStack is ) {
|
||||
if( !( is.getItem() instanceof IAEItemPowerStorage ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
AEBaseItemBlockChargeable itemChargeable = (AEBaseItemBlockChargeable) is.getItem();
|
||||
double curPower = itemChargeable.getAECurrentPower( is );
|
||||
double maxPower = itemChargeable.getAEMaxPower( is );
|
||||
|
||||
return curPower / maxPower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines which version of the energy cell model should be used depending on the fill factor
|
||||
* of the item stack.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
@Override
|
||||
public ItemMeshDefinition getItemMeshDefinition()
|
||||
{
|
||||
return is -> {
|
||||
double fillFactor = getFillFactor( is );
|
||||
|
||||
int storageLevel = TileEnergyCell.getStorageLevelFromFillFactor(fillFactor);
|
||||
|
||||
return new ModelResourceLocation( "appliedenergistics2:tile.BlockEnergyCell", "fullness=" + storageLevel );
|
||||
|
||||
};
|
||||
return new IProperty[] { ENERGY_STORAGE };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.block.AEBaseItemBlockChargeable;
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.tile.networking.TileEnergyCell;
|
||||
|
||||
|
||||
public class BlockEnergyCellRendering extends BlockRenderingCustomizer
|
||||
{
|
||||
|
||||
private final ResourceLocation baseModel;
|
||||
|
||||
public BlockEnergyCellRendering( ResourceLocation baseModel )
|
||||
{
|
||||
this.baseModel = baseModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
itemRendering.meshDefinition( this::getItemModel );
|
||||
// Note: Since we use the block models, we dont need to register custom variants
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines which version of the energy cell model should be used depending on the fill factor
|
||||
* of the item stack.
|
||||
*/
|
||||
private ModelResourceLocation getItemModel( ItemStack is )
|
||||
{
|
||||
double fillFactor = getFillFactor( is );
|
||||
|
||||
int storageLevel = TileEnergyCell.getStorageLevelFromFillFactor( fillFactor );
|
||||
return new ModelResourceLocation( baseModel, "fullness=" + storageLevel );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the energy fill factor (between 0 and 1) of a given item stack.
|
||||
* Returns 0 if the item stack has no fill factor.
|
||||
*/
|
||||
private static double getFillFactor( ItemStack is )
|
||||
{
|
||||
if( !( is.getItem() instanceof IAEItemPowerStorage ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
AEBaseItemBlockChargeable itemChargeable = (AEBaseItemBlockChargeable) is.getItem();
|
||||
double curPower = itemChargeable.getAECurrentPower( is );
|
||||
double maxPower = itemChargeable.getAEMaxPower( is );
|
||||
|
||||
return curPower / maxPower;
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,7 @@ package appeng.block.networking;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -38,14 +36,12 @@ import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.helpers.ICustomCollision;
|
||||
import appeng.tile.networking.TileWireless;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class BlockWireless extends AEBaseTileBlock implements ICustomCollision
|
||||
{
|
||||
|
||||
@@ -56,7 +52,6 @@ public class BlockWireless extends AEBaseTileBlock implements ICustomCollision
|
||||
this.setLightOpacity( 0 );
|
||||
this.setFullSize( false );
|
||||
this.setOpaque( false );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core, AEFeature.WirelessAccessTerminal ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.parts.CableBusContainer;
|
||||
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public class CableBusColor implements IBlockColor
|
||||
{
|
||||
|
||||
@Override
|
||||
public int colorMultiplier( IBlockState state, IBlockAccess worldIn, BlockPos pos, int color )
|
||||
{
|
||||
AEPartLocation side = AEPartLocation.fromOrdinal( ( color >> 2 ) & 7 );
|
||||
CableBusContainer bus = ( (IExtendedBlockState) state ).getValue( BlockCableBus.cableBus );
|
||||
switch( color & 3 )
|
||||
{
|
||||
case 0:
|
||||
return bus.getGridNode( side ) != null && bus.getGridNode( side ).isActive() ? 0xffffff : 0;
|
||||
case 1:
|
||||
return bus.getColor().blackVariant;
|
||||
case 2:
|
||||
return bus.getColor().mediumVariant;
|
||||
case 3:
|
||||
return bus.getColor().whiteVariant;
|
||||
default:
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package appeng.block.networking;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.client.render.model.pipeline.BakingPipelineBakedModel;
|
||||
import appeng.client.render.model.pipeline.FacingQuadRotator;
|
||||
import appeng.client.render.model.pipeline.Merge;
|
||||
import appeng.client.render.model.pipeline.TintIndexModifier;
|
||||
import appeng.client.render.model.pipeline.TypeTransformer;
|
||||
import appeng.client.render.model.pipeline.cable.CableAndConnections;
|
||||
import appeng.client.render.model.pipeline.cable.Facades;
|
||||
import appeng.client.render.model.pipeline.cable.Parts;
|
||||
|
||||
|
||||
public class CableModelCustomizer
|
||||
{
|
||||
|
||||
private final BakingPipeline rotatingPipeline = new BakingPipeline( TypeTransformer.quads2vecs, new FacingQuadRotator(), TypeTransformer.vecs2quads );
|
||||
private final TintIndexModifier tintIndexModifier = new TintIndexModifier( tint -> tint );
|
||||
private final BakingPipeline tintIndexFixPipeline = new BakingPipeline( TypeTransformer.quads2vecs, tintIndexModifier, TypeTransformer.vecs2quads );
|
||||
|
||||
public IBakedModel customizeModel( ModelResourceLocation location, IBakedModel model )
|
||||
{
|
||||
return new BakingPipelineBakedModel( model, new Merge( new CableAndConnections( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ), new Facades( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ), new Parts( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ) ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user