use of blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock in project ImmersiveEngineering by BluSunrize.
the class ItemIETool method onItemUseFirst.
// @Override
// public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack)
// {
// return stack.getItemDamage()!=0;
// }
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
TileEntity tileEntity = world.getTileEntity(pos);
if (stack.getItemDamage() == 0) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return EnumActionResult.PASS;
String[] permittedMultiblocks = null;
String[] interdictedMultiblocks = null;
if (ItemNBTHelper.hasKey(stack, "multiblockPermission")) {
NBTTagList list = stack.getTagCompound().getTagList("multiblockPermission", 8);
permittedMultiblocks = new String[list.tagCount()];
for (int i = 0; i < permittedMultiblocks.length; i++) permittedMultiblocks[i] = list.getStringTagAt(i);
}
if (ItemNBTHelper.hasKey(stack, "multiblockInterdiction")) {
NBTTagList list = stack.getTagCompound().getTagList("multiblockInterdiction", 8);
interdictedMultiblocks = new String[list.tagCount()];
for (int i = 0; i < interdictedMultiblocks.length; i++) interdictedMultiblocks[i] = list.getStringTagAt(i);
}
for (IMultiblock mb : MultiblockHandler.getMultiblocks()) if (mb.isBlockTrigger(world.getBlockState(pos))) {
boolean b = permittedMultiblocks == null;
if (permittedMultiblocks != null)
for (String s : permittedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
b = true;
continue;
}
if (!b)
break;
if (interdictedMultiblocks != null)
for (String s : interdictedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
b = false;
continue;
}
if (!b)
break;
if (MultiblockHandler.postMultiblockFormationEvent(player, mb, pos, stack).isCanceled())
continue;
if (mb.createStructure(world, pos, side, player))
return EnumActionResult.SUCCESS;
}
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof IDirectionalTile) && !(tile instanceof IHammerInteraction) && !(tile instanceof IConfigurableSides))
return RotationUtil.rotateBlock(world, pos, side) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
} else if (stack.getItemDamage() == 1 && tileEntity instanceof IImmersiveConnectable && !world.isRemote) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(null, target);
tileEntity = world.getTileEntity(masterPos);
if (!(tileEntity instanceof IImmersiveConnectable))
return EnumActionResult.PASS;
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
boolean cut = ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(nodeHere), world, target);
IESaveData.setDirty(world.provider.getDimension());
if (cut) {
int nbtDamage = ItemNBTHelper.getInt(stack, "cutterDmg") + 1;
if (nbtDamage < cutterMaxDamage)
ItemNBTHelper.setInt(stack, "cutterDmg", nbtDamage);
else {
player.renderBrokenItemStack(stack);
player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);
}
}
return EnumActionResult.SUCCESS;
} else if (stack.getItemDamage() == 2 && !world.isRemote) {
if (!player.isSneaking() && (tileEntity instanceof IFluxReceiver || tileEntity instanceof IFluxProvider)) {
int max = 0;
int stored = 0;
if (tileEntity instanceof IFluxReceiver) {
max = ((IFluxReceiver) tileEntity).getMaxEnergyStored(side);
stored = ((IFluxReceiver) tileEntity).getEnergyStored(side);
} else {
max = ((IFluxProvider) tileEntity).getMaxEnergyStored(side);
stored = ((IFluxProvider) tileEntity).getEnergyStored(side);
}
if (max > 0)
ChatUtils.sendServerNoSpamMessages(player, new TextComponentTranslation(Lib.CHAT_INFO + "energyStorage", stored, max));
return EnumActionResult.SUCCESS;
}
if (player.isSneaking() && tileEntity instanceof IImmersiveConnectable) {
if (!ItemNBTHelper.hasKey(stack, "linkingPos"))
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ() });
else {
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
if (array[0] == world.provider.getDimension()) {
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
if (nodeLink != null) {
Set<AbstractConnection> connections = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(Utils.toCC(nodeLink), world, true);
for (AbstractConnection con : connections) if (Utils.toCC(nodeHere).equals(con.end))
player.addChatComponentMessage(new TextComponentTranslation(Lib.CHAT_INFO + "averageLoss", Utils.formatDouble(con.getAverageLossRate() * 100, "###.000")));
}
}
ItemNBTHelper.remove(stack, "linkingPos");
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
Aggregations