use of buildcraft.transport.BlockGenericPipe.RaytraceResult in project BuildCraft by BuildCraft.
the class ItemGateCopier method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
boolean isCopying = !player.isSneaking();
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
NBTTagCompound data = NBTUtilBC.getItemData(stack);
PipePluggable pluggable = null;
Gate gate = null;
if (tile == null || !(tile instanceof IPipeTile)) {
isCopying = true;
} else {
if (tile instanceof TileGenericPipe && block instanceof BlockGenericPipe) {
RaytraceResult rayTraceResult = ((BlockGenericPipe) block).doRayTrace(world, pos, player);
if (rayTraceResult != null && rayTraceResult.boundingBox != null && rayTraceResult.hitPart == Part.Pluggable) {
pluggable = ((TileGenericPipe) tile).getPipePluggable(rayTraceResult.sideHit);
}
} else {
pluggable = ((IPipeTile) tile).getPipePluggable(side);
}
}
if (pluggable instanceof GatePluggable) {
gate = ((GatePluggable) pluggable).realGate;
}
if (isCopying) {
if (gate == null) {
data = new NBTTagCompound();
stack.setTagCompound(data);
// Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
data.setBoolean("Unbreakable", true);
// Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
data.setInteger("HideFlags", 4);
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.clear"));
return true;
}
data = new NBTTagCompound();
stack.setTagCompound(data);
gate.writeStatementsToNBT(data);
data.setByte("material", (byte) gate.material.ordinal());
data.setByte("logic", (byte) gate.logic.ordinal());
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gateCopied"));
// Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
data.setBoolean("Unbreakable", true);
// Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
data.setInteger("HideFlags", 4);
} else {
if (!data.hasKey("logic")) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noInformation"));
return true;
} else if (gate == null) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noGate"));
return true;
}
GateMaterial dataMaterial = GateMaterial.fromOrdinal(data.getByte("material"));
GateMaterial gateMaterial = gate.material;
if (gateMaterial.numSlots < dataMaterial.numSlots) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.slots"));
}
if (gateMaterial.numActionParameters < dataMaterial.numActionParameters) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.actionParameters"));
}
if (gateMaterial.numTriggerParameters < dataMaterial.numTriggerParameters) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.triggerParameters"));
}
if (data.getByte("logic") != gate.logic.ordinal()) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.logic"));
}
gate.readStatementsFromNBT(data);
if (!gate.verifyGateStatements()) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.load"));
}
if (tile instanceof TileGenericPipe) {
((TileGenericPipe) tile).sendNetworkUpdate();
}
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gatePasted"));
return true;
}
return true;
}
Aggregations