Skip to content

Commit

Permalink
Add another RS addons hook
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Oct 4, 2017
1 parent 9dbd752 commit e2f1262
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Consumer;

public abstract class ItemNetworkItem extends ItemEnergyItem implements INetworkItemProvider {
private static final String NBT_CONTROLLER_X = "ControllerX";
Expand All @@ -36,22 +37,26 @@ public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player
ItemStack stack = player.getHeldItem(hand);

if (!world.isRemote) {
if (!isValid(stack)) {
player.sendMessage(new TextComponentTranslation("misc.refinedstorage:network_item.not_found"));
} else {
World networkWorld = DimensionManager.getWorld(getDimensionId(stack));
applyNetwork(stack, n -> n.getNetworkItemHandler().onOpen(player, hand), player::sendMessage);
}

TileEntity network;
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}

if (networkWorld != null && ((network = networkWorld.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)))) instanceof INetwork)) {
((INetwork) network).getNetworkItemHandler().onOpen(player, hand);
} else {
player.sendMessage(new TextComponentTranslation("misc.refinedstorage:network_item.not_found"));
}
public void applyNetwork(ItemStack stack, Consumer<INetwork> networkConsumer, Consumer<TextComponentTranslation> errorConsumer) {
if (!isValid(stack)) {
errorConsumer.accept(new TextComponentTranslation("misc.refinedstorage:network_item.not_found"));
} else {
World networkWorld = DimensionManager.getWorld(getDimensionId(stack));

TileEntity network;

if (networkWorld != null && ((network = networkWorld.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)))) instanceof INetwork)) {
networkConsumer.accept((INetwork) network);
} else {
errorConsumer.accept(new TextComponentTranslation("misc.refinedstorage:network_item.not_found"));
}
}

return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}

@Override
Expand Down

0 comments on commit e2f1262

Please sign in to comment.