Added Rotatable Blocks integration.

This commit is contained in:
AlgorithmX2 2014-04-03 23:12:35 -05:00
parent 26b1a2abf9
commit 27f374eb04
12 changed files with 176 additions and 44 deletions

View file

@ -48,6 +48,7 @@ import appeng.util.LookDirection;
import appeng.util.Platform;
import appeng.util.SettingsFrom;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -158,6 +159,11 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return getRendererInstance().getTexture( ForgeDirection.getOrientation( direction ) );
}
public IIcon unmappedGetIcon(IBlockAccess w, int x, int y, int z, int s)
{
return super.getIcon( w, x, y, z, s );
}
@Override
public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s)
{
@ -169,6 +175,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) );
GameRegistry.registerTileEntity( tileEntityType = c, FeatureFullname );
isInventory = IInventory.class.isAssignableFrom( c );
setTileProvider( hasBlockTileEntity() );
}
protected void setfeature(EnumSet<AEFeature> f)
@ -181,6 +188,13 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
setLightOpacity( 15 );
setLightLevel( 0 );
setHardness( 1.2F );
setTileProvider( false );
}
// update Block value.
private void setTileProvider(boolean b)
{
ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" );
}
protected AEBaseBlock(Class<?> c, Material mat, String subname) {
@ -231,12 +245,6 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return tileEntityType != null;
}
@Override
final public boolean hasTileEntity(int metadata)
{
return hasBlockTileEntity();
}
public Class<? extends TileEntity> getTileEntityClass()
{
return tileEntityType;
@ -267,14 +275,18 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
@Override
final public TileEntity createNewTileEntity(World var1, int var2)
{
try
if ( hasBlockTileEntity() )
{
return tileEntityType.newInstance();
}
catch (Throwable e)
{
throw new RuntimeException( e );
try
{
return tileEntityType.newInstance();
}
catch (Throwable e)
{
throw new RuntimeException( e );
}
}
return null;
}
final public <T extends TileEntity> T getTileEntity(IBlockAccess w, int x, int y, int z)
@ -294,7 +306,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return false;
}
protected void customRotateBlock(IOrientable rotateable, ForgeDirection axis)
protected void customRotateBlock(IOrientable rotatable, ForgeDirection axis)
{
}
@ -302,28 +314,28 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
@Override
final public boolean rotateBlock(World w, int x, int y, int z, ForgeDirection axis)
{
IOrientable rotateable = null;
IOrientable rotatable = null;
if ( hasBlockTileEntity() )
{
rotateable = (AEBaseTile) getTileEntity( w, x, y, z );
rotatable = (AEBaseTile) getTileEntity( w, x, y, z );
}
else if ( this instanceof IOrientableBlock )
{
rotateable = ((IOrientableBlock) this).getOrientable( w, x, y, z );
rotatable = ((IOrientableBlock) this).getOrientable( w, x, y, z );
}
if ( rotateable != null && rotateable.canBeRotated() )
if ( rotatable != null && rotatable.canBeRotated() )
{
if ( hasCustomRotation() )
{
customRotateBlock( rotateable, axis );
customRotateBlock( rotatable, axis );
return true;
}
else
{
ForgeDirection forward = rotateable.getForward();
ForgeDirection up = rotateable.getUp();
ForgeDirection forward = rotatable.getForward();
ForgeDirection up = rotatable.getUp();
for (int rs = 0; rs < 4; rs++)
{
@ -332,14 +344,14 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
if ( this.isValidOrientation( w, x, y, z, forward, up ) )
{
rotateable.setOrientation( forward, up );
rotatable.setOrientation( forward, up );
return true;
}
}
}
}
return false;
return super.rotateBlock( w, x, y, z, axis );
}
public ForgeDirection mapRotation(IOrientable ori, ForgeDirection dir)

View file

@ -0,0 +1,26 @@
package appeng.block;
import net.minecraft.block.material.Material;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
public class AEDecorativeBlock extends AEBaseBlock
{
protected AEDecorativeBlock(Class<?> c, Material mat) {
super( c, mat );
}
@Override
public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s)
{
return super.unmappedGetIcon( w, x, y, z, s );
}
@Override
public int getRenderType()
{
return 0;
}
}

View file

@ -37,11 +37,11 @@ public class BlockInterface extends AEBaseBlock
}
@Override
protected void customRotateBlock(IOrientable rotateable, ForgeDirection axis)
protected void customRotateBlock(IOrientable rotatable, ForgeDirection axis)
{
if ( rotateable instanceof TileInterface )
if ( rotatable instanceof TileInterface )
{
((TileInterface) rotateable).setSide( axis );
((TileInterface) rotatable).setSide( axis );
}
}

View file

@ -3,14 +3,10 @@ package appeng.block.solids;
import java.util.EnumSet;
import net.minecraft.block.material.Material;
import net.minecraft.world.IBlockAccess;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.block.AEDecorativeBlock;
import appeng.core.features.AEFeature;
import appeng.helpers.LocationRotation;
public class BlockFluix extends AEBaseBlock implements IOrientableBlock
public class BlockFluix extends AEDecorativeBlock
{
public BlockFluix() {
@ -18,10 +14,4 @@ public class BlockFluix extends AEBaseBlock implements IOrientableBlock
setfeature( EnumSet.of( AEFeature.DecorativeQuartzBlocks ) );
}
@Override
public IOrientable getOrientable(final IBlockAccess w, final int x, final int y, final int z)
{
return new LocationRotation( w, x, y, z );
}
}

