2014-01-23 17:28:12 +01:00
|
|
|
package appeng.items.tools;
|
|
|
|
|
2014-02-16 22:28:50 +01:00
|
|
|
import java.io.IOException;
|
2014-01-23 17:28:12 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-16 22:28:50 +01:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2014-01-23 17:28:12 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.guiobjects.IGuiItem;
|
2014-01-23 20:41:11 +01:00
|
|
|
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IAEWrench;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.api.networking.IGridHost;
|
2014-02-16 22:28:50 +01:00
|
|
|
import appeng.client.ClientHelper;
|
2014-01-31 03:02:18 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
2014-02-16 22:28:50 +01:00
|
|
|
import appeng.core.AELog;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.sync.GuiBridge;
|
2014-02-16 22:28:50 +01:00
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
|
|
import appeng.core.sync.packets.PacketClick;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.items.AEBaseItem;
|
2014-01-26 07:48:09 +01:00
|
|
|
import appeng.items.contents.NetworkToolViewer;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
import buildcraft.api.tools.IToolWrench;
|
|
|
|
import cpw.mods.fml.common.Optional.Interface;
|
|
|
|
|
|
|
|
@Interface(iface = "buildcraft.api.tools.IToolWrench", modid = "BuildCraftAPI|core")
|
|
|
|
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench
|
|
|
|
{
|
|
|
|
|
|
|
|
public ToolNetworkTool() {
|
|
|
|
super( ToolNetworkTool.class, null );
|
|
|
|
setfeature( EnumSet.of( AEFeature.NetworkTool ) );
|
2014-02-01 23:25:50 +01:00
|
|
|
setMaxStackSize( 1 );
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-23 20:41:11 +01:00
|
|
|
public IGuiItemObject getGuiObject(ItemStack is, World world, int x, int y, int z)
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = world.getTileEntity( x, y, z );
|
2014-01-23 20:02:48 +01:00
|
|
|
return new NetworkToolViewer( is, (IGridHost) (te instanceof IGridHost ? te : null) );
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-16 22:28:50 +01:00
|
|
|
public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p)
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2014-02-16 22:28:50 +01:00
|
|
|
if ( Platform.isClient() )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2014-02-16 22:28:50 +01:00
|
|
|
MovingObjectPosition mop = ClientHelper.proxy.getMOP();
|
|
|
|
|
|
|
|
if ( mop == null )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2014-02-16 22:28:50 +01:00
|
|
|
onItemUseFirst( it, p, w, 0, 0, 0, -1, 0, 0, 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i = mop.blockX;
|
|
|
|
int j = mop.blockY;
|
|
|
|
int k = mop.blockZ;
|
|
|
|
|
|
|
|
if ( w.getBlock( i, j, k ).isAir( w, i, j, k ) )
|
|
|
|
onItemUseFirst( it, p, w, 0, 0, 0, -1, 0, 0, 0 );
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-16 22:28:50 +01:00
|
|
|
|
|
|
|
return it;
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-16 22:28:50 +01:00
|
|
|
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
2014-02-16 22:28:50 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketClick( x, y, z, side, hitX, hitY, hitZ ) );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2014-02-16 22:28:50 +01:00
|
|
|
public boolean serverSideToolLogic(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
|
|
|
if ( side >= 0 )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2014-02-16 22:28:50 +01:00
|
|
|
Block b = w.getBlock( x, y, z );
|
|
|
|
if ( b != null && !p.isSneaking() )
|
|
|
|
{
|
|
|
|
TileEntity te = w.getTileEntity( x, y, z );
|
|
|
|
if ( !(te instanceof IGridHost) )
|
|
|
|
{
|
|
|
|
if ( b.rotateBlock( w, x, y, z, ForgeDirection.getOrientation( side ) ) )
|
|
|
|
{
|
|
|
|
p.swingItem();
|
|
|
|
return !w.isRemote;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-31 03:02:18 +01:00
|
|
|
|
2014-02-16 22:28:50 +01:00
|
|
|
if ( !p.isSneaking() )
|
|
|
|
{
|
|
|
|
if ( p.openContainer instanceof AEBaseContainer )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
TileEntity te = w.getTileEntity( x, y, z );
|
|
|
|
if ( te instanceof IGridHost )
|
|
|
|
Platform.openGUI( p, te, ForgeDirection.getOrientation( side ), GuiBridge.GUI_NETWORK_STATUS );
|
|
|
|
else
|
|
|
|
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-23 17:28:12 +01:00
|
|
|
else
|
2014-02-16 22:28:50 +01:00
|
|
|
b.onBlockActivated( w, x, y, z, p, side, hitX, hitY, hitZ );
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
2014-02-16 22:28:50 +01:00
|
|
|
else
|
|
|
|
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
2014-01-23 17:28:12 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canWrench(ItemStack is, EntityPlayer player, int x, int y, int z)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canWrench(EntityPlayer player, int x, int y, int z)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void wrenchUsed(EntityPlayer player, int x, int y, int z)
|
|
|
|
{
|
|
|
|
player.swingItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|