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-01-01 09:58:31 +01:00
|
|
|
package appeng.debug;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-01-01 09:58:31 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.command.ICommandSender;
|
2014-01-01 09:58:31 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.ChatComponentText;
|
2014-01-01 09:58:31 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-01-01 09:58:31 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.spatial.ISpatialCache;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-01-01 09:58:31 +01:00
|
|
|
public class ToolReplicatorCard extends AEBaseItem
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
public ToolReplicatorCard()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) );
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-01 09:58:31 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( player.isSneaking() )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( world.getTileEntity( x, y, z ) instanceof IGridHost )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
tag.setInteger( "x", x );
|
|
|
|
tag.setInteger( "y", y );
|
|
|
|
tag.setInteger( "z", z );
|
|
|
|
tag.setInteger( "side", side );
|
|
|
|
tag.setInteger( "dimid", world.provider.dimensionId );
|
|
|
|
stack.setTagCompound( tag );
|
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "This is not a Grid Tile." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NBTTagCompound ish = stack.getTagCompound();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ish != null )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
|
|
|
int src_x = ish.getInteger( "x" );
|
|
|
|
int src_y = ish.getInteger( "y" );
|
|
|
|
int src_z = ish.getInteger( "z" );
|
|
|
|
int src_side = ish.getInteger( "side" );
|
|
|
|
int dimid = ish.getInteger( "dimid" );
|
|
|
|
World src_w = DimensionManager.getWorld( dimid );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = src_w.getTileEntity( src_x, src_y, src_z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IGridHost )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
|
|
|
IGridHost gh = (IGridHost) te;
|
|
|
|
ForgeDirection sideOff = ForgeDirection.getOrientation( src_side );
|
|
|
|
ForgeDirection currentSideOff = ForgeDirection.getOrientation( side );
|
|
|
|
IGridNode n = gh.getGridNode( sideOff );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( n != null )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
|
|
|
IGrid g = n.getGrid();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( g != null )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
|
|
|
ISpatialCache sc = g.getCache( ISpatialCache.class );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sc.isValidRegion() )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
|
|
|
DimensionalCoord min = sc.getMin();
|
|
|
|
DimensionalCoord max = sc.getMax();
|
|
|
|
|
|
|
|
x += currentSideOff.offsetX;
|
|
|
|
y += currentSideOff.offsetY;
|
|
|
|
z += currentSideOff.offsetZ;
|
|
|
|
|
|
|
|
int min_x = min.x;
|
|
|
|
int min_y = min.y;
|
|
|
|
int min_z = min.z;
|
|
|
|
|
|
|
|
int rel_x = min.x - src_x + x;
|
|
|
|
int rel_y = min.y - src_y + y;
|
|
|
|
int rel_z = min.z - src_z + z;
|
|
|
|
|
|
|
|
int scale_x = max.x - min.x;
|
|
|
|
int scale_y = max.y - min.y;
|
|
|
|
int scale_z = max.z - min.z;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = 1; i < scale_x; i++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = 1; j < scale_y; j++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int k = 1; k < scale_z; k++ )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
Block blk = src_w.getBlock( min_x + i, min_y + j, min_z + k );
|
2014-01-01 09:58:31 +01:00
|
|
|
int meta = src_w.getBlockMetadata( min_x + i, min_y + j, min_z + k );
|
2014-02-09 02:34:52 +01:00
|
|
|
world.setBlock( i + rel_x, j + rel_y, k + rel_z, blk, meta, 4 );
|
2014-01-01 09:58:31 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk != null && blk.hasTileEntity( meta ) )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity ote = src_w.getTileEntity( min_x + i, min_y + j, min_z + k );
|
2014-01-01 09:58:31 +01:00
|
|
|
TileEntity nte = blk.createTileEntity( world, meta );
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
|
|
ote.writeToNBT( data );
|
2014-01-20 17:41:37 +01:00
|
|
|
nte.readFromNBT( (NBTTagCompound) data.copy() );
|
2014-02-09 02:34:52 +01:00
|
|
|
world.setTileEntity( i + rel_x, j + rel_y, k + rel_z, nte );
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
world.markBlockForUpdate( i + rel_x, j + rel_y, k + rel_z );
|
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "requires valid spatial pylon setup." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "no grid?" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "No grid node?" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "Src is no longer a grid block?" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "No Source Defined" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private void outputMsg( ICommandSender player, String string )
|
2014-01-01 09:58:31 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
player.addChatMessage( new ChatComponentText( string ) );
|
2014-01-01 09:58:31 +01:00
|
|
|
}
|
|
|
|
}
|