First attempt at combining the Block registration and TE registration whilst still keeping support for addons.
It might need some refinement in the future.
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.Registration;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
@@ -76,7 +77,7 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
|
||||
private CreativeTabs creativeTab = CreativeTab.instance;
|
||||
|
||||
private Class<? extends AEBaseTile> teClass;
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
|
||||
private boolean disableItem = false;
|
||||
|
||||
@@ -156,9 +157,9 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder tileEntity( Class<? extends AEBaseTile> tileEntityClass )
|
||||
public IBlockBuilder tileEntity( TileEntityDefinition tileEntityDefinition )
|
||||
{
|
||||
teClass = tileEntityClass;
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -203,6 +204,7 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
@Override
|
||||
public <T extends IBlockDefinition> T build()
|
||||
{
|
||||
System.out.println("regName = " + registryName);
|
||||
if( !AEConfig.instance().areFeaturesEnabled( features ) )
|
||||
{
|
||||
return (T) new TileDefinition( registryName, null, null );
|
||||
@@ -238,9 +240,15 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
postInitCallbacks.forEach( consumer -> factory.addPostInit( side -> consumer.accept( block, item ) ) );
|
||||
|
||||
|
||||
if ( teClass != null && block instanceof AEBaseTileBlock )
|
||||
|
||||
if ( tileEntityDefinition != null && block instanceof AEBaseTileBlock )
|
||||
{
|
||||
((AEBaseTileBlock) block).setTileEntity( teClass );
|
||||
( (AEBaseTileBlock) block ).setTileEntity( tileEntityDefinition.getTileEntityClass() );
|
||||
if( tileEntityDefinition.getName() == null )
|
||||
{
|
||||
tileEntityDefinition.setName( registryName );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( Platform.isClient() )
|
||||
@@ -264,9 +272,14 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
if( block instanceof AEBaseTileBlock )
|
||||
{
|
||||
factory.addPreInit( side -> {
|
||||
AEBaseTile.registerTileItem( teClass, new BlockStackSrc( block, 0, ActivityState.Enabled ) );
|
||||
AEBaseTile.registerTileItem( tileEntityDefinition == null ? ( (AEBaseTileBlock) block ).getTileEntityClass() : tileEntityDefinition.getTileEntityClass(), new BlockStackSrc( block, 0, ActivityState.Enabled ) );
|
||||
} );
|
||||
|
||||
if( tileEntityDefinition != null )
|
||||
{
|
||||
factory.tileEntityComponent.addTileEntity( tileEntityDefinition );
|
||||
}
|
||||
|
||||
return (T) new TileDefinition( registryName, (AEBaseTileBlock) block, item );
|
||||
}
|
||||
else
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import appeng.bootstrap.components.ModelRegComponent;
|
||||
import appeng.bootstrap.components.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
@@ -33,11 +33,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.AEColoredItemDefinition;
|
||||
import appeng.bootstrap.components.BuiltInModelComponent;
|
||||
import appeng.bootstrap.components.InitComponent;
|
||||
import appeng.bootstrap.components.ModelOverrideComponent;
|
||||
import appeng.bootstrap.components.PostInitComponent;
|
||||
import appeng.bootstrap.components.PreInitComponent;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.ColoredItemDefinition;
|
||||
@@ -58,11 +53,16 @@ public class FeatureFactory
|
||||
@SideOnly( Side.CLIENT )
|
||||
private BuiltInModelComponent builtInModelComponent;
|
||||
|
||||
public final TileEntityComponent tileEntityComponent;
|
||||
|
||||
public FeatureFactory()
|
||||
{
|
||||
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
|
||||
this.bootstrapComponents = new ArrayList<>();
|
||||
|
||||
this.tileEntityComponent = new TileEntityComponent();
|
||||
this.bootstrapComponents.add( tileEntityComponent );
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
modelOverrideComponent = new ModelOverrideComponent();
|
||||
@@ -77,6 +77,7 @@ public class FeatureFactory
|
||||
{
|
||||
this.defaultFeatures = defaultFeatures.clone();
|
||||
this.bootstrapComponents = parent.bootstrapComponents;
|
||||
this.tileEntityComponent = parent.tileEntityComponent;
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.modelOverrideComponent = parent.modelOverrideComponent;
|
||||
|
||||
@@ -22,7 +22,7 @@ package appeng.bootstrap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
@@ -48,7 +48,7 @@ public interface IBlockBuilder
|
||||
|
||||
IBlockBuilder rendering( BlockRenderingCustomizer callback );
|
||||
|
||||
IBlockBuilder tileEntity( Class<? extends AEBaseTile> teClass );
|
||||
IBlockBuilder tileEntity( TileEntityDefinition tileEntityDefinition );
|
||||
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
public class TileEntityComponent implements PreInitComponent
|
||||
{
|
||||
private List<TileEntityDefinition> tileEntityDefinitions = new ArrayList<>();
|
||||
|
||||
public TileEntityComponent()
|
||||
{
|
||||
}
|
||||
|
||||
public void addTileEntity( TileEntityDefinition tileEntityDefinition )
|
||||
{
|
||||
if( !tileEntityDefinitions.contains( tileEntityDefinition ) )
|
||||
{
|
||||
tileEntityDefinitions.add( tileEntityDefinition );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInitialize( Side side )
|
||||
{
|
||||
for( TileEntityDefinition tileEntityDefinition : tileEntityDefinitions )
|
||||
{
|
||||
if ( !tileEntityDefinition.isRegistered() )
|
||||
{
|
||||
GameRegistry.registerTileEntity( tileEntityDefinition.getTileEntityClass(), AppEng.MOD_ID + ":" + tileEntityDefinition.getName() );
|
||||
tileEntityDefinition.setRegistered( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, 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.bootstrap.definitions;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
public class TileEntityDefinition
|
||||
{
|
||||
|
||||
private final Class<? extends AEBaseTile> tileEntityClass;
|
||||
private String name;
|
||||
private boolean isRegistered = false;
|
||||
|
||||
// This signals the BlockDefinitionBuilder to set the name of the TE to the blockname.
|
||||
public TileEntityDefinition( Class<? extends AEBaseTile> tileEntityClass )
|
||||
{
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
public TileEntityDefinition( Class<? extends AEBaseTile> tileEntityClass, String optionalName )
|
||||
{
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.name = optionalName;
|
||||
}
|
||||
|
||||
public Class<? extends AEBaseTile> getTileEntityClass()
|
||||
{
|
||||
return tileEntityClass;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isRegistered()
|
||||
{
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
public void setRegistered( boolean registered )
|
||||
{
|
||||
isRegistered = registered;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user