More work on lumberjacks.
RPC now support entity messages. Robots now support item synchronization between client and server. Lumberjack now use a variable tool. for #1869
This commit is contained in:
parent
10fd47b0b9
commit
efcabd31a1
14 changed files with 174 additions and 92 deletions
|
@ -60,7 +60,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
|
||||||
@RPC (RPCSide.SERVER)
|
@RPC (RPCSide.SERVER)
|
||||||
private void uploadBuildersInAction (RPCMessageInfo info) {
|
private void uploadBuildersInAction (RPCMessageInfo info) {
|
||||||
for (BuildingItem i : buildersInAction) {
|
for (BuildingItem i : buildersInAction) {
|
||||||
RPCHandler.rpcPlayer(this, "launchItem", info.sender, i);
|
RPCHandler.rpcPlayer(info.sender, this, "launchItem", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
|
||||||
|
|
||||||
public void addBuildingItem(BuildingItem item) {
|
public void addBuildingItem(BuildingItem item) {
|
||||||
buildersInAction.add(item);
|
buildersInAction.add(item);
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "launchItem", item);
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "launchItem", item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final double energyAvailable() {
|
public final double energyAvailable() {
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
||||||
@RPC (RPCSide.SERVER)
|
@RPC (RPCSide.SERVER)
|
||||||
public void handleClientSetName(String nameSet) {
|
public void handleClientSetName(String nameSet) {
|
||||||
name = nameSet;
|
name = nameSet;
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setName", name);
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "setName", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RPC
|
@RPC
|
||||||
|
|
|
@ -219,15 +219,14 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
|
||||||
BlueprintBase bpt = ItemBlueprint.loadBlueprint(getStackInSlot(1));
|
BlueprintBase bpt = ItemBlueprint.loadBlueprint(getStackInSlot(1));
|
||||||
|
|
||||||
if (bpt != null && uploadingPlayer != null) {
|
if (bpt != null && uploadingPlayer != null) {
|
||||||
RPCHandler.rpcPlayer(this, "downloadBlueprintToClient",
|
RPCHandler.rpcPlayer(uploadingPlayer, this, "downloadBlueprintToClient",
|
||||||
uploadingPlayer, bpt.id, bpt.getData());
|
bpt.id, bpt.getData());
|
||||||
uploadingPlayer = null;
|
uploadingPlayer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progressOut == 100 && getStackInSlot(3) == null) {
|
if (progressOut == 100 && getStackInSlot(3) == null) {
|
||||||
RPCHandler.rpcPlayer(this, "requestSelectedBlueprint",
|
RPCHandler.rpcPlayer(downloadingPlayer, this, "requestSelectedBlueprint");
|
||||||
downloadingPlayer);
|
|
||||||
progressOut = 0;
|
progressOut = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,7 +447,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setItemRequirements",
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "setItemRequirements",
|
||||||
null, null);
|
null, null);
|
||||||
iterateBpt(false);
|
iterateBpt(false);
|
||||||
}
|
}
|
||||||
|
@ -726,10 +726,10 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
||||||
stack.stackSize = 0;
|
stack.stackSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setItemRequirements",
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "setItemRequirements",
|
||||||
((BptBuilderBlueprint) bluePrintBuilder).neededItems, realSize);
|
((BptBuilderBlueprint) bluePrintBuilder).neededItems, realSize);
|
||||||
} else {
|
} else {
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setItemRequirements", null, null);
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "setItemRequirements", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class BuildCraftChannelHandler extends FMLIndexedMessageToMessageCodec<Bu
|
||||||
addDiscriminator(14, PacketRPCTile.class);
|
addDiscriminator(14, PacketRPCTile.class);
|
||||||
addDiscriminator(15, PacketRPCPipe.class);
|
addDiscriminator(15, PacketRPCPipe.class);
|
||||||
addDiscriminator(16, PacketRPCGui.class);
|
addDiscriminator(16, PacketRPCGui.class);
|
||||||
|
addDiscriminator(17, PacketRPCEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -92,6 +92,12 @@ public class PacketHandler extends SimpleChannelInboundHandler<BuildCraftPacket>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case PacketIds.RPC_ENTITY: {
|
||||||
|
((PacketRPCEntity) packet).call(player);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case PacketIds.RPC_PIPE: {
|
case PacketIds.RPC_PIPE: {
|
||||||
// TODO: RPC pipes are not used right now. Ressurect this
|
// TODO: RPC pipes are not used right now. Ressurect this
|
||||||
// code if needed later.
|
// code if needed later.
|
||||||
|
|
|
@ -42,6 +42,7 @@ public final class PacketIds {
|
||||||
public static final int RPC_TILE = 110;
|
public static final int RPC_TILE = 110;
|
||||||
public static final int RPC_PIPE = 111;
|
public static final int RPC_PIPE = 111;
|
||||||
public static final int RPC_GUI = 112;
|
public static final int RPC_GUI = 112;
|
||||||
|
public static final int RPC_ENTITY = 113;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivate constructor
|
* Deactivate constructor
|
||||||
|
|
61
common/buildcraft/core/network/PacketRPCEntity.java
Executable file
61
common/buildcraft/core/network/PacketRPCEntity.java
Executable file
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.core.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
|
public class PacketRPCEntity extends BuildCraftPacket {
|
||||||
|
private byte[] contents;
|
||||||
|
private Entity entity;
|
||||||
|
private int entityId;
|
||||||
|
|
||||||
|
public PacketRPCEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketRPCEntity(Entity iEntity, byte[] bytes) {
|
||||||
|
entity = iEntity;
|
||||||
|
contents = bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getID() {
|
||||||
|
return PacketIds.RPC_ENTITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void call(EntityPlayer sender) {
|
||||||
|
RPCMessageInfo info = new RPCMessageInfo();
|
||||||
|
info.sender = sender;
|
||||||
|
|
||||||
|
ByteBuf completeData = Unpooled.buffer();
|
||||||
|
completeData.writeBytes(contents);
|
||||||
|
|
||||||
|
entity = sender.worldObj.getEntityByID(entityId);
|
||||||
|
|
||||||
|
if (entity != null) {
|
||||||
|
RPCHandler.receiveRPC(entity, info, completeData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readData(ByteBuf data) {
|
||||||
|
entityId = data.readInt();
|
||||||
|
contents = new byte[data.readableBytes()];
|
||||||
|
data.readBytes(contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeData(ByteBuf data) {
|
||||||
|
data.writeInt(entity.getEntityId());
|
||||||
|
data.writeBytes(contents);
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,10 +20,12 @@ import java.util.TreeMap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
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.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import buildcraft.BuildCraftCore;
|
import buildcraft.BuildCraftCore;
|
||||||
import buildcraft.api.core.JavaTools;
|
import buildcraft.api.core.JavaTools;
|
||||||
|
@ -39,7 +41,6 @@ import buildcraft.transport.Pipe;
|
||||||
* RPCs must be sent and received by a tile entity.
|
* RPCs must be sent and received by a tile entity.
|
||||||
*/
|
*/
|
||||||
public final class RPCHandler {
|
public final class RPCHandler {
|
||||||
|
|
||||||
public static int MAX_PACKET_SIZE = 30 * 1024;
|
public static int MAX_PACKET_SIZE = 30 * 1024;
|
||||||
|
|
||||||
private static Map<String, RPCHandler> handlers = new TreeMap<String, RPCHandler>();
|
private static Map<String, RPCHandler> handlers = new TreeMap<String, RPCHandler>();
|
||||||
|
@ -109,13 +110,7 @@ public final class RPCHandler {
|
||||||
handlers.put(object.getClass().getName(), new RPCHandler(object.getClass()));
|
handlers.put(object.getClass().getName(), new RPCHandler(object.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildCraftPacket packet = null;
|
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||||
|
|
||||||
if (object instanceof Container) {
|
|
||||||
packet = handlers.get(object.getClass().getName()).createRCPPacketContainer(method, actuals);
|
|
||||||
} else if (object instanceof TileEntity) {
|
|
||||||
packet = handlers.get(object.getClass().getName()).createRCPPacketTile((TileEntity) object, method, actuals);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
if (packet instanceof PacketRPCTile) {
|
if (packet instanceof PacketRPCTile) {
|
||||||
|
@ -128,19 +123,12 @@ public final class RPCHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rpcPlayer(Object object, String method, EntityPlayer player, Object... actuals) {
|
public static void rpcPlayer(EntityPlayer player, Object object, String method, Object... actuals) {
|
||||||
if (!handlers.containsKey(object.getClass().getName())) {
|
if (!handlers.containsKey(object.getClass().getName())) {
|
||||||
handlers.put(object.getClass().getName(), new RPCHandler(object.getClass()));
|
handlers.put(object.getClass().getName(), new RPCHandler(object.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildCraftPacket packet = null;
|
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||||
|
|
||||||
if (object instanceof Container) {
|
|
||||||
packet = handlers.get(object.getClass().getName()).createRCPPacketContainer(method, actuals);
|
|
||||||
} else if (object instanceof TileEntity) {
|
|
||||||
packet = handlers.get(object.getClass().getName())
|
|
||||||
.createRCPPacketTile((TileEntity) object, method, actuals);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
if (packet instanceof PacketRPCTile) {
|
if (packet instanceof PacketRPCTile) {
|
||||||
|
@ -153,25 +141,26 @@ public final class RPCHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rpcBroadcastDefaultPlayers (Pipe pipe, String method, Object ... actuals) {
|
public static void rpcBroadcastPlayers(World world, Object object, String method, Object... actuals) {
|
||||||
RPCHandler.rpcBroadcastPlayers(pipe, method, DefaultProps.NETWORK_UPDATE_RANGE, actuals);
|
RPCHandler.rpcBroadcastPlayersAtDistance(world, object, method, DefaultProps.NETWORK_UPDATE_RANGE, actuals);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rpcBroadcastPlayers (TileEntity tile, String method, Object ... actuals) {
|
public static void rpcBroadcastPlayersAtDistance(World world, Object object, String method, int maxDistance,
|
||||||
RPCHandler.rpcBroadcastPlayersAtDistance(tile, method, DefaultProps.NETWORK_UPDATE_RANGE, actuals);
|
Object... actuals) {
|
||||||
|
if (!handlers.containsKey(object.getClass().getName())) {
|
||||||
|
handlers.put(object.getClass().getName(), new RPCHandler(object.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rpcBroadcastPlayersAtDistance (TileEntity tile, String method, int maxDistance, Object ... actuals) {
|
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||||
if (!handlers.containsKey(tile.getClass().getName())) {
|
|
||||||
handlers.put (tile.getClass().getName(), new RPCHandler (tile.getClass()));
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketRPCTile packet = handlers.get (tile.getClass().getName()).createRCPPacketTile(tile, method, actuals);
|
|
||||||
|
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
for (PacketRPCTile p : packet
|
if (packet instanceof PacketRPCTile) {
|
||||||
|
TileEntity tile = (TileEntity) object;
|
||||||
|
|
||||||
|
for (PacketRPCTile p : ((PacketRPCTile) packet)
|
||||||
.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||||
for (Object o : tile.getWorldObj().playerEntities) {
|
|
||||||
|
for (Object o : world.playerEntities) {
|
||||||
EntityPlayerMP player = (EntityPlayerMP) o;
|
EntityPlayerMP player = (EntityPlayerMP) o;
|
||||||
|
|
||||||
if (Math.abs(player.posX - tile.xCoord) <= maxDistance
|
if (Math.abs(player.posX - tile.xCoord) <= maxDistance
|
||||||
|
@ -181,23 +170,10 @@ public final class RPCHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
for (Object o : world.playerEntities) {
|
||||||
|
|
||||||
public static void rpcBroadcastPlayers (Pipe pipe, String method, int maxDistance, Object ... actuals) {
|
|
||||||
if (!handlers.containsKey(pipe.getClass().getName())) {
|
|
||||||
handlers.put (pipe.getClass().getName(), new RPCHandler (pipe.getClass()));
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketRPCPipe packet = handlers.get (pipe.getClass().getName()).createRCPPacketPipe(pipe, method, actuals);
|
|
||||||
|
|
||||||
if (packet != null) {
|
|
||||||
for (Object o : pipe.container.getWorld().playerEntities) {
|
|
||||||
EntityPlayerMP player = (EntityPlayerMP) o;
|
EntityPlayerMP player = (EntityPlayerMP) o;
|
||||||
|
|
||||||
if (Math.abs(player.posX - pipe.container.xCoord) <= maxDistance
|
|
||||||
&& Math.abs(player.posY - pipe.container.yCoord) <= maxDistance
|
|
||||||
&& Math.abs(player.posZ - pipe.container.zCoord) <= maxDistance) {
|
|
||||||
BuildCraftCore.instance.sendToPlayer(player, packet);
|
BuildCraftCore.instance.sendToPlayer(player, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +220,22 @@ public final class RPCHandler {
|
||||||
return new PacketRPCPipe(bytes);
|
return new PacketRPCPipe(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketRPCTile createRCPPacketTile (TileEntity tile, String method, Object ... actuals) {
|
private static BuildCraftPacket createPacket(Object object, String method, Object... actuals) {
|
||||||
|
BuildCraftPacket packet = null;
|
||||||
|
|
||||||
|
if (object instanceof Container) {
|
||||||
|
packet = handlers.get(object.getClass().getName()).createRCPPacketContainer(method, actuals);
|
||||||
|
} else if (object instanceof TileEntity) {
|
||||||
|
packet = handlers.get(object.getClass().getName())
|
||||||
|
.createRCPPacketTile((TileEntity) object, method, actuals);
|
||||||
|
} else if (object instanceof Entity) {
|
||||||
|
packet = handlers.get(object.getClass().getName()).createRCPPacketEntity((Entity) object, method, actuals);
|
||||||
|
}
|
||||||
|
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getBytes(String method, Object... actuals) {
|
||||||
ByteBuf data = Unpooled.buffer();
|
ByteBuf data = Unpooled.buffer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -260,26 +251,19 @@ public final class RPCHandler {
|
||||||
byte [] bytes = new byte [data.readableBytes()];
|
byte [] bytes = new byte [data.readableBytes()];
|
||||||
data.readBytes(bytes);
|
data.readBytes(bytes);
|
||||||
|
|
||||||
return new PacketRPCTile(tile, bytes);
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PacketRPCTile createRCPPacketTile(TileEntity tile, String method, Object... actuals) {
|
||||||
|
return new PacketRPCTile(tile, getBytes(method, actuals));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketRPCGui createRCPPacketContainer(String method, Object... actuals) {
|
private PacketRPCGui createRCPPacketContainer(String method, Object... actuals) {
|
||||||
ByteBuf data = Unpooled.buffer();
|
return new PacketRPCGui(getBytes(method, actuals));
|
||||||
|
|
||||||
try {
|
|
||||||
writeParameters(method, data, actuals);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = new byte[data.readableBytes()];
|
private PacketRPCEntity createRCPPacketEntity(Entity entity, String method, Object... actuals) {
|
||||||
data.readBytes(bytes);
|
return new PacketRPCEntity(entity, getBytes(method, actuals));
|
||||||
|
|
||||||
return new PacketRPCGui(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeParameters(String method, ByteBuf data, Object... actuals)
|
private void writeParameters(String method, ByteBuf data, Object... actuals)
|
||||||
|
|
|
@ -61,10 +61,12 @@ public class RenderRobot extends Render implements IItemRenderer {
|
||||||
|
|
||||||
box.render(factor);
|
box.render(factor);
|
||||||
|
|
||||||
// GL11.glTranslated(0.5, 0, 0);
|
if (robot.itemInUse != null) {
|
||||||
|
GL11.glPushMatrix();
|
||||||
GL11.glRotatef(robot.worldObj.getTotalWorldTime() % 45 + 90, 1, 0, 0);
|
GL11.glRotatef(robot.worldObj.getTotalWorldTime() % 45 + 90, 1, 0, 0);
|
||||||
doRenderItemAtHand(robot, new ItemStack(Items.diamond_axe));
|
doRenderItemAtHand(robot, robot.itemInUse);
|
||||||
// GL11.glTranslated(-0.5, 0, 0);
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
if (robot.laser.isVisible) {
|
if (robot.laser.isVisible) {
|
||||||
robot.laser.head.x = robot.posX;
|
robot.laser.head.x = robot.posX;
|
||||||
|
|
|
@ -29,6 +29,10 @@ import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.api.core.SafeTimeTracker;
|
import buildcraft.api.core.SafeTimeTracker;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.LaserData;
|
import buildcraft.core.LaserData;
|
||||||
|
import buildcraft.core.network.RPC;
|
||||||
|
import buildcraft.core.network.RPCHandler;
|
||||||
|
import buildcraft.core.network.RPCMessageInfo;
|
||||||
|
import buildcraft.core.network.RPCSide;
|
||||||
import buildcraft.transport.TileGenericPipe;
|
import buildcraft.transport.TileGenericPipe;
|
||||||
|
|
||||||
public class EntityRobot extends EntityLiving implements
|
public class EntityRobot extends EntityLiving implements
|
||||||
|
@ -55,6 +59,8 @@ public class EntityRobot extends EntityLiving implements
|
||||||
public IRedstoneBoardRobot board;
|
public IRedstoneBoardRobot board;
|
||||||
|
|
||||||
public RobotAIBase currentAI;
|
public RobotAIBase currentAI;
|
||||||
|
public ItemStack itemInUse;
|
||||||
|
|
||||||
protected RobotAIBase nextAI;
|
protected RobotAIBase nextAI;
|
||||||
|
|
||||||
private boolean needsUpdate = false;
|
private boolean needsUpdate = false;
|
||||||
|
@ -72,6 +78,10 @@ public class EntityRobot extends EntityLiving implements
|
||||||
|
|
||||||
board = iBoard;
|
board = iBoard;
|
||||||
dataWatcher.updateObject(16, board.getNBTHandler().getID());
|
dataWatcher.updateObject(16, board.getNBTHandler().getID());
|
||||||
|
|
||||||
|
if (world.isRemote) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityRobot(World par1World) {
|
public EntityRobot(World par1World) {
|
||||||
|
@ -445,4 +455,19 @@ public class EntityRobot extends EntityLiving implements
|
||||||
public boolean isMoving() {
|
public boolean isMoving() {
|
||||||
return motionX != 0 || motionY != 0 || motionZ != 0;
|
return motionX != 0 || motionY != 0 || motionZ != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setItemInUse(ItemStack stack) {
|
||||||
|
itemInUse = stack;
|
||||||
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "clientSetItemInUse", stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RPC(RPCSide.CLIENT)
|
||||||
|
private void clientSetItemInUse(ItemStack stack) {
|
||||||
|
itemInUse = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RPC(RPCSide.SERVER)
|
||||||
|
public void requestInitialization(RPCMessageInfo info) {
|
||||||
|
RPCHandler.rpcPlayer(info.sender, this, "clientSetItemInUse", itemInUse);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.core.BlockIndex;
|
import buildcraft.core.BlockIndex;
|
||||||
import buildcraft.core.robots.EntityRobot;
|
import buildcraft.core.robots.EntityRobot;
|
||||||
import buildcraft.core.robots.RobotAIMoveTo;
|
import buildcraft.core.robots.RobotAIMoveTo;
|
||||||
|
import buildcraft.core.utils.BlockUtil;
|
||||||
import buildcraft.core.utils.IPathFound;
|
import buildcraft.core.utils.IPathFound;
|
||||||
import buildcraft.core.utils.PathFinding;
|
import buildcraft.core.utils.PathFinding;
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ public class BoardRobotLumberjack implements IRedstoneBoardRobot<EntityRobot> {
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
range = data.getInteger("range");
|
range = data.getInteger("range");
|
||||||
|
robot.setItemInUse(new ItemStack(Items.wooden_axe));
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
@ -82,14 +85,14 @@ public class BoardRobotLumberjack implements IRedstoneBoardRobot<EntityRobot> {
|
||||||
Block block = robot.worldObj.getBlock(woodToChop.x, woodToChop.y, woodToChop.z);
|
Block block = robot.worldObj.getBlock(woodToChop.x, woodToChop.y, woodToChop.z);
|
||||||
int meta = robot.worldObj.getBlockMetadata(woodToChop.x, woodToChop.y, woodToChop.z);
|
int meta = robot.worldObj.getBlockMetadata(woodToChop.x, woodToChop.y, woodToChop.z);
|
||||||
float hardness = block.getBlockHardness(robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z);
|
float hardness = block.getBlockHardness(robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z);
|
||||||
float speed = getBreakSpeed(robot, new ItemStack(Items.wooden_axe), block, meta);
|
float speed = getBreakSpeed(robot, robot.itemInUse, block, meta);
|
||||||
blockDamage += speed / hardness / 30F;
|
blockDamage += speed / hardness / 30F;
|
||||||
|
|
||||||
|
|
||||||
if (blockDamage > 1.0F) {
|
if (blockDamage > 1.0F) {
|
||||||
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x,
|
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x,
|
||||||
woodToChop.y, woodToChop.z, -1);
|
woodToChop.y, woodToChop.z, -1);
|
||||||
blockDamage = 0;
|
blockDamage = 0;
|
||||||
|
BlockUtil.breakBlock((WorldServer) robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z, 6000);
|
||||||
robot.worldObj.setBlockToAir(woodToChop.x, woodToChop.y, woodToChop.z);
|
robot.worldObj.setBlockToAir(woodToChop.x, woodToChop.y, woodToChop.z);
|
||||||
stage = Stages.LOOK_FOR_WOOD;
|
stage = Stages.LOOK_FOR_WOOD;
|
||||||
woodToChop = null;
|
woodToChop = null;
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
|
||||||
addLaser(receiver.xCoord, receiver.yCoord,
|
addLaser(receiver.xCoord, receiver.yCoord,
|
||||||
receiver.zCoord);
|
receiver.zCoord);
|
||||||
|
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "addLaser",
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "addLaser",
|
||||||
receiver.xCoord, receiver.yCoord,
|
receiver.xCoord, receiver.yCoord,
|
||||||
receiver.zCoord);
|
receiver.zCoord);
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
|
||||||
accumulated++;
|
accumulated++;
|
||||||
|
|
||||||
if (syncMJ.markTimeIfDelay(worldObj)) {
|
if (syncMJ.markTimeIfDelay(worldObj)) {
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "synchronizeMJ", mjAcc
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "synchronizeMJ", mjAcc
|
||||||
/ accumulated);
|
/ accumulated);
|
||||||
mjAcc = 0;
|
mjAcc = 0;
|
||||||
accumulated = 0;
|
accumulated = 0;
|
||||||
|
@ -121,7 +121,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
|
||||||
for (Target t : targets.values()) {
|
for (Target t : targets.values()) {
|
||||||
if (t.data.isVisible) {
|
if (t.data.isVisible) {
|
||||||
t.data.isVisible = false;
|
t.data.isVisible = false;
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "disableLaser",
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "disableLaser",
|
||||||
t.receiver.xCoord, t.receiver.yCoord,
|
t.receiver.xCoord, t.receiver.yCoord,
|
||||||
t.receiver.zCoord);
|
t.receiver.zCoord);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
|
||||||
for (Target t : targets.values()) {
|
for (Target t : targets.values()) {
|
||||||
if (!t.data.isVisible) {
|
if (!t.data.isVisible) {
|
||||||
t.data.isVisible = true;
|
t.data.isVisible = true;
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "enableLaser",
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "enableLaser",
|
||||||
t.receiver.xCoord, t.receiver.yCoord,
|
t.receiver.xCoord, t.receiver.yCoord,
|
||||||
t.receiver.zCoord);
|
t.receiver.zCoord);
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
|
||||||
@RPC (RPCSide.SERVER)
|
@RPC (RPCSide.SERVER)
|
||||||
public void requestLasers (RPCMessageInfo info) {
|
public void requestLasers (RPCMessageInfo info) {
|
||||||
for (BlockIndex b : targets.keySet()) {
|
for (BlockIndex b : targets.keySet()) {
|
||||||
RPCHandler.rpcPlayer(this, "addLaser", info.sender, b.x, b.y, b.z);
|
RPCHandler.rpcPlayer(info.sender, this, "addLaser", b.x, b.y, b.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class TileTestCase extends TileEntity {
|
||||||
information = "test clear";
|
information = "test clear";
|
||||||
}
|
}
|
||||||
|
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setInformation", information);
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "setInformation", information);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RPC(RPCSide.CLIENT)
|
@RPC(RPCSide.CLIENT)
|
||||||
|
@ -154,7 +154,7 @@ public class TileTestCase extends TileEntity {
|
||||||
@RPC(RPCSide.SERVER)
|
@RPC(RPCSide.SERVER)
|
||||||
private void setName(String name) {
|
private void setName(String name) {
|
||||||
testName = name;
|
testName = name;
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setNameClient", name);
|
RPCHandler.rpcBroadcastPlayers(worldObj, this, "setNameClient", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RPC(RPCSide.CLIENT)
|
@RPC(RPCSide.CLIENT)
|
||||||
|
|
Loading…
Reference in a new issue