View file

@ -3,10 +3,10 @@ package appeng.block.solids;
import java.util.EnumSet;
import net.minecraft.block.material.Material;
import appeng.block.AEBaseBlock;
import appeng.block.AEDecorativeBlock;
import appeng.core.features.AEFeature;
public class BlockQuartz extends AEBaseBlock
public class BlockQuartz extends AEDecorativeBlock
{
public BlockQuartz() {

View file

@ -3,10 +3,10 @@ package appeng.block.solids;
import java.util.EnumSet;
import net.minecraft.block.material.Material;
import appeng.block.AEBaseBlock;
import appeng.block.AEDecorativeBlock;
import appeng.core.features.AEFeature;
public class BlockQuartzChiseled extends AEBaseBlock
public class BlockQuartzChiseled extends AEDecorativeBlock
{
public BlockQuartzChiseled() {

View file

@ -9,23 +9,28 @@ import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import rblocks.api.RotatableBlockEnable;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.core.AppEng;
import appeng.core.WorldSettings;
import appeng.core.features.AEFeature;
import appeng.helpers.LocationRotation;
import appeng.helpers.NullRotation;
import appeng.integration.abstraction.IRB;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@RotatableBlockEnable
public class BlockSkyStone extends AEBaseBlock implements IOrientableBlock
{
@ -79,8 +84,20 @@ public class BlockSkyStone extends AEBaseBlock implements IOrientableBlock
@Override
public IOrientable getOrientable(final IBlockAccess w, final int x, final int y, final int z)
{
if ( AppEng.instance.isIntegrationEnabled( "RB" ) )
{
TileEntity te = w.getTileEntity( x, y, z );
if ( te != null )
{
IOrientable out = ((IRB) AppEng.instance.getIntegration( "RB" )).getOrientable( te );
if ( out != null )
return out;
}
}
if ( w.getBlockMetadata( x, y, z ) == 0 )
return new LocationRotation( w, x, y, z );
return new NullRotation();
}
@ -145,4 +162,10 @@ public class BlockSkyStone extends AEBaseBlock implements IOrientableBlock
WorldSettings.getInstance().getCompass().updateArea( w, x, y, z );
}
// use AE2's enderer, no rotatable blocks.
int getRealRenderType()
{
return getRenderType();
}
}

View file

@ -87,6 +87,7 @@ public class AppEng
// IntegrationSide.BOTH, "Forestry", "Forestry", "Forestry", // Forestry
// IntegrationSide.BOTH, "Mekanism", "Mekanism", "Mekanism", // MeK
IntegrationSide.CLIENT, "Waila", "Waila", "Waila", // Waila
IntegrationSide.BOTH, "Rotatable Blocks", "RotatableBlocks", "RB", // RB
IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks", "InvTweaks", // INV
IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems", "NEI", // NEI
IntegrationSide.CLIENT, "Craft Guide", "craftguide", "CraftGuide", // CraftGuide

View file

@ -43,6 +43,6 @@ public class LocationRotation implements IOrientable
@Override
public boolean canBeRotated()
{
return true;
return false;
}
}

View file

@ -0,0 +1,11 @@
package appeng.integration.abstraction;
import net.minecraft.tileentity.TileEntity;
import appeng.api.util.IOrientable;
public interface IRB
{
IOrientable getOrientable(TileEntity te);
}

View file

@ -0,0 +1,69 @@
package appeng.integration.modules;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import rblocks.api.IOrientable;
import appeng.integration.BaseModule;
import appeng.integration.abstraction.IRB;
public class RB extends BaseModule implements IRB
{
private class RBWrapper implements appeng.api.util.IOrientable
{
final private IOrientable internal;
public RBWrapper(IOrientable ww) {
internal = ww;
}
@Override
public boolean canBeRotated()
{
return internal.canBeRotated();
}
@Override
public ForgeDirection getForward()
{
return internal.getForward();
}
@Override
public ForgeDirection getUp()
{
return internal.getUp();
}
@Override
public void setOrientation(ForgeDirection Forward, ForgeDirection Up)
{
internal.setOrientation( Forward, Up );
}
};
public static RB instance;
@Override
public void Init() throws Throwable
{
TestClass( IOrientable.class );
}
@Override
public void PostInit() throws Throwable
{
}
@Override
public appeng.api.util.IOrientable getOrientable(TileEntity te)
{
if ( te instanceof IOrientable )
return new RBWrapper( (IOrientable) te );
return null;
}
}

View file

@ -240,7 +240,7 @@ public class AdaptorIInventory extends InventoryAdaptor
}
else if ( is != null )
{
if ( Platform.isSameItem( is, left ) )
if ( Platform.isSameItemPrecise( is, left ) )
{
if ( is.stackSize < stack_limit )
{
@ -303,7 +303,7 @@ public class AdaptorIInventory extends InventoryAdaptor
}
else
{
if ( Platform.isSameItem( is, left ) )
if ( Platform.isSameItemPrecise( is, left ) )
{
if ( is.stackSize < stack_limit )
{