2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* 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>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.block;
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2015-03-29 09:33:06 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.client.resources.IResource;
|
2014-10-03 17:05:21 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-10-03 17:05:21 +02:00
|
|
|
import net.minecraft.item.Item;
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
import com.google.common.base.Optional;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.implementations.items.IMemoryCard;
|
|
|
|
import appeng.api.implementations.items.MemoryCardMessages;
|
|
|
|
import appeng.api.implementations.tiles.IColorableTile;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.IOrientable;
|
|
|
|
import appeng.api.util.IOrientableBlock;
|
|
|
|
import appeng.block.networking.BlockCableBus;
|
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.render.BlockRenderInfo;
|
|
|
|
import appeng.client.render.WorldRender;
|
2014-11-18 16:47:30 +01:00
|
|
|
import appeng.client.texture.FlippableIcon;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.client.texture.MissingIcon;
|
2014-11-18 16:47:30 +01:00
|
|
|
import appeng.core.features.AEBlockFeatureHandler;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-11-18 16:47:30 +01:00
|
|
|
import appeng.core.features.FeatureNameExtractor;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.core.features.IAEFeature;
|
2014-11-18 16:47:30 +01:00
|
|
|
import appeng.core.features.IFeatureHandler;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.core.features.ItemStackSrc;
|
|
|
|
import appeng.helpers.AEGlassMaterial;
|
|
|
|
import appeng.helpers.ICustomCollision;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.tile.networking.TileCableBus;
|
|
|
|
import appeng.tile.storage.TileSkyChest;
|
|
|
|
import appeng.util.LookDirection;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.SettingsFrom;
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
public class AEBaseBlock extends BlockContainer implements IAEFeature
|
|
|
|
{
|
2014-09-29 09:54:34 +02:00
|
|
|
private final String featureFullName;
|
2014-11-18 16:47:30 +01:00
|
|
|
private final Optional<String> featureSubName;
|
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public IIcon renderIcon;
|
2014-09-24 02:26:27 +02:00
|
|
|
protected boolean isOpaque = true;
|
|
|
|
protected boolean isFullSize = true;
|
|
|
|
protected boolean hasSubtypes = false;
|
|
|
|
protected boolean isInventory = false;
|
2014-11-18 16:47:30 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
2014-09-24 02:26:27 +02:00
|
|
|
BlockRenderInfo renderInfo;
|
2014-11-18 16:47:30 +01:00
|
|
|
private IFeatureHandler handler;
|
2015-03-29 09:33:06 +02:00
|
|
|
|
|
|
|
@Nullable
|
2014-11-18 16:47:30 +01:00
|
|
|
private Class<? extends TileEntity> tileEntityType = null;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
protected AEBaseBlock( Class<? extends AEBaseBlock> c, Material mat )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
this( c, mat, Optional.<String>absent() );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setLightOpacity( 255 );
|
|
|
|
this.setLightLevel( 0 );
|
|
|
|
this.setHardness( 2.2F );
|
|
|
|
this.setTileProvider( false );
|
|
|
|
this.setHarvestLevel( "pickaxe", 0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
protected AEBaseBlock( Class<?> c, Material mat, Optional<String> subName )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
super( mat );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( mat == AEGlassMaterial.INSTANCE || mat == Material.glass )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setStepSound( Block.soundTypeGlass );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
else if( mat == Material.rock )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setStepSound( Block.soundTypeStone );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
else if( mat == Material.wood )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setStepSound( Block.soundTypeWood );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setStepSound( Block.soundTypeMetal );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.featureFullName = new FeatureNameExtractor( c, subName ).get();
|
|
|
|
this.featureSubName = subName;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
// update Block value.
|
|
|
|
private void setTileProvider( boolean b )
|
|
|
|
{
|
|
|
|
ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" );
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
public String toString()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.featureFullName;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void registerNoIcons()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
BlockRenderInfo info = this.getRendererInstance();
|
2014-09-24 02:26:27 +02:00
|
|
|
FlippableIcon i = new FlippableIcon( new MissingIcon( this ) );
|
|
|
|
info.updateIcons( i, i, i, i, i, i );
|
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public BlockRenderInfo getRendererInstance()
|
|
|
|
{
|
|
|
|
if( this.renderInfo != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
return this.renderInfo;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
final BaseBlockRender renderer = this.getRenderer().newInstance();
|
|
|
|
this.renderInfo = new BlockRenderInfo( renderer );
|
|
|
|
|
|
|
|
return this.renderInfo;
|
|
|
|
}
|
|
|
|
catch ( InstantiationException e )
|
|
|
|
{
|
|
|
|
throw new IllegalStateException( "Failed to create a new instance of an illegal class " + this.getRenderer(), e );
|
2015-03-29 09:33:06 +02:00
|
|
|
}
|
2015-03-23 10:14:35 +01:00
|
|
|
catch( IllegalAccessException e )
|
2015-03-29 09:33:06 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Failed to create a new instance of " + this.getRenderer() + " because of permissions.", e );
|
2015-03-29 09:33:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
protected Class<? extends BaseBlockRender> getRenderer()
|
|
|
|
{
|
|
|
|
return BaseBlockRender.class;
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
public IIcon unmappedGetIcon( IBlockAccess w, int x, int y, int z, int s )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return super.getIcon( w, x, y, z, s );
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
protected void setTileEntity( Class<? extends TileEntity> c )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
this.tileEntityType = c;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) );
|
2015-03-29 09:33:06 +02:00
|
|
|
GameRegistry.registerTileEntity( this.tileEntityType, this.featureFullName );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.isInventory = IInventory.class.isAssignableFrom( c );
|
|
|
|
this.setTileProvider( this.hasBlockTileEntity() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
public boolean hasBlockTileEntity()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
return this.tileEntityType != null;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
protected void setFeature( EnumSet<AEFeature> f )
|
|
|
|
{
|
|
|
|
this.handler = new AEBlockFeatureHandler( f, this, this.featureSubName );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final IFeatureHandler handler()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.handler;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
public void postInit()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
// override!
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
public boolean isOpaque()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.isOpaque;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean renderAsNormalBlock()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.isFullSize && this.isOpaque;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public int getRenderType()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
return WorldRender.INSTANCE.getRenderId();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
public IIcon getIcon( IBlockAccess w, int x, int y, int z, int s )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getIcon( this.mapRotation( w, x, y, z, s ), w.getBlockMetadata( x, y, z ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public IIcon getIcon( int direction, int metadata )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.renderIcon != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.renderIcon;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getRendererInstance().getTexture( ForgeDirection.getOrientation( direction ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings( "unchecked" )
|
|
|
|
// NOTE: WAS FINAL, changed for Immibis
|
|
|
|
public void addCollisionBoxesToList( World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
ICustomCollision collisionHandler = null;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this instanceof ICustomCollision )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
collisionHandler = (ICustomCollision) this;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile te = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te instanceof ICustomCollision )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
collisionHandler = (ICustomCollision) te;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( collisionHandler != null && bb != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
List<AxisAlignedBB> tmp = new ArrayList<AxisAlignedBB>();
|
|
|
|
collisionHandler.addCollidingBlockToList( w, x, y, z, bb, tmp, e );
|
2015-03-29 09:33:06 +02:00
|
|
|
for( AxisAlignedBB b : tmp )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
b.minX += x;
|
|
|
|
b.minY += y;
|
|
|
|
b.minZ += z;
|
|
|
|
b.maxX += x;
|
|
|
|
b.maxY += y;
|
|
|
|
b.maxZ += z;
|
2015-03-29 09:33:06 +02:00
|
|
|
if( bb.intersectsWith( b ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
out.add( b );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
super.addCollisionBoxesToList( w, x, y, z, bb, out, e );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
2015-04-06 00:35:42 +02:00
|
|
|
public final AxisAlignedBB getSelectedBoundingBoxFromPool( World w, int x, int y, int z )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
ICustomCollision collisionHandler = null;
|
|
|
|
AxisAlignedBB b = null;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this instanceof ICustomCollision )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
collisionHandler = (ICustomCollision) this;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile te = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te instanceof ICustomCollision )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
collisionHandler = (ICustomCollision) te;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( collisionHandler != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( Platform.isClient() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
LookDirection ld = Platform.getPlayerRay( player, Platform.getEyeOffset( player ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
Iterable<AxisAlignedBB> bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, Minecraft.getMinecraft().thePlayer, true );
|
|
|
|
AxisAlignedBB br = null;
|
|
|
|
|
|
|
|
double lastDist = 0;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
for( AxisAlignedBB bb : bbs )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
this.setBlockBounds( (float) bb.minX, (float) bb.minY, (float) bb.minZ, (float) bb.maxX, (float) bb.maxY, (float) bb.maxZ );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
MovingObjectPosition r = super.collisionRayTrace( w, x, y, z, ld.a, ld.b );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setBlockBounds( 0, 0, 0, 1, 1, 1 );
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( r != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
double xLen = ( ld.a.xCoord - r.hitVec.xCoord );
|
|
|
|
double yLen = ( ld.a.yCoord - r.hitVec.yCoord );
|
|
|
|
double zLen = ( ld.a.zCoord - r.hitVec.zCoord );
|
|
|
|
|
|
|
|
double thisDist = xLen * xLen + yLen * yLen + zLen * zLen;
|
2015-03-29 09:33:06 +02:00
|
|
|
if( br == null || lastDist > thisDist )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
lastDist = thisDist;
|
|
|
|
br = bb;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( br != null )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
br.setBounds( br.minX + x, br.minY + y, br.minZ + z, br.maxX + x, br.maxY + y, br.maxZ + z );
|
|
|
|
return br;
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
for( AxisAlignedBB bx : collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, false ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( b == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
b = bx;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
double minX = Math.min( b.minX, bx.minX );
|
|
|
|
double minY = Math.min( b.minY, bx.minY );
|
|
|
|
double minZ = Math.min( b.minZ, bx.minZ );
|
|
|
|
double maxX = Math.max( b.maxX, bx.maxX );
|
|
|
|
double maxY = Math.max( b.maxY, bx.maxY );
|
|
|
|
double maxZ = Math.max( b.maxZ, bx.maxZ );
|
|
|
|
b.setBounds( minX, minY, minZ, maxX, maxY, maxZ );
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
b.setBounds( b.minX + x, b.minY + y, b.minZ + z, b.maxX + x, b.maxY + y, b.maxZ + z );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
b = super.getSelectedBoundingBoxFromPool( w, x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
return b;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final boolean isOpaqueCube()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.isOpaque;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
public MovingObjectPosition collisionRayTrace( World w, int x, int y, int z, Vec3 a, Vec3 b )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ICustomCollision collisionHandler = null;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this instanceof ICustomCollision )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
collisionHandler = (ICustomCollision) this;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile te = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te instanceof ICustomCollision )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
collisionHandler = (ICustomCollision) te;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( collisionHandler != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
Iterable<AxisAlignedBB> bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, true );
|
|
|
|
MovingObjectPosition br = null;
|
|
|
|
|
|
|
|
double lastDist = 0;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
for( AxisAlignedBB bb : bbs )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
this.setBlockBounds( (float) bb.minX, (float) bb.minY, (float) bb.minZ, (float) bb.maxX, (float) bb.maxY, (float) bb.maxZ );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
MovingObjectPosition r = super.collisionRayTrace( w, x, y, z, a, b );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setBlockBounds( 0, 0, 0, 1, 1, 1 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( r != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
double xLen = ( a.xCoord - r.hitVec.xCoord );
|
|
|
|
double yLen = ( a.yCoord - r.hitVec.yCoord );
|
|
|
|
double zLen = ( a.zCoord - r.hitVec.zCoord );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
double thisDist = xLen * xLen + yLen * yLen + zLen * zLen;
|
2015-03-29 09:33:06 +02:00
|
|
|
if( br == null || lastDist > thisDist )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
lastDist = thisDist;
|
|
|
|
br = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( br != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return br;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setBlockBounds( 0, 0, 0, 1, 1, 1 );
|
2014-09-24 02:26:27 +02:00
|
|
|
return super.collisionRayTrace( w, x, y, z, a, b );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final boolean onBlockActivated( World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( player != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ItemStack is = player.inventory.getCurrentItem();
|
2015-03-29 09:33:06 +02:00
|
|
|
if( is != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( Platform.isWrench( player, is, x, y, z ) && player.isSneaking() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
Block id = w.getBlock( x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( id != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile tile = this.getTileEntity( w, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
ItemStack[] drops = Platform.getBlockDrops( w, x, y, z );
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( tile == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( tile instanceof TileCableBus || tile instanceof TileSkyChest )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
ItemStack op = new ItemStack( this );
|
2015-03-29 09:33:06 +02:00
|
|
|
for( ItemStack ol : drops )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( Platform.isSameItemType( ol, op ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
NBTTagCompound tag = tile.downloadSettings( SettingsFrom.DISMANTLE_ITEM );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( tag != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
ol.setTagCompound( tag );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( id.removedByPlayer( w, player, x, y, z, false ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
List<ItemStack> l = Lists.newArrayList( drops );
|
2014-09-24 02:26:27 +02:00
|
|
|
Platform.spawnDrops( w, x, y, z, l );
|
|
|
|
w.setBlockToAir( x, y, z );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( is.getItem() instanceof IMemoryCard && !( this instanceof BlockCableBus ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
IMemoryCard memoryCard = (IMemoryCard) is.getItem();
|
|
|
|
if( player.isSneaking() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile t = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( t != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
String name = this.getUnlocalizedName();
|
2014-09-24 02:26:27 +02:00
|
|
|
NBTTagCompound data = t.downloadSettings( SettingsFrom.MEMORY_CARD );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( data != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
memoryCard.setMemoryCardContents( is, name, data );
|
|
|
|
memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
2014-09-24 02:26:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
String name = memoryCard.getSettingsName( is );
|
|
|
|
NBTTagCompound data = memoryCard.getData( is );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.getUnlocalizedName().equals( name ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile t = this.getTileEntity( w, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
t.uploadSettings( SettingsFrom.MEMORY_CARD, data );
|
2014-09-28 11:47:17 +02:00
|
|
|
memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
memoryCard.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.onActivated( w, x, y, z, player, side, hitX, hitY, hitZ );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
public boolean onActivated( World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return false;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy( World w, int x, int y, int z, EntityLivingBase player, ItemStack is )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( is.hasDisplayName() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
TileEntity te = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te instanceof AEBaseTile )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
( (AEBaseTile) w.getTileEntity( x, y, z ) ).setName( is.getDisplayName() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
@SuppressWarnings( "unchecked" )
|
|
|
|
public final void getSubBlocks( Item item, CreativeTabs tabs, List itemStacks )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
this.getCheckedSubBlocks( item, tabs, itemStacks );
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasComparatorInputOverride()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.isInventory;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
|
|
|
public int getComparatorInputOverride( World w, int x, int y, int z, int s )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
TileEntity te = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te instanceof IInventory )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
return Container.calcRedstoneFromInventory( (IInventory) te );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
return 0;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public void registerBlockIcons( IIconRegister iconRegistry )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
BlockRenderInfo info = this.getRendererInstance();
|
2014-11-18 16:47:30 +01:00
|
|
|
FlippableIcon topIcon;
|
|
|
|
FlippableIcon bottomIcon;
|
|
|
|
FlippableIcon sideIcon;
|
|
|
|
FlippableIcon eastIcon;
|
|
|
|
FlippableIcon westIcon;
|
|
|
|
FlippableIcon southIcon;
|
|
|
|
FlippableIcon northIcon;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.blockIcon = topIcon = this.optionalIcon( iconRegistry, this.getTextureName(), null );
|
|
|
|
bottomIcon = this.optionalIcon( iconRegistry, this.getTextureName() + "Bottom", topIcon );
|
|
|
|
sideIcon = this.optionalIcon( iconRegistry, this.getTextureName() + "Side", topIcon );
|
|
|
|
eastIcon = this.optionalIcon( iconRegistry, this.getTextureName() + "East", sideIcon );
|
|
|
|
westIcon = this.optionalIcon( iconRegistry, this.getTextureName() + "West", sideIcon );
|
|
|
|
southIcon = this.optionalIcon( iconRegistry, this.getTextureName() + "Front", sideIcon );
|
|
|
|
northIcon = this.optionalIcon( iconRegistry, this.getTextureName() + "Back", sideIcon );
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
info.updateIcons( bottomIcon, topIcon, northIcon, southIcon, eastIcon, westIcon );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final boolean isNormalCube( IBlockAccess world, int x, int y, int z )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.isFullSize;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final boolean rotateBlock( World w, int x, int y, int z, ForgeDirection axis )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
IOrientable rotatable = null;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.hasBlockTileEntity() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
rotatable = (AEBaseTile) this.getTileEntity( w, x, y, z );
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
else if( this instanceof IOrientableBlock )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
rotatable = ( (IOrientableBlock) this ).getOrientable( w, x, y, z );
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( rotatable != null && rotatable.canBeRotated() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.hasCustomRotation() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.customRotateBlock( rotatable, axis );
|
2014-11-18 16:47:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ForgeDirection forward = rotatable.getForward();
|
|
|
|
ForgeDirection up = rotatable.getUp();
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
for( int rs = 0; rs < 4; rs++ )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
forward = Platform.rotateAround( forward, axis );
|
|
|
|
up = Platform.rotateAround( up, axis );
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.isValidOrientation( w, x, y, z, forward, up ) )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
rotatable.setOrientation( forward, up );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.rotateBlock( w, x, y, z, axis );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean hasCustomRotation()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void customRotateBlock( IOrientable rotatable, ForgeDirection axis )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValidOrientation( World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up )
|
|
|
|
{
|
|
|
|
return true;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final ForgeDirection[] getValidRotations( World w, int x, int y, int z )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.hasBlockTileEntity() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile obj = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( obj != null && obj.canBeRotated() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
return ForgeDirection.VALID_DIRECTIONS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ForgeDirection[0];
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
public boolean recolourBlock( World world, int x, int y, int z, ForgeDirection side, int colour )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
TileEntity te = this.getTileEntity( world, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te instanceof IColorableTile )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
IColorableTile ct = (IColorableTile) te;
|
2014-09-24 02:26:27 +02:00
|
|
|
AEColor c = ct.getColor();
|
|
|
|
AEColor newColor = AEColor.values()[colour];
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( c != newColor )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ct.recolourBlock( side, newColor, null );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.recolourBlock( world, x, y, z, side, colour );
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
private FlippableIcon optionalIcon( IIconRegister ir, String Name, IIcon substitute )
|
|
|
|
{
|
|
|
|
// if the input is an flippable IIcon find the original.
|
2015-03-29 09:33:06 +02:00
|
|
|
while( substitute instanceof FlippableIcon )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
substitute = ( (FlippableIcon) substitute ).getOriginal();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( substitute != null )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ResourceLocation resLoc = new ResourceLocation( Name );
|
2015-03-29 09:33:06 +02:00
|
|
|
resLoc = new ResourceLocation( resLoc.getResourceDomain(), String.format( "%s/%s%s", "textures/blocks", resLoc.getResourcePath(), ".png" ) );
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
IResource res = Minecraft.getMinecraft().getResourceManager().getResource( resLoc );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( res != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return new FlippableIcon( ir.registerIcon( Name ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
catch( Throwable e )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
return new FlippableIcon( substitute );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new FlippableIcon( ir.registerIcon( Name ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public void getCheckedSubBlocks( Item item, CreativeTabs tabs, List<ItemStack> itemStacks )
|
|
|
|
{
|
|
|
|
super.getSubBlocks( item, tabs, itemStacks );
|
|
|
|
}
|
|
|
|
|
|
|
|
int mapRotation( IBlockAccess w, int x, int y, int z, int s )
|
|
|
|
{
|
|
|
|
IOrientable ori = null;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.hasBlockTileEntity() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
ori = (AEBaseTile) this.getTileEntity( w, x, y, z );
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
else if( this instanceof IOrientableBlock )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
ori = ( (IOrientableBlock) this ).getOrientable( w, x, y, z );
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( ori != null && ori.canBeRotated() )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.mapRotation( ori, ForgeDirection.getOrientation( s ) ).ordinal();
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
@Nullable
|
2014-11-18 16:47:30 +01:00
|
|
|
public <T extends TileEntity> T getTileEntity( IBlockAccess w, int x, int y, int z )
|
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( !this.hasBlockTileEntity() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
TileEntity te = w.getTileEntity( x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.tileEntityType.isInstance( te ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
return (T) te;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ForgeDirection mapRotation( IOrientable ori, ForgeDirection dir )
|
|
|
|
{
|
|
|
|
// case DOWN: return bottomIcon;
|
|
|
|
// case UP: return blockIcon;
|
|
|
|
// case NORTH: return northIcon;
|
|
|
|
// case SOUTH: return southIcon;
|
|
|
|
// case WEST: return sideIcon;
|
|
|
|
// case EAST: return sideIcon;
|
|
|
|
|
|
|
|
ForgeDirection forward = ori.getForward();
|
|
|
|
ForgeDirection up = ori.getUp();
|
|
|
|
ForgeDirection west = ForgeDirection.UNKNOWN;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( forward == null || up == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return dir;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
int west_x = forward.offsetY * up.offsetZ - forward.offsetZ * up.offsetY;
|
|
|
|
int west_y = forward.offsetZ * up.offsetX - forward.offsetX * up.offsetZ;
|
|
|
|
int west_z = forward.offsetX * up.offsetY - forward.offsetY * up.offsetX;
|
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
for( ForgeDirection dx : ForgeDirection.VALID_DIRECTIONS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dx.offsetX == west_x && dx.offsetY == west_y && dx.offsetZ == west_z )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
west = dx;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dir == forward )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return ForgeDirection.SOUTH;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dir == forward.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return ForgeDirection.NORTH;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dir == up )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return ForgeDirection.UP;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dir == up.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return ForgeDirection.DOWN;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dir == west )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return ForgeDirection.WEST;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
if( dir == west.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
return ForgeDirection.EAST;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Class<? extends TileEntity> getTileEntityClass()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.tileEntityType;
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public void setRenderStateByMeta( int itemDamage )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-04-06 00:35:42 +02:00
|
|
|
public final TileEntity createNewTileEntity( World var1, int var2 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-29 09:33:06 +02:00
|
|
|
if( this.hasBlockTileEntity() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.tileEntityType.newInstance();
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
catch( InstantiationException e )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Failed to create a new instance of an illegal class " + this.tileEntityType , e );
|
2015-03-29 09:33:06 +02:00
|
|
|
}
|
|
|
|
catch( IllegalAccessException e )
|
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Failed to create a new instance of " + this.tileEntityType + ", because lack of permissions", e );
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-03-29 09:33:06 +02:00
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
return null;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-10-03 17:05:21 +02:00
|
|
|
@Override
|
2014-11-18 16:47:30 +01:00
|
|
|
public void breakBlock( World w, int x, int y, int z, Block a, int b )
|
2014-10-03 17:05:21 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile te = this.getTileEntity( w, x, y, z );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te != null )
|
2014-11-18 16:47:30 +01:00
|
|
|
{
|
|
|
|
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te.dropItems() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
te.getDrops( w, x, y, z, drops );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
te.getNoDrops( w, x, y, z, drops );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-11-18 16:47:30 +01:00
|
|
|
|
|
|
|
// Cry ;_; ...
|
|
|
|
Platform.spawnDrops( w, x, y, z, drops );
|
|
|
|
}
|
|
|
|
|
|
|
|
super.breakBlock( w, x, y, z, a, b );
|
2015-03-29 09:33:06 +02:00
|
|
|
if( te != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-11-18 16:47:30 +01:00
|
|
|
w.setTileEntity( x, y, z, null );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-10-03 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:47:30 +01:00
|
|
|
public String getUnlocalizedName( ItemStack is )
|
2014-10-03 17:05:21 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getUnlocalizedName();
|
2014-11-18 16:47:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addInformation( ItemStack is, EntityPlayer player, List<String> lines, boolean advancedItemTooltips )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public Class<? extends AEBaseItemBlock> getItemBlockClass()
|
|
|
|
{
|
|
|
|
return AEBaseItemBlock.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasSubtypes()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.hasSubtypes;
|
2014-10-03 17:05:21 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|