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;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.client.MinecraftForgeClient;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.util.IOrientable;
|
|
|
|
import appeng.api.util.IOrientableBlock;
|
|
|
|
import appeng.block.misc.BlockLightDetector;
|
|
|
|
import appeng.block.misc.BlockSkyCompass;
|
|
|
|
import appeng.block.networking.BlockWireless;
|
|
|
|
import appeng.client.render.ItemRenderer;
|
|
|
|
import appeng.me.helpers.IGridProxyable;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class AEBaseItemBlock extends ItemBlock
|
|
|
|
{
|
|
|
|
|
|
|
|
final AEBaseBlock blockType;
|
|
|
|
|
2014-10-03 18:46:16 +02:00
|
|
|
public AEBaseItemBlock(Block id)
|
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super( id );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.blockType = (AEBaseBlock) id;
|
|
|
|
this.hasSubtypes = this.blockType.hasSubtypes;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
MinecraftForgeClient.registerItemRenderer( this, ItemRenderer.instance );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetadata(int dmg)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.hasSubtypes )
|
2014-09-24 02:26:27 +02:00
|
|
|
return dmg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack is)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.blockType.getUnlocalizedName( is );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-03 18:46:16 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public final void addInformation(ItemStack itemStack, EntityPlayer player, List toolTip, boolean advancedTooltips)
|
|
|
|
{
|
|
|
|
this.addCheckedInformation( itemStack, player, toolTip, advancedTooltips );
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addCheckedInformation(ItemStack itemStack, EntityPlayer player, List<String> toolTip, boolean advancedToolTips)
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-10-03 18:46:16 +02:00
|
|
|
this.blockType.addInformation( itemStack, player, toolTip, advancedToolTips );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
|
|
|
{
|
|
|
|
ForgeDirection up = ForgeDirection.UNKNOWN;
|
|
|
|
ForgeDirection forward = ForgeDirection.UNKNOWN;
|
|
|
|
|
|
|
|
IOrientable ori = null;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.blockType.hasBlockTileEntity() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.blockType instanceof BlockLightDetector )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
up = ForgeDirection.getOrientation( side );
|
|
|
|
if ( up == ForgeDirection.UP || up == ForgeDirection.DOWN )
|
|
|
|
forward = ForgeDirection.SOUTH;
|
|
|
|
else
|
|
|
|
forward = ForgeDirection.UP;
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
else if ( this.blockType instanceof BlockWireless || this.blockType instanceof BlockSkyCompass )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
forward = ForgeDirection.getOrientation( side );
|
|
|
|
if ( forward == ForgeDirection.UP || forward == ForgeDirection.DOWN )
|
|
|
|
up = ForgeDirection.SOUTH;
|
|
|
|
else
|
|
|
|
up = ForgeDirection.UP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
up = ForgeDirection.UP;
|
|
|
|
|
2014-09-28 20:56:16 +02:00
|
|
|
byte rotation = (byte) (MathHelper.floor_double( (player.rotationYaw * 4F) / 360F + 2.5D ) & 3);
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
switch (rotation)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
forward = ForgeDirection.SOUTH;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
forward = ForgeDirection.WEST;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
forward = ForgeDirection.NORTH;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
forward = ForgeDirection.EAST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( player.rotationPitch > 65 )
|
|
|
|
{
|
|
|
|
up = forward.getOpposite();
|
|
|
|
forward = ForgeDirection.UP;
|
|
|
|
}
|
|
|
|
else if ( player.rotationPitch < -65 )
|
|
|
|
{
|
|
|
|
up = forward.getOpposite();
|
|
|
|
forward = ForgeDirection.DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.blockType instanceof IOrientableBlock )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ori = ((IOrientableBlock) this.blockType).getOrientable( w, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
up = ForgeDirection.getOrientation( side );
|
|
|
|
forward = ForgeDirection.SOUTH;
|
|
|
|
if ( up.offsetY == 0 )
|
|
|
|
forward = ForgeDirection.UP;
|
|
|
|
|
|
|
|
ori.setOrientation( forward, up );
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( !this.blockType.isValidOrientation( w, x, y, z, forward, up ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) )
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.blockType.hasBlockTileEntity() && !(this.blockType instanceof BlockLightDetector) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AEBaseTile tile = this.blockType.getTileEntity( w, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
ori = tile;
|
|
|
|
|
|
|
|
if ( tile == null )
|
|
|
|
return true;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( ori.canBeRotated() && !this.blockType.hasCustomRotation() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
if ( ori.getForward() == null || ori.getUp() == null || // null
|
|
|
|
tile.getForward() == ForgeDirection.UNKNOWN || ori.getUp() == ForgeDirection.UNKNOWN )
|
|
|
|
ori.setOrientation( forward, up );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tile instanceof IGridProxyable )
|
|
|
|
{
|
|
|
|
((IGridProxyable) tile).getProxy().setOwner( player );
|
|
|
|
}
|
|
|
|
|
|
|
|
tile.onPlacement( stack, player, side );
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
else if ( this.blockType instanceof IOrientableBlock )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ori.setOrientation( forward, up );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|