1.15 port
This commit is contained in:
@@ -19,316 +19,25 @@
|
||||
package appeng.core.api;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
import org.objectweb.asm.commons.RemappingClassAdapter;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.parts.CableRenderMode;
|
||||
import appeng.api.parts.IPartHelper;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.parts.PartPlacement;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
|
||||
|
||||
public class ApiPart implements IPartHelper
|
||||
{
|
||||
|
||||
private final LoadingCache<CacheKey, Class<? extends AEBaseTile>> cache = CacheBuilder.newBuilder()
|
||||
.build( new CacheLoader<CacheKey, Class<? extends AEBaseTile>>()
|
||||
{
|
||||
@Override
|
||||
public Class<? extends AEBaseTile> load( CacheKey key ) throws Exception
|
||||
{
|
||||
return ApiPart.this.generateCombinedClass( key );
|
||||
}
|
||||
} );
|
||||
|
||||
private final Map<Class<?>, String> interfaces2Layer = new HashMap<>();
|
||||
private final List<String> desc = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Conceptually this method will build a new class hierarchy that is rooted at the given base class, and includes a
|
||||
* chain of all registered layers.
|
||||
* <p/>
|
||||
* To accomplish this, it takes the first registered layer, replaces it's inheritance from LayerBase with an
|
||||
* inheritance from the given baseClass,
|
||||
* and uses the resulting class as the parent class for the next registered layer, for which it repeats this
|
||||
* process. This process is then repeated
|
||||
* until a class hierarchy of all layers is formed. While janking out the inheritance from LayerBase, it'll make
|
||||
* also sure that calls to that
|
||||
* classes method will instead be forwarded to the superclass that was inserted as part of the described process.
|
||||
* <p/>
|
||||
* Example: If layers A and B are registered, and TileCableBus is passed in as the baseClass, a synthetic class
|
||||
* A_B_TileCableBus should be returned,
|
||||
* which has A_B_TileCableBus -extends-> B_TileCableBus -extends-> TileCableBus as it's class hierarchy, where
|
||||
* A_B_TileCableBus has been generated
|
||||
* from A, and B_TileCableBus has been generated from B.
|
||||
*/
|
||||
public Class<? extends AEBaseTile> getCombinedInstance( final Class<? extends AEBaseTile> baseClass )
|
||||
{
|
||||
if( this.desc.isEmpty() )
|
||||
{
|
||||
// No layers registered...
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
return this.cache.getUnchecked( new CacheKey( baseClass, this.desc ) );
|
||||
}
|
||||
|
||||
private Class<? extends AEBaseTile> generateCombinedClass( CacheKey cacheKey )
|
||||
{
|
||||
final Class<? extends AEBaseTile> parentClass;
|
||||
|
||||
// Get the list of interfaces that still need to be implemented beyond the current one
|
||||
List<String> remainingInterfaces = cacheKey.getInterfaces().subList( 1, cacheKey.getInterfaces().size() );
|
||||
|
||||
// We are not at the root of the class hierarchy yet
|
||||
if( !remainingInterfaces.isEmpty() )
|
||||
{
|
||||
CacheKey parentKey = new CacheKey( cacheKey.getBaseClass(), remainingInterfaces );
|
||||
parentClass = this.cache.getUnchecked( parentKey );
|
||||
}
|
||||
else
|
||||
{
|
||||
parentClass = cacheKey.getBaseClass();
|
||||
}
|
||||
|
||||
// Which interface should be implemented in this layer?
|
||||
String interfaceName = cacheKey.getInterfaces().get( 0 );
|
||||
|
||||
try
|
||||
{
|
||||
// This is the particular interface that this layer was registered for. Loading the class may fail if i.e.
|
||||
// an API is broken or not present
|
||||
// and in this case, the layer will be skipped!
|
||||
Class<?> interfaceClass = Class.forName( interfaceName );
|
||||
String layerImpl = this.interfaces2Layer.get( interfaceClass );
|
||||
|
||||
return this.getClassByDesc( parentClass, layerImpl );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
AELog.warn( "Error loading " + interfaceName );
|
||||
AELog.debug( t );
|
||||
return parentClass;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
private Class<? extends AEBaseTile> getClassByDesc( Class<? extends AEBaseTile> baseClass, final String next )
|
||||
{
|
||||
final ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
|
||||
final ClassNode n = this.getReader( next );
|
||||
final String originalName = n.name;
|
||||
|
||||
try
|
||||
{
|
||||
n.name = n.name + '_' + baseClass.getSimpleName();
|
||||
n.superName = baseClass.getName().replace( '.', '/' );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
AELog.debug( t );
|
||||
}
|
||||
|
||||
for( final MethodNode mn : n.methods )
|
||||
{
|
||||
final Iterator<AbstractInsnNode> i = mn.instructions.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
this.processNode( i.next(), n.superName );
|
||||
}
|
||||
}
|
||||
|
||||
final DefaultPackageClassNameRemapper remapper = new DefaultPackageClassNameRemapper();
|
||||
remapper.inputOutput.put( "appeng/api/parts/LayerBase", n.superName );
|
||||
remapper.inputOutput.put( originalName, n.name );
|
||||
n.accept( new RemappingClassAdapter( cw, remapper ) );
|
||||
// n.accept( cw );
|
||||
|
||||
// n.accept( new TraceClassVisitor( new PrintWriter( System.out ) ) );
|
||||
final byte[] byteArray = cw.toByteArray();
|
||||
final int size = byteArray.length;
|
||||
final Class clazz = this.loadClass( n.name.replace( "/", "." ), byteArray );
|
||||
|
||||
try
|
||||
{
|
||||
final Object fish = clazz.newInstance();
|
||||
|
||||
boolean hasError = false;
|
||||
|
||||
if( !baseClass.isInstance( fish ) )
|
||||
{
|
||||
hasError = true;
|
||||
AELog.error( "Error, Expected layer to implement " + baseClass + " did not." );
|
||||
}
|
||||
|
||||
if( fish instanceof LayerBase )
|
||||
{
|
||||
hasError = true;
|
||||
AELog.error( "Error, Expected layer to NOT implement LayerBase but it DID." );
|
||||
}
|
||||
|
||||
if( !( fish instanceof TileCableBus ) )
|
||||
{
|
||||
hasError = true;
|
||||
AELog.error( "Error, Expected layer to implement TileCableBus did not." );
|
||||
}
|
||||
|
||||
if( !( fish instanceof TileEntity ) )
|
||||
{
|
||||
hasError = true;
|
||||
AELog.error( "Error, Expected layer to implement TileEntity did not." );
|
||||
}
|
||||
|
||||
if( !hasError )
|
||||
{
|
||||
AELog.info( "Layer: " + n.name + " loaded successfully - " + size + " bytes" );
|
||||
}
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
AELog.error( "Layer: " + n.name + " Failed." );
|
||||
AELog.debug( t );
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
private ClassNode getReader( final String name )
|
||||
{
|
||||
final String path = '/' + name.replace( ".", "/" ) + ".class";
|
||||
final InputStream is = this.getClass().getResourceAsStream( path );
|
||||
try
|
||||
{
|
||||
final ClassReader cr = new ClassReader( is );
|
||||
|
||||
final ClassNode cn = new ClassNode();
|
||||
cr.accept( cn, ClassReader.EXPAND_FRAMES );
|
||||
|
||||
return cn;
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
throw new IllegalStateException( "Error loading " + name, e );
|
||||
}
|
||||
}
|
||||
|
||||
private void processNode( final AbstractInsnNode next, final String nePar )
|
||||
{
|
||||
if( next instanceof MethodInsnNode )
|
||||
{
|
||||
final MethodInsnNode min = (MethodInsnNode) next;
|
||||
if( min.owner.equals( "appeng/api/parts/LayerBase" ) )
|
||||
{
|
||||
min.owner = nePar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Class loadClass( final String name, byte[] b )
|
||||
{
|
||||
// override classDefine (as it is protected) and define the class.
|
||||
Class clazz = null;
|
||||
try
|
||||
{
|
||||
final ClassLoader loader = this.getClass().getClassLoader();// ClassLoader.getSystemClassLoader();
|
||||
final Class<ClassLoader> root = ClassLoader.class;
|
||||
final Class<? extends ClassLoader> cls = loader.getClass();
|
||||
final Method defineClassMethod = root.getDeclaredMethod( "defineClass", String.class, byte[].class, int.class, int.class );
|
||||
final Method runTransformersMethod = cls.getDeclaredMethod( "runTransformers", String.class, String.class, byte[].class );
|
||||
|
||||
runTransformersMethod.setAccessible( true );
|
||||
defineClassMethod.setAccessible( true );
|
||||
try
|
||||
{
|
||||
final Object[] argsA = {
|
||||
name,
|
||||
name,
|
||||
b
|
||||
};
|
||||
b = (byte[]) runTransformersMethod.invoke( loader, argsA );
|
||||
|
||||
final Object[] args = {
|
||||
name,
|
||||
b,
|
||||
0,
|
||||
b.length
|
||||
};
|
||||
clazz = (Class) defineClassMethod.invoke( loader, args );
|
||||
}
|
||||
finally
|
||||
{
|
||||
runTransformersMethod.setAccessible( false );
|
||||
defineClassMethod.setAccessible( false );
|
||||
}
|
||||
}
|
||||
catch( final Exception e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
throw new IllegalStateException( "Unable to manage part API.", e );
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerNewLayer( final String layer, final String layerInterface )
|
||||
{
|
||||
try
|
||||
{
|
||||
final Class<?> layerInterfaceClass = Class.forName( layerInterface );
|
||||
if( this.interfaces2Layer.get( layerInterfaceClass ) == null )
|
||||
{
|
||||
this.interfaces2Layer.put( layerInterfaceClass, layer );
|
||||
this.desc.add( layerInterface );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AELog.info( "Layer " + layer + " not registered, " + layerInterface + " already has a layer." );
|
||||
}
|
||||
}
|
||||
catch( final Throwable ignored )
|
||||
{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult placeBus( final ItemStack is, final BlockPos pos, final EnumFacing side, final EntityPlayer player, final EnumHand hand, final World w )
|
||||
public ActionResult placeBus( final ItemStack is, final BlockPos pos, final Direction side, final PlayerEntity player, final Hand hand, final World w )
|
||||
{
|
||||
return PartPlacement.place( is, pos, side, player, hand, w, PartPlacement.PlaceType.PLACE_ITEM, 0 );
|
||||
}
|
||||
@@ -338,69 +47,4 @@ public class ApiPart implements IPartHelper
|
||||
{
|
||||
return AppEng.proxy.getRenderMode();
|
||||
}
|
||||
|
||||
private static class DefaultPackageClassNameRemapper extends Remapper
|
||||
{
|
||||
|
||||
private final HashMap<String, String> inputOutput = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String map( final String typeName )
|
||||
{
|
||||
final String o = this.inputOutput.get( typeName );
|
||||
if( o == null )
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CacheKey
|
||||
{
|
||||
private final Class<? extends AEBaseTile> baseClass;
|
||||
|
||||
private final List<String> interfaces;
|
||||
|
||||
private CacheKey( Class<? extends AEBaseTile> baseClass, List<String> interfaces )
|
||||
{
|
||||
this.baseClass = baseClass;
|
||||
this.interfaces = ImmutableList.copyOf( interfaces );
|
||||
}
|
||||
|
||||
private Class<? extends AEBaseTile> getBaseClass()
|
||||
{
|
||||
return this.baseClass;
|
||||
}
|
||||
|
||||
private List<String> getInterfaces()
|
||||
{
|
||||
return this.interfaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( o == null || this.getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CacheKey cacheKey = (CacheKey) o;
|
||||
|
||||
return this.baseClass.equals( cacheKey.baseClass ) && this.interfaces.equals( cacheKey.interfaces );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = this.baseClass.hashCode();
|
||||
result = 31 * result + this.interfaces.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ import com.google.common.collect.MutableClassToInstanceMap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
@@ -100,7 +101,7 @@ public class ApiStorage implements IStorageHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingLink loadCraftingLink( final NBTTagCompound data, final ICraftingRequester req )
|
||||
public ICraftingLink loadCraftingLink( final CompoundNBT data, final ICraftingRequester req )
|
||||
{
|
||||
Preconditions.checkNotNull( data );
|
||||
Preconditions.checkNotNull( req );
|
||||
@@ -154,7 +155,7 @@ public class ApiStorage implements IStorageHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack createFromNBT( NBTTagCompound nbt )
|
||||
public IAEItemStack createFromNBT( CompoundNBT nbt )
|
||||
{
|
||||
Preconditions.checkNotNull( nbt );
|
||||
return AEItemStack.fromNBT( nbt );
|
||||
@@ -224,11 +225,10 @@ public class ApiStorage implements IStorageHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack createFromNBT( NBTTagCompound nbt )
|
||||
public IAEFluidStack createFromNBT( CompoundNBT nbt )
|
||||
{
|
||||
Preconditions.checkNotNull( nbt );
|
||||
return AEFluidStack.fromNBT( nbt );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package appeng.core.api;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
import net.minecraftforge.fml.InterModComms.IMCMessage;
|
||||
|
||||
public interface IIMCProcessor
|
||||
{
|
||||
|
||||
@@ -23,22 +23,20 @@ import com.google.common.base.Verify;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.block.SlabBlock;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemSlab;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.block.AEBaseItemBlockChargeable;
|
||||
import appeng.block.AEBaseBlockItemChargeable;
|
||||
import appeng.block.crafting.BlockCraftingMonitor;
|
||||
import appeng.block.crafting.BlockCraftingStorage;
|
||||
import appeng.block.crafting.BlockCraftingUnit;
|
||||
@@ -95,7 +93,6 @@ import appeng.bootstrap.FeatureFactory;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.components.IEntityRegistrationComponent;
|
||||
import appeng.bootstrap.components.IOreDictComponent;
|
||||
import appeng.bootstrap.components.IPostInitComponent;
|
||||
import appeng.bootstrap.components.IPreInitComponent;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
@@ -117,6 +114,7 @@ import appeng.debug.TileEnergyGenerator;
|
||||
import appeng.debug.TileItemGen;
|
||||
import appeng.debug.TilePhantomNode;
|
||||
import appeng.decorative.slab.BlockSlabCommon;
|
||||
import appeng.decorative.slab.CommonSlabBlock;
|
||||
import appeng.decorative.solid.BlockChargedQuartzOre;
|
||||
import appeng.decorative.solid.BlockChiseledQuartz;
|
||||
import appeng.decorative.solid.BlockFluix;
|
||||
@@ -252,16 +250,10 @@ public final class ApiBlocks implements IBlocks
|
||||
// this.quartzOre = new BlockDefinition( "ore.quartz", new OreQuartz() );
|
||||
this.quartzOre = registry.block( "quartz_ore", BlockQuartzOre::new )
|
||||
.features( AEFeature.CERTUS_ORE )
|
||||
.bootstrap( ( block, item ) -> (IOreDictComponent) side -> OreDictionary.registerOre( "oreCertusQuartz", new ItemStack( block ) ) )
|
||||
.build();
|
||||
this.quartzOreCharged = registry.block( "charged_quartz_ore", BlockChargedQuartzOre::new )
|
||||
.features( AEFeature.CERTUS_ORE, AEFeature.CHARGED_CERTUS_ORE )
|
||||
.useCustomItemModel()
|
||||
.bootstrap( ( block, item ) -> (IOreDictComponent) side ->
|
||||
{
|
||||
OreDictionary.registerOre( "oreCertusQuartz", new ItemStack( block ) );
|
||||
OreDictionary.registerOre( "oreChargedCertusQuartz", new ItemStack( block ) );
|
||||
} )
|
||||
.build();
|
||||
this.matrixFrame = registry.block( "matrix_frame", BlockMatrixFrame::new ).features( AEFeature.SPATIAL_IO ).build();
|
||||
|
||||
@@ -276,7 +268,7 @@ public final class ApiBlocks implements IBlocks
|
||||
.rendering( new BlockRenderingCustomizer()
|
||||
{
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.builtInModel( "models/block/builtin/quartz_glass", new GlassModel() );
|
||||
@@ -349,7 +341,7 @@ public final class ApiBlocks implements IBlocks
|
||||
.rendering( new BlockRenderingCustomizer()
|
||||
{
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.tesr( BlockCharger.createTesr() );
|
||||
@@ -448,13 +440,13 @@ public final class ApiBlocks implements IBlocks
|
||||
.build();
|
||||
this.energyCell = registry.block( "energy_cell", BlockEnergyCell::new )
|
||||
.features( AEFeature.ENERGY_CELLS )
|
||||
.item( AEBaseItemBlockChargeable::new )
|
||||
.item( AEBaseBlockItemChargeable::new )
|
||||
.tileEntity( new TileEntityDefinition( TileEnergyCell.class ) )
|
||||
.rendering( new BlockEnergyCellRendering( new ResourceLocation( AppEng.MOD_ID, "energy_cell" ) ) )
|
||||
.build();
|
||||
this.energyCellDense = registry.block( "dense_energy_cell", BlockDenseEnergyCell::new )
|
||||
.features( AEFeature.ENERGY_CELLS, AEFeature.DENSE_ENERGY_CELLS )
|
||||
.item( AEBaseItemBlockChargeable::new )
|
||||
.item( AEBaseBlockItemChargeable::new )
|
||||
.tileEntity( new TileEntityDefinition( TileDenseEnergyCell.class ) )
|
||||
.rendering( new BlockEnergyCellRendering( new ResourceLocation( AppEng.MOD_ID, "dense_energy_cell" ) ) )
|
||||
.build();
|
||||
@@ -591,17 +583,17 @@ public final class ApiBlocks implements IBlocks
|
||||
return new BlockDefinition( slabId, null, null );
|
||||
}
|
||||
|
||||
BlockSlab slabBlock = (BlockSlab) slabDef.maybeBlock().get();
|
||||
SlabBlock slabBlock = (SlabBlock) slabDef.maybeBlock().get();
|
||||
|
||||
// Reigster the double slab variant as well
|
||||
IBlockDefinition doubleSlabDef = registry.block( doubleSlabId, () -> new BlockSlabCommon.Double( slabBlock, block ) )
|
||||
IBlockDefinition doubleSlabDef = registry.block( doubleSlabId, () -> new CommonSlabBlock.Double( slabBlock, block ) )
|
||||
.features( AEFeature.DECORATIVE_BLOCKS )
|
||||
.disableItem()
|
||||
.build();
|
||||
|
||||
Verify.verify( doubleSlabDef.maybeBlock().isPresent() );
|
||||
|
||||
BlockSlab doubleSlabBlock = (BlockSlab) doubleSlabDef.maybeBlock().get();
|
||||
SlabBlock doubleSlabBlock = (SlabBlock) doubleSlabDef.maybeBlock().get();
|
||||
|
||||
// Make the slab item
|
||||
IItemDefinition itemDef = registry.item( slabId, () -> new ItemSlab( slabBlock, slabBlock, doubleSlabBlock ) )
|
||||
@@ -611,7 +603,7 @@ public final class ApiBlocks implements IBlocks
|
||||
Verify.verify( itemDef.maybeItem().isPresent() );
|
||||
|
||||
// Return a new composite block definition that combines the single slab block with the slab item
|
||||
return new BlockDefinition( slabId, slabBlock, (ItemBlock) itemDef.maybeItem().get() );
|
||||
return new BlockDefinition( slabId, slabBlock, (BlockItem) itemDef.maybeItem().get() );
|
||||
}
|
||||
|
||||
private static IBlockDefinition makeStairs( String registryName, FeatureFactory registry, IBlockDefinition block )
|
||||
@@ -621,7 +613,7 @@ public final class ApiBlocks implements IBlocks
|
||||
.rendering( new BlockRenderingCustomizer()
|
||||
{
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
ModelResourceLocation model = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, registryName ), "facing=east,half=bottom,shape=straight" );
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
@@ -129,7 +129,7 @@ public final class ApiMaterials implements IMaterials
|
||||
.rendering( new ItemRenderingCustomizer()
|
||||
{
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
rendering.meshDefinition( is -> materials.getTypeByStack( is ).getModel() );
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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.core.api.imc;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.api.IIMCProcessor;
|
||||
|
||||
|
||||
public class IMCBlackListSpatial implements IIMCProcessor
|
||||
{
|
||||
|
||||
@Override
|
||||
public void process( final IMCMessage m )
|
||||
{
|
||||
|
||||
final ItemStack is = m.getItemStackValue();
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
final Block blk = Block.getBlockFromItem( is.getItem() );
|
||||
if( blk != Blocks.AIR )
|
||||
{
|
||||
AEApi.instance().registries().movable().blacklistBlock( blk );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AELog.info( "Bad Block blacklisted by " + m.getSender() );
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/* Example:
|
||||
|
||||
NBTTagCompound msg = new NBTTagCompound();
|
||||
NBTTagCompound in = new NBTTagCompound();
|
||||
NBTTagCompound out = new NBTTagCompound();
|
||||
|
||||
new ItemStack( Blocks.iron_ore ).writeToNBT( in );
|
||||
new ItemStack( Items.iron_ingot ).writeToNBT( out );
|
||||
msg.setTag( "in", in );
|
||||
msg.setTag( "out", out );
|
||||
msg.setInteger( "turns", 8 );
|
||||
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-grindable", msg );
|
||||
|
||||
-- or --
|
||||
|
||||
NBTTagCompound msg = new NBTTagCompound();
|
||||
NBTTagCompound in = new NBTTagCompound();
|
||||
NBTTagCompound out = new NBTTagCompound();
|
||||
NBTTagCompound optional = new NBTTagCompound();
|
||||
|
||||
new ItemStack( Blocks.iron_ore ).writeToNBT( in );
|
||||
new ItemStack( Items.iron_ingot ).writeToNBT( out );
|
||||
new ItemStack( Blocks.gravel ).writeToNBT( optional );
|
||||
msg.setTag( "in", in );
|
||||
msg.setTag( "out", out );
|
||||
msg.setTag( "optional", optional );
|
||||
msg.setFloat( "chance", 0.5 );
|
||||
msg.setInteger( "turns", 8 );
|
||||
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-grindable", msg );
|
||||
|
||||
*/
|
||||
|
||||
package appeng.core.api.imc;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderRecipe;
|
||||
import appeng.api.features.IGrinderRecipeBuilder;
|
||||
import appeng.api.features.IGrinderRegistry;
|
||||
import appeng.core.api.IIMCProcessor;
|
||||
|
||||
|
||||
public class IMCGrinder implements IIMCProcessor
|
||||
{
|
||||
@Override
|
||||
public void process( final IMCMessage m )
|
||||
{
|
||||
final NBTTagCompound msg = m.getNBTValue();
|
||||
final NBTTagCompound inTag = (NBTTagCompound) msg.getTag( "in" );
|
||||
final NBTTagCompound outTag = (NBTTagCompound) msg.getTag( "out" );
|
||||
|
||||
final ItemStack in = new ItemStack( inTag );
|
||||
final ItemStack out = new ItemStack( outTag );
|
||||
|
||||
final int turns = msg.getInteger( "turns" );
|
||||
|
||||
if( in.isEmpty() )
|
||||
{
|
||||
throw new IllegalStateException( "invalid input" );
|
||||
}
|
||||
|
||||
if( out.isEmpty() )
|
||||
{
|
||||
throw new IllegalStateException( "invalid output" );
|
||||
}
|
||||
|
||||
if( msg.hasKey( "optional" ) )
|
||||
{
|
||||
final NBTTagCompound optionalTag = (NBTTagCompound) msg.getTag( "optional" );
|
||||
final ItemStack optional = new ItemStack( optionalTag );
|
||||
|
||||
if( optional.isEmpty() )
|
||||
{
|
||||
throw new IllegalStateException( "invalid optional" );
|
||||
}
|
||||
|
||||
final float chance = msg.getFloat( "chance" );
|
||||
final IGrinderRegistry grinderRegistry = AEApi.instance().registries().grinder();
|
||||
final IGrinderRecipeBuilder builder = grinderRegistry.builder();
|
||||
final IGrinderRecipe grinderRecipe = builder.withInput( in )
|
||||
.withOutput( out )
|
||||
.withFirstOptional( optional, chance )
|
||||
.withTurns( turns )
|
||||
.build();
|
||||
|
||||
grinderRegistry.addRecipe( grinderRecipe );
|
||||
}
|
||||
else
|
||||
{
|
||||
final IGrinderRegistry grinderRegistry = AEApi.instance().registries().grinder();
|
||||
final IGrinderRecipeBuilder builder = grinderRegistry.builder();
|
||||
final IGrinderRecipe grinderRecipe = builder.withInput( in )
|
||||
.withOutput( out )
|
||||
.withTurns( turns )
|
||||
.build();
|
||||
|
||||
grinderRegistry.addRecipe( grinderRecipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/* Example:
|
||||
|
||||
NBTTagCompound msg = new NBTTagCompound();
|
||||
NBTTagCompound item = new NBTTagCompound();
|
||||
|
||||
new ItemStack( Blocks.anvil ).writeToNBT( item );
|
||||
msg.setTag( "item", item );
|
||||
msg.setDouble( "weight", 32.0 );
|
||||
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-mattercannon-ammo", msg );
|
||||
|
||||
*/
|
||||
|
||||
package appeng.core.api.imc;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.core.api.IIMCProcessor;
|
||||
|
||||
|
||||
public class IMCMatterCannon implements IIMCProcessor
|
||||
{
|
||||
|
||||
@Override
|
||||
public void process( final IMCMessage m )
|
||||
{
|
||||
final NBTTagCompound msg = m.getNBTValue();
|
||||
final NBTTagCompound item = (NBTTagCompound) msg.getTag( "item" );
|
||||
|
||||
final ItemStack ammo = new ItemStack( item );
|
||||
final double weight = msg.getDouble( "weight" );
|
||||
|
||||
if( ammo.isEmpty() )
|
||||
{
|
||||
throw new IllegalStateException( "invalid item in message " + m );
|
||||
}
|
||||
|
||||
AEApi.instance().registries().matterCannon().registerAmmo( ammo, weight );
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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>.
|
||||
*/
|
||||
|
||||
/* Example:
|
||||
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-me", new ItemStack( myBlockOrItem ) );
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-bc-power", new ItemStack( myBlockOrItem ) );
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-ic2-power", new ItemStack( myBlockOrItem ) );
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-redstone", new ItemStack( myBlockOrItem ) );
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-fluid", new ItemStack( myBlockOrItem ) );
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-item", new ItemStack( myBlockOrItem ) );
|
||||
|
||||
*/
|
||||
|
||||
package appeng.core.api.imc;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.core.api.IIMCProcessor;
|
||||
|
||||
|
||||
public class IMCP2PAttunement implements IIMCProcessor
|
||||
{
|
||||
|
||||
@Override
|
||||
public void process( final IMCMessage m )
|
||||
{
|
||||
final String key = m.key.substring( "add-p2p-attunement-".length() ).replace( '-', '_' ).toUpperCase( Locale.ENGLISH );
|
||||
|
||||
final TunnelType type = TunnelType.valueOf( key );
|
||||
|
||||
if( type != null )
|
||||
{
|
||||
final ItemStack is = m.getItemStackValue();
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
AEApi.instance().registries().p2pTunnel().addNewAttunement( is, type );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException( "invalid item in message " + m );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException( "invalid type in message " + m + " is not contained in " + Arrays.toString( TunnelType.values() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/* Example:
|
||||
|
||||
FMLInterModComms.sendMessage( "appliedenergistics2", "whitelist-spatial", "mymod.tileentities.MyTileEntity" );
|
||||
|
||||
*/
|
||||
|
||||
package appeng.core.api.imc;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.api.IIMCProcessor;
|
||||
|
||||
|
||||
public class IMCSpatial implements IIMCProcessor
|
||||
{
|
||||
|
||||
@Override
|
||||
public void process( final IMCMessage m )
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
final Class classInstance = Class.forName( m.getStringValue() );
|
||||
AEApi.instance().registries().movable().whiteListTileEntity( classInstance );
|
||||
}
|
||||
catch( final ClassNotFoundException e )
|
||||
{
|
||||
AELog.info( "Bad Class Registered: " + m.getStringValue() + " by " + m.getSender() );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user