Network tool is now powered by black magic.
This commit is contained in:
parent
f5a2f6652e
commit
02f2eb00bd
6 changed files with 151 additions and 34 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.client.particle.EntityFX;
|
||||||
import net.minecraft.client.renderer.entity.RenderManager;
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
@ -115,4 +116,10 @@ public class ClientHelper extends ServerHelper
|
||||||
return r.nextInt( 2 * (setting + 1) ) == 0;
|
return r.nextInt( 2 * (setting + 1) ) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MovingObjectPosition getMOP()
|
||||||
|
{
|
||||||
|
return Minecraft.getMinecraft().objectMouseOver;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import appeng.block.AEBaseBlock;
|
import appeng.block.AEBaseBlock;
|
||||||
import appeng.core.sync.AppEngPacket;
|
import appeng.core.sync.AppEngPacket;
|
||||||
|
@ -31,4 +32,6 @@ public abstract class CommonHelper
|
||||||
|
|
||||||
public abstract boolean shouldAddParticles(Random r);
|
public abstract boolean shouldAddParticles(Random r);
|
||||||
|
|
||||||
|
public abstract MovingObjectPosition getMOP();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import appeng.core.sync.packets.PacketClick;
|
||||||
import appeng.core.sync.packets.PacketConfigButton;
|
import appeng.core.sync.packets.PacketConfigButton;
|
||||||
import appeng.core.sync.packets.PacketInventoryAction;
|
import appeng.core.sync.packets.PacketInventoryAction;
|
||||||
import appeng.core.sync.packets.PacketLightning;
|
import appeng.core.sync.packets.PacketLightning;
|
||||||
|
@ -49,6 +50,8 @@ public class AppEngPacketHandlerBase
|
||||||
|
|
||||||
PACKET_PROGRESS_VALUE(PacketProgressBar.class),
|
PACKET_PROGRESS_VALUE(PacketProgressBar.class),
|
||||||
|
|
||||||
|
PACKET_CLICK(PacketClick.class),
|
||||||
|
|
||||||
PACKET_SWITCH_GUIS(PacketSwitchGuis.class);
|
PACKET_SWITCH_GUIS(PacketSwitchGuis.class);
|
||||||
|
|
||||||
final public Class pc;
|
final public Class pc;
|
||||||
|
|
58
core/sync/packets/PacketClick.java
Normal file
58
core/sync/packets/PacketClick.java
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
package appeng.core.sync.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import appeng.core.sync.AppEngPacket;
|
||||||
|
import appeng.core.sync.network.INetworkInfo;
|
||||||
|
import appeng.items.tools.ToolNetworkTool;
|
||||||
|
|
||||||
|
public class PacketClick extends AppEngPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
int x, y, z, side;
|
||||||
|
float hitX, hitY, hitZ;
|
||||||
|
|
||||||
|
// automatic.
|
||||||
|
public PacketClick(ByteBuf stream) throws IOException {
|
||||||
|
x = stream.readInt();
|
||||||
|
y = stream.readInt();
|
||||||
|
z = stream.readInt();
|
||||||
|
side = stream.readInt();
|
||||||
|
hitX = stream.readFloat();
|
||||||
|
hitY = stream.readFloat();
|
||||||
|
hitZ = stream.readFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
|
||||||
|
{
|
||||||
|
ItemStack is = player.inventory.getCurrentItem();
|
||||||
|
if ( is != null && is.getItem() instanceof ToolNetworkTool )
|
||||||
|
{
|
||||||
|
ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
|
||||||
|
tnt.serverSideToolLogic( is, player, player.worldObj, x, y, z, side, hitX, hitY, hitZ );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// api
|
||||||
|
public PacketClick(int x, int y, int z, int side, float hitX, float hitY, float hitZ) throws IOException {
|
||||||
|
|
||||||
|
ByteBuf data = Unpooled.buffer();
|
||||||
|
|
||||||
|
data.writeInt( getPacketID() );
|
||||||
|
data.writeInt( this.x = x );
|
||||||
|
data.writeInt( this.y = y );
|
||||||
|
data.writeInt( this.z = z );
|
||||||
|
data.writeInt( this.side = side );
|
||||||
|
data.writeFloat( this.hitX = hitX );
|
||||||
|
data.writeFloat( this.hitY = hitY );
|
||||||
|
data.writeFloat( this.hitZ = hitZ );
|
||||||
|
|
||||||
|
configureWrite( data );
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,26 @@
|
||||||
package appeng.items.tools;
|
package appeng.items.tools;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import appeng.api.implementations.guiobjects.IGuiItem;
|
import appeng.api.implementations.guiobjects.IGuiItem;
|
||||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||||
import appeng.api.implementations.items.IAEWrench;
|
import appeng.api.implementations.items.IAEWrench;
|
||||||
import appeng.api.networking.IGridHost;
|
import appeng.api.networking.IGridHost;
|
||||||
|
import appeng.client.ClientHelper;
|
||||||
import appeng.container.AEBaseContainer;
|
import appeng.container.AEBaseContainer;
|
||||||
|
import appeng.core.AELog;
|
||||||
import appeng.core.features.AEFeature;
|
import appeng.core.features.AEFeature;
|
||||||
import appeng.core.sync.GuiBridge;
|
import appeng.core.sync.GuiBridge;
|
||||||
|
import appeng.core.sync.network.NetworkHandler;
|
||||||
|
import appeng.core.sync.packets.PacketClick;
|
||||||
import appeng.items.AEBaseItem;
|
import appeng.items.AEBaseItem;
|
||||||
import appeng.items.contents.NetworkToolViewer;
|
import appeng.items.contents.NetworkToolViewer;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
@ -39,29 +45,64 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p)
|
||||||
{
|
{
|
||||||
Block b = world.getBlock( x, y, z );
|
if ( Platform.isClient() )
|
||||||
if ( b != null && !player.isSneaking() )
|
|
||||||
{
|
{
|
||||||
TileEntity te = world.getTileEntity( x, y, z );
|
MovingObjectPosition mop = ClientHelper.proxy.getMOP();
|
||||||
if ( !(te instanceof IGridHost) )
|
|
||||||
|
if ( mop == null )
|
||||||
{
|
{
|
||||||
if ( b.rotateBlock( world, x, y, z, ForgeDirection.getOrientation( side ) ) )
|
onItemUseFirst( it, p, w, 0, 0, 0, -1, 0, 0, 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
player.swingItem();
|
int i = mop.blockX;
|
||||||
return !world.isRemote;
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitx, float hity, float hitz)
|
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
if ( Platform.isClient() )
|
if ( Platform.isClient() )
|
||||||
return false;
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NetworkHandler.instance.sendToServer( new PacketClick( x, y, z, side, hitX, hitY, hitZ ) );
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
AELog.error( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !p.isSneaking() )
|
if ( !p.isSneaking() )
|
||||||
{
|
{
|
||||||
|
@ -75,17 +116,15 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench,
|
||||||
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
b.onBlockActivated( w, x, y, z, p, side, hitX, hitY, hitZ );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
||||||
{
|
|
||||||
onItemUse( par1ItemStack, par3EntityPlayer, par2World, 0, 0, 0, -1, 0, 0, 0 );
|
|
||||||
return super.onItemRightClick( par1ItemStack, par2World, par3EntityPlayer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Random;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import appeng.block.AEBaseBlock;
|
import appeng.block.AEBaseBlock;
|
||||||
import appeng.core.CommonHelper;
|
import appeng.core.CommonHelper;
|
||||||
|
@ -92,4 +93,10 @@ public class ServerHelper extends CommonHelper
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MovingObjectPosition getMOP()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue